Module: Decidim::ApplicationHelper
- Included in:
- ActivityCell, Decidim::Amendable::AmendersListCell, Decidim::Amendable::AnnouncementCell, AmendmentsController, BadgeCell, BadgesCell, CardMCell, CoauthorshipsCell, EndorsersListCell, Exporters::ParticipatorySpaceComponentsSerializer, FollowersCell, FollowingCell, GroupsCell, MembersCell, PadIframeCell, ProfileCell, ProfileSidebarCell, ScopesPickerCell, UserConversationCell, UserConversationsCell, UserGroupPendingInvitationsListCell, UserGroupPendingRequestsListCell, VersionAuthorCell
- Defined in:
- app/helpers/decidim/application_helper.rb
Overview
Main module to add application-wide helpers.
Instance Method Summary collapse
-
#cell(name, model, options = {}, &block) ⇒ Object
Public: Overwrites the ‘cell` helper method to automatically set some common context.
-
#edit_link(link_url, action, subject, extra_context = {}, link_options = { class: "topbar__edit__link" }) ⇒ Object
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’re at a public page.
-
#extra_admin_link(link_url, action, subject, extra_context = {}, link_options = {}) ⇒ Object
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’re at a public page.
-
#html_truncate(text, options = {}) ⇒ Object
Truncates a given text respecting its HTML tags.
- #present(object, presenter_class: nil) {|presenter| ... } ⇒ Object
- #resolve_presenter_class(object, presenter_class: nil) ⇒ Object
-
#step_cta_url(process) ⇒ Object
Public: Builds the URL for the step Call To Action.
Methods included from CacheHelper
Methods included from AmendmentsHelper
#accept_and_reject_buttons_for, #action_button_card_for, #allowed_to_accept_and_reject?, #allowed_to_promote?, #amend_button_for, #amenders_list_for, #amendments_enabled?, #amendments_for, #amendments_form_field_for, #amendments_form_fields_label, #amendments_form_fields_value, #can_participate_in_private_space?, #can_react_to_emendation?, #emendation_actions_for, #emendation_announcement_for, #promote_button_for, #render_emendation_body
Methods included from RichTextEditorHelper
Methods included from ContextualHelpHelper
Methods included from ScopesHelper
#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_picker_tag
Methods included from TranslatableAttributes
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, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag
Methods included from OmniauthHelper
#normalize_provider_name, #oauth_icon, #provider_name
Instance Method Details
#cell(name, model, options = {}, &block) ⇒ 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.
100 101 102 103 |
# File 'app/helpers/decidim/application_helper.rb', line 100 def cell(name, model, = {}, &block) = { context: { current_user: current_user } }.deep_merge() super(name, model, , &block) end |
#edit_link(link_url, action, subject, extra_context = {}, link_options = { class: "topbar__edit__link" }) ⇒ Object
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’re 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.
60 61 62 63 64 65 66 67 |
# File 'app/helpers/decidim/application_helper.rb', line 60 def edit_link(link_url, action, subject, extra_context = {}, = { class: "topbar__edit__link" }) 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_url, link_options: )) content_for(:edit_link, cell_html) end |
#extra_admin_link(link_url, action, subject, extra_context = {}, link_options = {}) ⇒ Object
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’re 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.
83 84 85 86 87 88 89 90 |
# File 'app/helpers/decidim/application_helper.rb', line 83 def extra_admin_link(link_url, action, subject, extra_context = {}, = {}) 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_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's being
truncated. See `truncato` gem for more options.
Returns a String.
21 22 23 24 25 26 27 28 29 |
# File 'app/helpers/decidim/application_helper.rb', line 21 def html_truncate(text, = {}) [:max_length] = .delete(:length) || [:max_length] [:tail] = .delete(:separator) || [:tail] || "..." [:count_tags] ||= false [:count_tail] ||= false [:tail_before_final_tag] = true unless .has_key?(:tail_before_final_tag) Truncato.truncate(text, ) end |
#present(object, presenter_class: nil) {|presenter| ... } ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'app/helpers/decidim/application_helper.rb', line 31 def present(object, presenter_class: nil) presenter_class ||= resolve_presenter_class(object, presenter_class: presenter_class) presenter = presenter_class.new(object) yield(presenter) if block_given? presenter end |
#resolve_presenter_class(object, presenter_class: nil) ⇒ Object
40 41 42 43 44 |
# File 'app/helpers/decidim/application_helper.rb', line 40 def resolve_presenter_class(object, presenter_class: nil) presenter_class || "#{object.class.name}Presenter".constantize rescue StandardError ::Decidim::NilPresenter end |
#step_cta_url(process) ⇒ Object
Public: Builds the URL for the step Call To Action. Takes URL params into account.
process - a ParticipatoryProcess
Returns a String that can be used as a URL.
111 112 113 114 115 116 117 118 119 120 121 |
# File 'app/helpers/decidim/application_helper.rb', line 111 def step_cta_url(process) return unless respond_to?(:decidim_participatory_processes) base_url, params = decidim_participatory_processes.participatory_process_path(process).split("?") if params.present? [base_url, "/", process.active_step.cta_path, "?", params].join("") else [base_url, "/", process.active_step.cta_path].join("") end end |