Module: Decidim::Debates::ApplicationHelper

Includes:
CheckBoxesTreeHelper, Comments::CommentsHelper, 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 CheckBoxesTreeHelper

#check_boxes_tree_options, #filter_categories_values, #filter_scopes_values, #filter_scopes_values_from, #filter_scopes_values_from_parent, #filter_tree_from, #resource_filter_scope_values, #scope_children_to_tree

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

Instance Method Details

#activity_filter_valuesObject

Options to filter Debates by activity.


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

def activity_filter_values
  base = [
    ["all", t("decidim.debates.debates.filters.all")],
    ["my_debates", t("decidim.debates.debates.filters.my_debates")]
  ]
  base += [["commented", t("decidim.debates.debates.filters.commented")]]
  base
end

#filter_debates_state_valuesObject

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


56
57
58
59
60
61
62
63
64
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 56

def filter_debates_state_values
  Decidim::CheckBoxesTreeHelper::TreeNode.new(
    Decidim::CheckBoxesTreeHelper::TreePoint.new("", t("decidim.debates.debates.filters.all")),
    [
      Decidim::CheckBoxesTreeHelper::TreePoint.new("open", t("decidim.debates.debates.filters.state_values.open")),
      Decidim::CheckBoxesTreeHelper::TreePoint.new("closed", t("decidim.debates.debates.filters.state_values.closed"))
    ]
  )
end

#filter_origin_valuesObject

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


35
36
37
38
39
40
41
42
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 35

def filter_origin_values
  origin_values = []
  origin_values << TreePoint.new("official", t("decidim.debates.debates.filters.official"))
  origin_values << TreePoint.new("citizens", t("decidim.debates.debates.filters.citizens"))
  origin_values << TreePoint.new("user_group", t("decidim.debates.debates.filters.user_groups")) if current_organization.user_groups_enabled?

  TreeNode.new(TreePoint.new("", t("decidim.debates.debates.filters.all")), origin_values)
end

#render_debate_description(debate) ⇒ Object

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


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

def render_debate_description(debate)
  description = present(debate).description(strip_tags: !safe_content?, links: true)

  safe_content? ? decidim_sanitize(description) : simple_format(description)
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)

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

def safe_content?
  debate&.official? || rich_text_editor_in_public_views?
end

#text_editor_for_debate_description(form) ⇒ Object

Returns :text_area or :editor based on current_component settings.


29
30
31
# File 'decidim-debates/app/helpers/decidim/debates/application_helper.rb', line 29

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