Module: Decidim::Debates::ApplicationHelper
- Includes:
- CheckBoxesTreeHelper, Comments::CommentsHelper, Decidim::DateRangeHelper, FollowableHelper, LikeableHelper, RichTextEditorHelper, PaginateHelper
- Defined in:
- app/helpers/decidim/debates/application_helper.rb
Overview
Custom helpers, scoped to the debates engine.
Instance Method Summary collapse
-
#activity_filter_values ⇒ Object
Options to filter Debates by activity.
- #all_filter_text ⇒ Object
- #component_name ⇒ Object
-
#filter_debates_state_values ⇒ Object
Returns a TreeNode to be used in the list filters to filter debates by its state.
-
#filter_origin_values ⇒ Object
Returns a TreeNode to be used in the list filters to filter debates by its origin.
- #filter_sections ⇒ Object
-
#render_debate_description(debate) ⇒ Object
If the content is safe, HTML tags are sanitized, otherwise, they are stripped.
-
#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.
-
#safe_content_admin? ⇒ Boolean
For admin entered content, the debate body can contain certain extra tags, such as iframes.
- #search_variable ⇒ Object
-
#text_editor_for_debate_description(form) ⇒ Object
Returns :text_area or :editor based on current_component settings.
Instance Method Details
#activity_filter_values ⇒ Object
Options to filter Debates by activity.
55 56 57 |
# File 'app/helpers/decidim/debates/application_helper.rb', line 55 def activity_filter_values %w(all my_debates commented).map { |k| [k, t(k, scope: "decidim.debates.debates.filters")] } end |
#all_filter_text ⇒ Object
67 68 69 |
# File 'app/helpers/decidim/debates/application_helper.rb', line 67 def all_filter_text t("all", scope: "decidim.debates.debates.filters") end |
#component_name ⇒ Object
107 108 109 |
# File 'app/helpers/decidim/debates/application_helper.rb', line 107 def component_name (defined?(current_component) && translated_attribute(current_component&.name).presence) || t("decidim.components.debates.name") end |
#filter_debates_state_values ⇒ Object
Returns a TreeNode to be used in the list filters to filter debates by its state.
61 62 63 64 65 |
# File 'app/helpers/decidim/debates/application_helper.rb', line 61 def filter_debates_state_values %w(ongoing closed).map { |k| [k, t(k, scope: "decidim.debates.debates.filters.state_values")] }.prepend( ["all", all_filter_text] ) end |
#filter_origin_values ⇒ Object
Returns a TreeNode to be used in the list filters to filter debates by its origin.
45 46 47 48 49 50 51 52 |
# File 'app/helpers/decidim/debates/application_helper.rb', line 45 def filter_origin_values origin_keys = %w(official participants) 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_sections ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'app/helpers/decidim/debates/application_helper.rb', line 71 def filter_sections @filter_sections ||= begin items = [{ method: :with_any_state, name: "[with_any_state]", collection: filter_debates_state_values, label: t("decidim.debates.debates.filters.state"), id: "date", type: :radio_buttons }] current_component.available_taxonomy_filters.each do |taxonomy_filter| items.append(method: :with_any_taxonomies, name: "[with_any_taxonomies][#{taxonomy_filter.root_taxonomy_id}]", collection: filter_taxonomy_values_for(taxonomy_filter), label: decidim_sanitize_translated(taxonomy_filter.name), id: "taxonomy-#{taxonomy_filter.root_taxonomy_id}") end items.append(method: :with_any_origin, name: "[with_any_origin]", collection: filter_origin_values, label: t("decidim.debates.debates.filters.origin"), id: "origin") if current_user items.append(method: :activity, name: "[activity]", collection: activity_filter_values, label: t("decidim.debates.debates.filters.activity"), id: "activity") end 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 '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.
18 19 20 |
# File '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.
24 25 26 |
# File 'app/helpers/decidim/debates/application_helper.rb', line 24 def safe_content_admin? debate&.official? end |
#search_variable ⇒ Object
105 |
# File 'app/helpers/decidim/debates/application_helper.rb', line 105 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 'app/helpers/decidim/debates/application_helper.rb', line 39 def text_editor_for_debate_description(form) text_editor_for(form, :description) end |