Module: Decidim::Design::ApplicationHelper

Includes:
ApplicationHelper, IconHelper
Defined in:
decidim-design/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"

Constants included from AmendmentsHelper

AmendmentsHelper::TOTAL_STEPS

Instance Method Summary collapse

Methods included from IconHelper

#component_icon, #manifest_icon, #resource_icon, #resource_type_icon, #resource_type_icon_key, #text_with_resource_icon

Methods included from LayoutHelper

#_icon_classes, #apple_favicon, #application_path, #current_url, #current_user_unread_data, #extended_navigation_bar, #external_icon, #favicon, #icon, #legacy_favicon, #role, #root_url

Methods included from TooltipHelper

#with_tooltip

Methods included from ModalHelper

#decidim_drawer, #decidim_modal

Methods included from OrganizationHelper

#current_organization_name, #organization_colors, #organization_description_label, #organization_name

Methods included from TranslatableAttributes

#attachment?, #default_locale?

Methods included from ApplicationHelper

#add_body_classes, #cell, #edit_link, #extra_admin_link, #html_truncate, #layout_item_classes, #present, #prevent_timeout_seconds, #resolve_presenter_class, #text_initials

Methods included from CacheHelper

#cache

Methods included from AmendmentsHelper

#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amendments_enabled?, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #current_step, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body, #total_steps, #wizard_aside_back_url, #wizard_header_title

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from ContextualHelpHelper

#floating_help

Methods included from Decidim::DecidimFormHelper

#areas_for_select, #base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #form_required_explanation, #name_with_locale, #tab_element_class_for, #translated_field_tag

Methods included from OmniauthHelper

#normalize_provider_name, #oauth_icon, #provider_name

Instance Method Details

#cell_snippet_locals(args) ⇒ Object



76
77
78
79
80
81
82
83
# File 'decidim-design/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 'decidim-design/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 'decidim-design/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 'decidim-design/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 'decidim-design/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 'decidim-design/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 'decidim-design/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 'decidim-design/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 'decidim-design/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 'decidim-design/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 'decidim-design/app/helpers/decidim/design/application_helper.rb', line 13

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