Module: Decidim::Accountability::ApplicationHelper
- Includes:
- Comments::CommentsHelper, PaginateHelper
- Included in:
- HighlightedResultsForComponentCell
- Defined in:
- decidim-accountability/app/helpers/decidim/accountability/application_helper.rb
Overview
Custom helpers, scoped to the accountability engine.
Instance Method Summary collapse
- #active_class_if_current(scope) ⇒ Object
- #apply_accountability_pack_tags ⇒ Object
- #categories_label ⇒ Object
- #component_name ⇒ Object
- #display_count(count) ⇒ Object
- #display_percentage(number) ⇒ Object
- #filter_items_for(participatory_space:, category:) ⇒ Object
- #heading_leaf_level_results(count) ⇒ Object
- #heading_parent_level_results(count) ⇒ Object
- #subcategories_label ⇒ Object
Methods included from Comments::CommentsHelper
#comments_for, #inline_comments_for
Methods included from PaginateHelper
Instance Method Details
#active_class_if_current(scope) ⇒ Object
21 22 23 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 21 def active_class_if_current(scope) "class=active" if scope.to_s == current_scope.to_s end |
#apply_accountability_pack_tags ⇒ Object
87 88 89 90 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 87 def append_stylesheet_pack_tag("decidim_accountability", media: "all") append_javascript_pack_tag("decidim_accountability") end |
#categories_label ⇒ Object
29 30 31 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 29 def categories_label translated_attribute(component_settings.categories_label).presence || t("results.home.categories_label", scope: "decidim.accountability") end |
#component_name ⇒ Object
25 26 27 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 25 def component_name (defined?(current_component) && translated_attribute(current_component&.name).presence) || t("decidim.components.accountability.name") end |
#display_count(count) ⇒ Object
17 18 19 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 17 def display_count(count) heading_parent_level_results(count) end |
#display_percentage(number) ⇒ Object
11 12 13 14 15 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 11 def display_percentage(number) return if number.blank? number_to_percentage(number, precision: 1, strip_insignificant_zeros: true, locale: I18n.locale) end |
#filter_items_for(participatory_space:, category:) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 55 def filter_items_for(participatory_space:, category:) [ { url: url_for(filter: { with_category: category.try(:id) }), text: t("results.filters.all", scope: "decidim.accountability"), icon: "apps-2-line", active: current_scope.blank?, sr_text: Decidim::Scope.model_name.human(count: 2) }, *( if participatory_space.scope [{ url: url_for(filter: { with_scope: participatory_space.scope.id, with_category: category.try(:id) }), text: translated_attribute(participatory_space.scope.name), icon: resource_type_icon_key(participatory_space.scope.class), active: participatory_space.scope.id.to_s == current_scope.to_s, sr_text: Decidim::Scope.model_name.human(count: 1) }] end ), *participatory_space.subscopes.map do |scope| { url: url_for(filter: { with_scope: scope.id, with_category: category.try(:id) }), text: translated_attribute(scope.name), icon: resource_type_icon_key(scope.class), active: scope.id.to_s == current_scope.to_s, sr_text: Decidim::Scope.model_name.human(count: 1) } end ] end |
#heading_leaf_level_results(count) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 46 def heading_leaf_level_results(count) text = translated_attribute(component_settings.heading_leaf_level_results).presence if text pluralize(count, text) else t("results.count.results_count", scope: "decidim.accountability", count:) end end |
#heading_parent_level_results(count) ⇒ Object
37 38 39 40 41 42 43 44 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 37 def heading_parent_level_results(count) text = translated_attribute(component_settings.heading_parent_level_results).presence if text pluralize(count, text) else t("results.count.results_count", scope: "decidim.accountability", count:) end end |
#subcategories_label ⇒ Object
33 34 35 |
# File 'decidim-accountability/app/helpers/decidim/accountability/application_helper.rb', line 33 def subcategories_label translated_attribute(component_settings.subcategories_label).presence || t("results.home.subcategories_label", scope: "decidim.accountability") end |