Sha256: e2f214ba507a90c64a16814553d1188fc4e7bb1487314e8350ede390dacf6797

Contents?: true

Size: 1.07 KB

Versions: 30

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module Decidim
  # A presenter to render attributes for resources
  class ResourcePresenter < SimpleDelegator
    include Decidim::TranslatableAttributes
    include Decidim::SanitizeHelper

    def title(resource_title, links, html_escape, all_locales, extras: true)
      handle_locales(resource_title, all_locales) do |content|
        content = decidim_html_escape(content) if html_escape

        renderer = Decidim::ContentRenderers::HashtagRenderer.new(content)
        renderer.render(links: links, extras: extras).html_safe
      end
    end

    def handle_locales(content, all_locales, &block)
      if all_locales
        content.each_with_object({}) do |(key, value), parsed_content|
          parsed_content[key] = if key == "machine_translations"
                                  handle_locales(value, all_locales, &block)
                                else
                                  block.call(value)
                                end
        end
      else
        yield(translated_attribute(content))
      end
    end
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
decidim-core-0.27.9 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.8 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.7 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.6 app/presenters/decidim/resource_presenter.rb
decidim-core-0.26.10 app/presenters/decidim/resource_presenter.rb
decidim-core-0.26.9 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.5 app/presenters/decidim/resource_presenter.rb
decidim-core-0.26.8 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.4 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.3 app/presenters/decidim/resource_presenter.rb
decidim-core-0.26.7 app/presenters/decidim/resource_presenter.rb
decidim-core-0.26.5 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.2 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.1 app/presenters/decidim/resource_presenter.rb
decidim-core-0.26.4 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.0 app/presenters/decidim/resource_presenter.rb
decidim-core-0.26.3 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.0.rc2 app/presenters/decidim/resource_presenter.rb
decidim-core-0.27.0.rc1 app/presenters/decidim/resource_presenter.rb
decidim-core-0.26.2 app/presenters/decidim/resource_presenter.rb