Class: Decidim::ResourcePresenter
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Decidim::ResourcePresenter
- Includes:
- SanitizeHelper, TranslatableAttributes
- Defined in:
- app/presenters/decidim/resource_presenter.rb
Overview
A presenter to render attributes for resources
Instance Method Summary collapse
-
#editor_locales(data, all_locales, extras: true) ⇒ Object
Prepares the HTML content for the editors with the correct tags included to identify the hashtags and mentions.
- #handle_locales(content, all_locales, &block) ⇒ Object
- #title(resource_title, links, html_escape, all_locales, extras: true) ⇒ Object
Methods included from SanitizeHelper
#decidim_escape_translated, #decidim_html_escape, #decidim_sanitize, #decidim_sanitize_admin, #decidim_sanitize_editor, #decidim_sanitize_editor_admin, #decidim_sanitize_newsletter, #decidim_sanitize_translated, #decidim_url_escape, included
Methods included from TranslatableAttributes
Instance Method Details
#editor_locales(data, all_locales, extras: true) ⇒ Object
Prepares the HTML content for the editors with the correct tags included to identify the hashtags and mentions.
34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'app/presenters/decidim/resource_presenter.rb', line 34 def editor_locales(data, all_locales, extras: true) handle_locales(data, all_locales) do |content| [ Decidim::ContentRenderers::HashtagRenderer, Decidim::ContentRenderers::UserRenderer, Decidim::ContentRenderers::UserGroupRenderer ].each do |renderer_class| renderer = renderer_class.new(content) content = renderer.render(links: false, editor: true, extras:).html_safe end content end end |
#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:, extras:).html_safe end end |