Module: Decidim::TraceabilityHelper

Includes:
SanitizeHelper
Defined in:
app/helpers/decidim/traceability_helper.rb

Overview

A Helper to find and render the author of a version.

Instance Method Summary collapse

Methods included from SanitizeHelper

#decidim_sanitize

Instance Method Details

#diff_rendererObject

Caches a DiffRenderer instance for the ‘current_version`.



33
34
35
# File 'app/helpers/decidim/traceability_helper.rb', line 33

def diff_renderer
  @diff_renderer ||= Decidim::Accountability::DiffRenderer.new(current_version)
end

#render_diff_data(data) ⇒ Object

Renders the diff between ‘:old_data` and `:new_data` keys in the `data` param.

data - A Hash with ‘old_data`, `:new_data` and `:type` keys.

Returns an HTML-safe string.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/decidim/traceability_helper.rb', line 42

def render_diff_data(data)
  (:div, class: "card card--list diff diff-#{data[:type]}") do
    if [:i18n, :i18n_html].include?(data[:type])
      render_diff_value(
        " ",
        data[:type],
        nil,
        data: {
          old_value: data[:old_value].to_s.gsub("</p>", "</p>\n"),
          new_value: data[:new_value].to_s.gsub("</p>", "</p>\n")
        }
      )
    else
      render_diff_value(data[:old_value], data[:type], :removal) +
        render_diff_value(data[:new_value], data[:type], :addition)
    end
  end
end

#render_resource_editor(version) ⇒ Object

Renders the avatar and author name of the author of the given version.

version - an object that responds to ‘whodunnit` and returns a String.

Returns an HTML-safe String representing the HTML to render the author.



25
26
27
28
29
30
# File 'app/helpers/decidim/traceability_helper.rb', line 25

def render_resource_editor(version)
  render partial: "decidim/shared/version_author",
         locals: {
           author: Decidim.traceability.version_editor(version)
         }
end

#render_resource_last_editor(resource) ⇒ Object

Renders the avatar and author name of the author of the last version of the given resource.

resource - an object implementing ‘Decidim::Traceable`

Returns an HTML-safe String representing the HTML to render the author.



13
14
15
16
17
18
# File 'app/helpers/decidim/traceability_helper.rb', line 13

def render_resource_last_editor(resource)
  render partial: "decidim/shared/version_author",
         locals: {
           author: Decidim.traceability.last_editor(resource)
         }
end