Module: PaperTrailHistory::ApplicationHelper

Defined in:
app/helpers/paper_trail_history/application_helper.rb

Overview

Helper module providing utility methods for PaperTrailHistory views

Instance Method Summary collapse

Instance Method Details

#displayed_attributes(record) ⇒ Array<Array(String, Object)>

Gives the attributes of a record for the interface. The value of an attribute that the host application filters becomes a placeholder, thus a password digest or an API token does not appear on the page.

Parameters:

  • record (ActiveRecord::Base)

Returns:

  • (Array<Array(String, Object)>)

    pairs of name and value



59
60
61
62
63
64
65
# File 'app/helpers/paper_trail_history/application_helper.rb', line 59

def displayed_attributes(record)
  record.attributes.map do |name, value|
    next [name, t('paper_trail_history.display.filtered')] if PaperTrailHistory.config.filtered_attribute?(name)

    [name, value]
  end
end

#engine_csp_nonceString?

Gives the nonce of the Content Security Policy, or nil.

An empty nonce attribute is not useful: the browser refuses it and writes an error. The engine writes no attribute if the host application makes no nonce.

Returns:

  • (String, nil)


25
26
27
# File 'app/helpers/paper_trail_history/application_helper.rb', line 25

def engine_csp_nonce
  content_security_policy_nonce.presence
end

#engine_javascript_tag(name) ⇒ ActiveSupport::SafeBuffer

Makes the script tag for one of the scripts of the interface.

Parameters:

  • name (Symbol)

    key in the assets configuration

Returns:

  • (ActiveSupport::SafeBuffer)


47
48
49
50
51
# File 'app/helpers/paper_trail_history/application_helper.rb', line 47

def engine_javascript_tag(name)
  asset = PaperTrailHistory.config.assets.fetch(name)

  (:script, '', src: asset[:href], **asset_integrity_options(asset))
end

#engine_stylesheet_tag(name) ⇒ ActiveSupport::SafeBuffer

Makes the link tag for one of the stylesheets of the interface.

The tag carries the integrity value, and a nonce when the host application uses a Content Security Policy with nonces. A policy that permits no other origin thus still works, if the host application serves the file itself.

Parameters:

  • name (Symbol)

    key in the assets configuration

Returns:

  • (ActiveSupport::SafeBuffer)


37
38
39
40
41
# File 'app/helpers/paper_trail_history/application_helper.rb', line 37

def engine_stylesheet_tag(name)
  asset = PaperTrailHistory.config.assets.fetch(name)

  tag.link(rel: 'stylesheet', href: asset[:href], **asset_integrity_options(asset))
end

Generate restore version path with model_name context



13
14
15
16
# File 'app/helpers/paper_trail_history/application_helper.rb', line 13

def restore_version_link_path(version, options = {})
  model_name = options[:model_name] || version.item_type
  restore_version_path(version.id, model_name: model_name)
end

Generate version path with model_name context when available



7
8
9
10
# File 'app/helpers/paper_trail_history/application_helper.rb', line 7

def version_link_path(version, options = {})
  model_name = options[:model_name] || version.item_type
  version_path(version.id, model_name: model_name)
end