Module: Decidim::Design::ApplicationHelper

Includes:
ApplicationHelper, IconHelper
Defined in:
app/helpers/decidim/design/application_helper.rb

Constant Summary collapse

RELEASE_ID =

For the moment keep this as a constant and later decide where to move this

"develop"

Instance Method Summary collapse

Instance Method Details

#cell_snippet_locals(args) ⇒ Object



76
77
78
79
80
81
82
83
# File 'app/helpers/decidim/design/application_helper.rb', line 76

def cell_snippet_locals(args)
  path = args.delete(:path) || File.join("decidim-core/app/cells/", args[:cell])
  url = "https://github.com/decidim/decidim/blob/#{RELEASE_ID}/#{path}_cell.rb"
  call_string = args.delete(:call_string) || ""
  args_texts = call_string.present? ? [] : inspect_args(args[:args])

  args.merge(text: path, url:, call_string:, args_texts:)
end

#inspect_args(args = []) ⇒ Object



85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'app/helpers/decidim/design/application_helper.rb', line 85

def inspect_args(args = [])
  return ["nil"] if args.blank?

  args.map do |arg|
    next arg.inspect if arg.is_a?(String)
    next arg.except(:context).inspect if arg.is_a?(Hash)

    class_name = arg.class.name
    next "#{class_name}.take" if arg.is_a?(Decidim::ApplicationRecord)

    class_name
  end
end

#render_cell(cell) ⇒ Object



109
110
111
112
113
114
115
116
117
# File 'app/helpers/decidim/design/application_helper.rb', line 109

def render_cell(cell)
  (:td) do
    if cell.is_a?(Hash)
      send(cell[:method], *cell[:args]).to_s
    else
      cell
    end
  end
end

#render_cell_call_textarea(cell_data) ⇒ Object



72
73
74
# File 'app/helpers/decidim/design/application_helper.rb', line 72

def render_cell_call_textarea(cell_data)
  render partial: "decidim/design/shared/cell_call_textarea", locals: cell_snippet_locals(cell_data)
end

#render_cell_snippet(content) ⇒ Object



66
67
68
69
70
# File 'app/helpers/decidim/design/application_helper.rb', line 66

def render_cell_snippet(content)
  return "" if content[:cell_snippet].blank?

  render partial: "decidim/design/shared/cell_snippet", locals: cell_snippet_locals(content[:cell_snippet])
end

#render_content(content) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'app/helpers/decidim/design/application_helper.rb', line 29

def render_content(content)
  case content[:type]
  when :text
    html = ""
    content[:values].each do |value|
      html += (:p, value.html_safe, class: content[:class])
    end
    html.html_safe
  when :cell_table
    render partial: "decidim/design/shared/cell_table", locals: content.slice(:cell_snippet).merge(content[:options] || {})
  when :table
    render partial: "decidim/design/shared/table", locals: content.slice(:items).merge(content[:options] || {})
  when :partial
    partial = render_partial(content)

    return partial if content[:layout].blank?

    render layout: content[:layout] do
      partial.html_safe
    end
  else
    content[:values].to_s.html_safe
  end
end

#render_partial(content) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
# File 'app/helpers/decidim/design/application_helper.rb', line 54

def render_partial(content)
  if content[:template].is_a?(Array)
    templates = ""
    content[:template].each do |value|
      templates += render partial: value, locals: content[:locals]
    end
    return templates
  end

  render partial: content[:template], locals: content[:locals]
end

#render_row(row) ⇒ Object



99
100
101
102
103
104
105
106
107
# File 'app/helpers/decidim/design/application_helper.rb', line 99

def render_row(row)
  if row.is_a?(Array)
    html = ""
    row.each do |cell|
      html += render_cell(cell)
    end
    html.html_safe
  end
end

#section_subtitle(section) ⇒ Object



17
18
19
# File 'app/helpers/decidim/design/application_helper.rb', line 17

def section_subtitle(section)
  (:h3, section_text(section))
end

#section_text(section) ⇒ Object



21
22
23
24
25
26
27
# File 'app/helpers/decidim/design/application_helper.rb', line 21

def section_text(section)
  title = section[:title] || section[:id]&.titleize
  return title if section[:label].blank?

  title += (:span, section[:label], class: "label")
  title.html_safe
end

#section_title(section) ⇒ Object



13
14
15
# File 'app/helpers/decidim/design/application_helper.rb', line 13

def section_title(section)
  (:h2, section_text(section))
end