Module: Decidim::ApplicationHelper
- Includes:
- OmniauthHelper, ScopesHelper
- Included in:
- BadgeCell, BadgesCell, CardMCell, CoauthorshipsCell, FollowersCell, FollowingCell, ProfileCell
- Defined in:
- app/helpers/decidim/application_helper.rb
Overview
Main module to add application-wide helpers.
Instance Method Summary collapse
-
#edit_link(link, action, subject, extra_context = {}) ⇒ 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.
-
#html_truncate(text, options = {}) ⇒ Object
Truncates a given text respecting its HTML tags.
- #present(object) {|presenter| ... } ⇒ Object
Methods included from ScopesHelper
#has_visible_scopes?, #scope_name_for_picker, #scopes_picker_field, #scopes_picker_filter, #scopes_picker_tag
Methods included from DecidimFormHelper
#base_error_messages, #decidim_form_for, #decidim_form_slug_url, #editor_field_tag, #form_field_has_error?, #foundation_datepicker_locale_tag, #name_with_locale, #scopes_picker_field_tag, #tab_element_class_for, #translated_field_tag
Methods included from OmniauthHelper
#any_social_provider_enabled?, #normalize_provider_name, #oauth_icon, #social_provider_enabled?
Instance Method Details
#edit_link(link, action, subject, extra_context = {}) ⇒ 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 - 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.
Returns nothing.
46 47 48 49 50 51 52 |
# File 'app/helpers/decidim/application_helper.rb', line 46 def edit_link(link, action, subject, extra_context = {}) return unless current_user return unless admin_allowed_to?(action, subject, extra_context) return if content_for?(:edit_link) content_for(:edit_link, link) 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.
18 19 20 21 22 23 24 25 26 |
# File 'app/helpers/decidim/application_helper.rb', line 18 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 Truncato.truncate(text, ) end |
#present(object) {|presenter| ... } ⇒ Object
28 29 30 31 32 33 34 |
# File 'app/helpers/decidim/application_helper.rb', line 28 def present(object) presenter = "#{object.class.name}Presenter".constantize.new(object) yield(presenter) if block_given? presenter end |