Class: Decidim::ResourcePresenter

Inherits:
SimpleDelegator
  • Object
show all
Includes:
SanitizeHelper, TranslatableAttributes
Defined in:
app/presenters/decidim/resource_presenter.rb

Overview

A presenter to render attributes for resources

Instance Method Summary collapse

Methods included from SanitizeHelper

#decidim_html_escape, #decidim_sanitize, #decidim_sanitize_newsletter, #decidim_url_escape, included

Methods included from TranslatableAttributes

#default_locale?

Instance Method Details

#handle_locales(content, all_locales, &block) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/presenters/decidim/resource_presenter.rb', line 18

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

#title(resource_title, links, html_escape, all_locales, extras: true) ⇒ Object



9
10
11
12
13
14
15
16
# File 'app/presenters/decidim/resource_presenter.rb', line 9

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