Class: Decidim::EnhancedTextwork::ParagraphPresenter
- Inherits:
-
ResourcePresenter
- Object
- ResourcePresenter
- Decidim::EnhancedTextwork::ParagraphPresenter
- Includes:
- ActionView::Helpers::UrlHelper
- Defined in:
- app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb
Overview
Decorator for paragraphs
Direct Known Subclasses
Instance Method Summary collapse
- #author ⇒ Object
- #body(links: false, extras: true, strip_tags: false, all_locales: false) ⇒ Object
- #display_mention ⇒ Object
- #id_and_title(links: false, extras: true, html_escape: false) ⇒ Object
- #paragraph ⇒ Object
- #paragraph_path ⇒ Object
- #resource_manifest ⇒ Object
-
#title(links: false, extras: true, html_escape: false, all_locales: false) ⇒ Object
Render the paragraph title.
-
#title_if_enabled ⇒ Object
Render the paragraph title if it is not numeric and if showing it is enabled.
-
#versions ⇒ Object
Returns the paragraph versions, hiding not published answers.
Instance Method Details
#author ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 12 def @author ||= if official? Decidim::EnhancedTextwork::OfficialAuthorPresenter.new else = .includes(:author, :user_group).first .user_group&.presenter || ..presenter end end |
#body(links: false, extras: true, strip_tags: false, all_locales: false) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 62 def body(links: false, extras: true, strip_tags: false, all_locales: false) return unless paragraph handle_locales(paragraph.body, all_locales) do |content| content = (sanitize_text(content)) if renderer = Decidim::ContentRenderers::HashtagRenderer.new(content) content = renderer.render(links: links, extras: extras).html_safe content = Decidim::ContentRenderers::LinkRenderer.new(content).render if links content end end |
#display_mention ⇒ Object
29 30 31 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 29 def display_mention link_to title, paragraph_path end |
#id_and_title(links: false, extras: true, html_escape: false) ⇒ Object
58 59 60 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 58 def id_and_title(links: false, extras: true, html_escape: false) "##{paragraph.id} - #{title(links: links, extras: extras, html_escape: html_escape)}" end |
#paragraph ⇒ Object
21 22 23 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 21 def paragraph __getobj__ end |
#paragraph_path ⇒ Object
25 26 27 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 25 def paragraph_path Decidim::ResourceLocatorPresenter.new(paragraph).path end |
#resource_manifest ⇒ Object
102 103 104 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 102 def resource_manifest paragraph.class.resource_manifest end |
#title(links: false, extras: true, html_escape: false, all_locales: false) ⇒ Object
Render the paragraph title
links - should render hashtags as links? extras - should include extra hashtags?
Returns a String.
39 40 41 42 43 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 39 def title(links: false, extras: true, html_escape: false, all_locales: false) return unless paragraph super paragraph.title, links, html_escape, all_locales, extras: extras end |
#title_if_enabled ⇒ Object
Render the paragraph title if it is not numeric and if showing it is enabled
links - should render hashtags as links? extras - should include extra hashtags?
Returns a String.
51 52 53 54 55 56 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 51 def title_if_enabled return unless paragraph return "" if paragraph.component.settings.hide_participatory_text_titles_enabled? && translated_attribute(paragraph.title) !~ /\D/ translated_attribute(paragraph.title) end |
#versions ⇒ Object
Returns the paragraph versions, hiding not published answers
Returns an Array.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'app/presenters/decidim/enhanced_textwork/paragraph_presenter.rb', line 79 def versions version_state_published = false pending_state_change = nil paragraph.versions.map do |version| state_published_change = version.changeset["state_published_at"] version_state_published = state_published_change.last.present? if state_published_change if version_state_published version.changeset["state"] = pending_state_change if pending_state_change pending_state_change = nil elsif version.changeset["state"] pending_state_change = version.changeset.delete("state") end next if version.event == "update" && Decidim::EnhancedTextwork::DiffRenderer.new(version).diff.empty? version end.compact end |