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
-
#displayed_attributes(record) ⇒ Array<Array(String, Object)>
Gives the attributes of a record for the interface.
-
#engine_csp_nonce ⇒ String?
Gives the nonce of the Content Security Policy, or nil.
-
#engine_javascript_tag(name) ⇒ ActiveSupport::SafeBuffer
Makes the script tag for one of the scripts of the interface.
-
#engine_stylesheet_tag(name) ⇒ ActiveSupport::SafeBuffer
Makes the link tag for one of the stylesheets of the interface.
-
#restore_version_link_path(version, options = {}) ⇒ Object
Generate restore version path with model_name context.
-
#version_link_path(version, options = {}) ⇒ Object
Generate version path with model_name context when available.
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.
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_nonce ⇒ String?
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.
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.
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) content_tag(:script, '', src: asset[:href], **(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.
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)) end |
#restore_version_link_path(version, options = {}) ⇒ Object
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, = {}) model_name = [:model_name] || version.item_type restore_version_path(version.id, model_name: model_name) end |
#version_link_path(version, options = {}) ⇒ Object
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, = {}) model_name = [:model_name] || version.item_type version_path(version.id, model_name: model_name) end |