Module: Decidim::Debates::ApplicationHelper

Includes:
CheckBoxesTreeHelper, Comments::CommentsHelper, Decidim::DateRangeHelper, EndorsableHelper, FollowableHelper, PaginateHelper, RichTextEditorHelper
Defined in:
decidim-debates/app/helpers/decidim/debates/application_helper.rb

Overview

Custom helpers, scoped to the debates engine.

Instance Method Summary collapse

Methods included from Decidim::DateRangeHelper

#format_date_range

Methods included from CheckBoxesTreeHelper

#check_boxes_tree_options, #filter_areas_values, #filter_categories_values, #filter_global_scopes_values, #filter_scopes_values, #filter_text_for, #filter_tree_from_array, #flat_filter_values, #resource_filter_scope_values

Methods included from FollowableHelper

#follow_button_for

Methods included from EndorsableHelper

#current_user_can_endorse?, #endorsement_buttons_cell, #endorsements_blocked?, #endorsements_enabled?, #endorsers_list_cell, #fully_endorsed?, #path_to_create_endorsement, #path_to_destroy_endorsement, #render_endorsement_identity, #show_endorsements_card?

Methods included from RichTextEditorHelper

included, #text_editor_for

Methods included from Comments::CommentsHelper

#comments_for, #inline_comments_for

Methods included from PaginateHelper

#decidim_paginate, #per_page

Instance Method Details

#activity_filter_valuesObject

Options to filter Debates by activity.



56
57
58
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 56

def activity_filter_values
  %w(all my_debates commented).map { |k| [k, t(k, scope: "decidim.debates.debates.filters")] }
end

#all_filter_textObject



68
69
70
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 68

def all_filter_text
  t("all", scope: "decidim.debates.debates.filters")
end

#component_nameObject



96
97
98
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 96

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

#filter_debates_state_valuesObject

Returns a TreeNode to be used in the list filters to filter debates by its state.



62
63
64
65
66
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 62

def filter_debates_state_values
  %w(open closed).map { |k| [k, t(k, scope: "decidim.debates.debates.filters.state_values")] }.prepend(
    ["all", all_filter_text]
  )
end

#filter_origin_valuesObject

Returns a TreeNode to be used in the list filters to filter debates by its origin.



45
46
47
48
49
50
51
52
53
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 45

def filter_origin_values
  origin_keys = %w(official participants)
  origin_keys << "user_group" if current_organization.user_groups_enabled?

  origin_values = origin_keys.map { |key| [key, t(key, scope: "decidim.debates.debates.filters")] }
  origin_values.prepend(["", all_filter_text])

  filter_tree_from_array(origin_values)
end

#filter_sectionsObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 72

def filter_sections
  @filter_sections ||= begin
    items = [{
      method: :with_any_state,
      collection: filter_debates_state_values,
      label_scope: "decidim.meetings.meetings.filters",
      id: "date",
      type: :radio_buttons
    }]
    if current_component.has_subscopes?
      items.append(method: :with_any_scope, collection: filter_scopes_values, label_scope: "decidim.shared.participatory_space_filters.filters", id: "scope")
    end
    if current_participatory_space.categories.any?
      items.append(method: :with_any_category, collection: filter_categories_values, label_scope: "decidim.debates.debates.filters", id: "category")
    end
    items.append(method: :with_any_origin, collection: filter_origin_values, label_scope: "decidim.debates.debates.filters", id: "origin")
    items.append(method: :activity, collection: activity_filter_values, label_scope: "decidim.debates.debates.filters", id: "activity") if current_user

    items.reject { |item| item[:collection].blank? }
  end
end

#render_debate_description(debate) ⇒ Object

If the content is safe, HTML tags are sanitized, otherwise, they are stripped.



29
30
31
32
33
34
35
36
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 29

def render_debate_description(debate)
  sanitized = render_sanitized_content(debate, :description)
  if safe_content?
    Decidim::ContentProcessor.render_without_format(sanitized).html_safe
  else
    Decidim::ContentProcessor.render(sanitized, "div")
  end
end

#safe_content?Boolean

If the debate is official or the rich text editor is enabled on the frontend, the debate description is considered as safe content.

Returns:

  • (Boolean)


18
19
20
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 18

def safe_content?
  rich_text_editor_in_public_views? || safe_content_admin?
end

#safe_content_admin?Boolean

For admin entered content, the debate body can contain certain extra tags, such as iframes.

Returns:

  • (Boolean)


24
25
26
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 24

def safe_content_admin?
  debate&.official?
end

#search_variableObject



94
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 94

def search_variable = :search_text_cont

#text_editor_for_debate_description(form) ⇒ Object

Returns :text_area or :editor based on current_component settings.



39
40
41
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 39

def text_editor_for_debate_description(form)
  text_editor_for(form, :description)
end