Module: Decidim::Plans::TraceabilityHelper

Includes:
TraceabilityHelper
Defined in:
app/helpers/decidim/plans/traceability_helper.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#associated_diff_renderersObject



16
17
18
19
20
# File 'app/helpers/decidim/plans/traceability_helper.rb', line 16

def associated_diff_renderers
  @associated_diff_renderers ||= associated_versions.map do |version|
    renderer_for(version)
  end.compact
end

#content_diff_renderersObject



22
23
24
25
26
# File 'app/helpers/decidim/plans/traceability_helper.rb', line 22

def content_diff_renderers
  @content_diff_renderers ||= content_versions.map do |version|
    renderer_for(version)
  end.compact
end

#diff_renderersObject



28
29
30
# File 'app/helpers/decidim/plans/traceability_helper.rb', line 28

def diff_renderers
  item_diff_renderers + associated_diff_renderers + content_diff_renderers
end

#item_diff_renderersObject

Caches a DiffRenderer instance for the ‘current_version`.



10
11
12
13
14
# File 'app/helpers/decidim/plans/traceability_helper.rb', line 10

def item_diff_renderers
  @item_diff_renderers ||= item_versions.map do |version|
    renderer_for(version)
  end.compact
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.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'app/helpers/decidim/plans/traceability_helper.rb', line 37

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