Module: Decidim::EnhancedTextwork::ParticipatoryTextsHelper

Defined in:
app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb

Overview

Simple helper to handle markup variations for participatory texts related partials

Instance Method Summary collapse

Instance Method Details

#hide_paragraph_title?(paragraph) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb', line 44

def hide_paragraph_title?(paragraph)
  paragraph.component.settings.hide_participatory_text_titles_enabled? && translated_attribute(paragraph.title) !~ /\D/
end

#mime_types_with_document_examplesObject

Public: A formatted collection of mime_type to be used in forms.



28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb', line 28

def mime_types_with_document_examples
  links = ""
  accepted_mime_types = Decidim::EnhancedTextwork::DocToMarkdown::ACCEPTED_MIME_TYPES.keys
  accepted_mime_types.each_with_index do |mime_type, index|
    links += link_to t(".accepted_mime_types.#{mime_type}"),
                     asset_pack_path("media/documents/participatory_text.#{mime_type}"),
                     download: "participatory_text.#{mime_type}"
    links += ", " unless accepted_mime_types.length == index + 1
  end
  links
end

#preview_participatory_text_section_title(paragraph) ⇒ Object

Returns the title for a given participatory text section.

paragraph - The current paragraph item.

Returns a string with the title of the section, subsection or article.



12
13
14
15
16
# File 'app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb', line 12

def preview_participatory_text_section_title(paragraph)
  title = decidim_html_escape(present(paragraph).title)
  translated = t(paragraph.participatory_text_level, scope: "decidim.enhanced_textwork.admin.participatory_texts.sections", title: title)
  translated.html_safe
end

#render_participatory_text_title(participatory_text) ⇒ Object



18
19
20
21
22
23
24
# File 'app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb', line 18

def render_participatory_text_title(participatory_text)
  if participatory_text.nil?
    t("alternative_title", scope: "decidim.enhanced_textwork.participatory_text_paragraph")
  else
    translated_attribute(participatory_text.title)
  end
end

#show_paragraph_title?(paragraph) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb', line 40

def show_paragraph_title?(paragraph)
  !hide_paragraph_title?(paragraph)
end