Module: Decidim::Accountability::ApplicationHelper

Includes:
Comments::CommentsHelper, PaginateHelper
Included in:
HighlightedResultsForComponentCell, ProjectCell, ResultLCell, StatusCell
Defined in:
app/helpers/decidim/accountability/application_helper.rb

Overview

Custom helpers, scoped to the accountability engine.

Instance Method Summary collapse

Instance Method Details

#apply_accountability_pack_tagsObject



53
54
55
56
# File 'app/helpers/decidim/accountability/application_helper.rb', line 53

def apply_accountability_pack_tags
  append_stylesheet_pack_tag("decidim_accountability", media: "all")
  append_javascript_pack_tag("decidim_accountability")
end

#component_nameObject



17
18
19
# File 'app/helpers/decidim/accountability/application_helper.rb', line 17

def component_name
  (defined?(current_component) && translated_attribute(current_component&.name).presence) || t("decidim.components.accountability.name")
end

#display_percentage(number) ⇒ Object



11
12
13
14
15
# File '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



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/helpers/decidim/accountability/application_helper.rb', line 21

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