Module: Decidim::ApplicationHelper

Includes:
AmendmentsHelper, CacheHelper, ContextualHelpHelper, DecidimFormHelper, OmniauthHelper
Included in:
Decidim::Accountability::Admin::ResultsBulkActionsController, Decidim::Accountability::Admin::ResultsController, AmendmentsController, Blogs::Admin::PostsHelper, Blogs::PostSerializer, Blogs::PostsHelper, Blogs::PostsSelectHelper, Budgets::Admin::ProjectForm, Budgets::Admin::ProjectsController, Budgets::ProjectSerializer, Budgets::ProjectsHelper, CardGCell, CollaborativeTexts::Admin::DocumentForm, CollaborativeTexts::SuggestionPresenter, Conferences::Admin::ConferenceSpeakerForm, Conferences::Admin::RegistrationTypeForm, Conferences::Admin::RegistrationTypesController, Debates::DebateSerializer, Debates::VersionsController, Design::ApplicationHelper, Elections::Admin::ElectionsController, Elections::Admin::ElectionsHelper, Elections::ElectionsController, Exporters::ParticipatorySpaceComponentsSerializer, Exporters::ParticipatorySpaceSerializer, LikersListCell, Meetings::Admin::InviteJoinMeetingMailer, Meetings::CloseMeetingReminderMailer, Meetings::MeetingSerializer, Meetings::MeetingsHelper, Meetings::RegistrationMailer, Pages::PageSerializer, Proposals::Admin::ProposalBaseForm, Proposals::Admin::ProposalsController, Proposals::CollaborativeDraftCellsHelper, Proposals::CollaborativeDraftsController, Proposals::MapHelper, Proposals::ProposalCellsHelper, Proposals::ProposalMentionedEvent, Proposals::ProposalSerializer, Proposals::ProposalsController, Proposals::VersionsController, ResourceHiddenEvent, TraceabilityHelper, ViewModel
Defined in:
decidim-core/app/helpers/decidim/application_helper.rb

Overview

Main module to add application-wide helpers.

Constant Summary

Constants included from AmendmentsHelper

Decidim::AmendmentsHelper::TOTAL_STEPS

Instance Method Summary collapse

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 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

#add_body_classes(*class_names) ⇒ Object



117
118
119
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 117

def add_body_classes(*class_names)
  content_for :body_class, class_names.map { |class_name| " #{class_name.strip}" }.join
end

#cell(name, model, options = {}) ⇒ Object

Public: Overwrites the cell helper method to automatically set some common context.

name - the name of the cell to render model - the cell model options - a Hash with options

Renders the cell contents.



104
105
106
107
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 104

def cell(name, model, options = {}, &)
  options = { context: { view_context: self, current_user: } }.deep_merge(options)
  super
end

Generates a link to be added to the global Edit link so admins can easily manage data without having to look for it at the admin panel when they are at a public page.

link_url - The String with the URL. action - The Symbol action to check the permissions for. subject - The Symbol subject to perform the action to. extra_context - An optional Hash to check the permissions. link_options - An optional Hash to change the default name and icon link. link_options - An optional String to be used as the label of the link. link_options - An optional String with the identifier name of the icon. link_options - An optional String to add as a css class to the link wrapper.

Returns nothing.



64
65
66
67
68
69
70
71
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 64

def edit_link(link_url, action, subject, extra_context = {}, link_options = {})
  return unless current_user
  return unless admin_allowed_to?(action, subject, extra_context)
  return if content_for?(:edit_link)

  cell_html = raw(cell("decidim/navbar_admin_link", link_url:, link_options:))
  content_for(:edit_link, cell_html)
end

Generates a second link to be added to the global admin action link so admins can easily manage data without having to look for it at the admin panel when they are at a public page.

link_url - The String with the URL. action - The Symbol action to check the permissions for. subject - The Symbol subject to perform the action to. extra_context - An optional Hash to check the permissions. link_options - An optional Hash to change the default name and icon link. link_options - An optional String to be used as the label of the link. link_options - An optional String with the identifier name of the icon. link_options - An optional String to add as a css class to the link wrapper.

Returns nothing.



87
88
89
90
91
92
93
94
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 87

def extra_admin_link(link_url, action, subject, extra_context = {}, link_options = {})
  return unless current_user
  return unless admin_allowed_to?(action, subject, extra_context)
  return if content_for?(:extra_admin_link)

  cell_html = raw(cell("decidim/navbar_admin_link", link_url:, link_options:))
  content_for(:extra_admin_link, cell_html)
end

#html_truncate(text, options = {}) ⇒ Object

Truncates a given text respecting its HTML tags.

text - The String text to be truncated. options - A Hash with the options to truncate the text (default: {}): :length - An Integer number with the max length of the text. :separator - A String to append to the text when it is being truncated.

Returns a String.



25
26
27
28
29
30
31
32
33
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 25

def html_truncate(text, options = {})
  options[:max_length] = options.delete(:length) || options[:max_length]
  options[:tail] = options.delete(:separator) || options[:tail] || ""
  options[:count_tags] ||= false
  options[:count_tail] ||= false
  options[:tail_before_final_tag] = true unless options.has_key?(:tail_before_final_tag)

  Decidim::HtmlTruncation.new(text, options).perform
end

#layout_item_classesObject



12
13
14
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 12

def layout_item_classes
  "layout-item"
end

#present(object, presenter_class: nil) {|presenter| ... } ⇒ Object

Yields:

  • (presenter)


35
36
37
38
39
40
41
42
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 35

def present(object, presenter_class: nil)
  presenter_class ||= resolve_presenter_class(object, presenter_class:)
  presenter = presenter_class.new(object)

  yield(presenter) if block_given?

  presenter
end

#prevent_timeout_secondsObject



109
110
111
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 109

def prevent_timeout_seconds
  0
end

#resolve_presenter_class(object, presenter_class: nil) ⇒ Object



44
45
46
47
48
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 44

def resolve_presenter_class(object, presenter_class: nil)
  presenter_class || "#{object.class.name}Presenter".constantize
rescue StandardError
  ::Decidim::NilPresenter
end

#text_initials(name) ⇒ Object



113
114
115
# File 'decidim-core/app/helpers/decidim/application_helper.rb', line 113

def text_initials(name)
  name.split(/[\s.]+/).map(&:chr).slice(0, 2).join.upcase
end