Sha256: 50a18d8f1dcc1f4fd9de730c5a841dc75ea7ae5304b4e1f626c22912177aef10

Contents?: true

Size: 1.9 KB

Versions: 6

Compression:

Stored size: 1.9 KB

Contents

# frozen_string_literal: true

module Decidim
  module EnhancedTextwork
    # Simple helper to handle markup variations for participatory texts related partials
    module ParticipatoryTextsHelper
      # 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.
      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

      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

      # Public: A formatted collection of mime_type to be used
      # in forms.
      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

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

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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
decidim-enhanced_textwork-1.0.5 app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb
decidim-enhanced_textwork-1.0.4 app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb
decidim-enhanced_textwork-1.0.3 app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb
decidim-enhanced_textwork-1.0.2 app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb
decidim-enhanced_textwork-1.0.1 app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb
decidim-enhanced_textwork-1.0.0 app/helpers/decidim/enhanced_textwork/participatory_texts_helper.rb