Class: Decidim::Proposals::ProposalPresenter
- Inherits:
-
ResourcePresenter
- Object
- ResourcePresenter
- Decidim::Proposals::ProposalPresenter
- Includes:
- ActionView::Helpers::UrlHelper
- Defined in:
- app/presenters/decidim/proposals/proposal_presenter.rb
Overview
Decorator for proposals
Instance Method Summary collapse
- #author ⇒ Object
- #body(links: false, strip_tags: false, all_locales: false) ⇒ Object
- #display_mention ⇒ Object
- #editor_body(all_locales: false) ⇒ Object
- #id_and_title(html_escape: false) ⇒ Object
- #proposal ⇒ Object
- #proposal_path ⇒ Object
- #resource_manifest ⇒ Object
-
#title(html_escape: false, all_locales: false) ⇒ Object
Render the proposal title.
-
#versions ⇒ Object
Returns the proposal versions, hiding not published answers.
Instance Method Details
#author ⇒ Object
12 13 14 15 16 17 18 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 12 def @author ||= if official? Decidim::Proposals::OfficialAuthorPresenter.new else .includes(:author).first..presenter end end |
#body(links: false, strip_tags: false, all_locales: false) ⇒ Object
45 46 47 48 49 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 45 def body(links: false, strip_tags: false, all_locales: false) return unless proposal content_handle_locale(proposal.body, all_locales, links, ) end |
#display_mention ⇒ Object
28 29 30 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 28 def display_mention link_to title, proposal_path end |
#editor_body(all_locales: false) ⇒ Object
51 52 53 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 51 def editor_body(all_locales: false) editor_locales(proposal.body, all_locales) end |
#id_and_title(html_escape: false) ⇒ Object
41 42 43 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 41 def id_and_title(html_escape: false) "##{proposal.id} - #{title(html_escape:)}" end |
#proposal ⇒ Object
20 21 22 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 20 def proposal __getobj__ end |
#proposal_path ⇒ Object
24 25 26 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 24 def proposal_path Decidim::ResourceLocatorPresenter.new(proposal).path end |
#resource_manifest ⇒ Object
81 82 83 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 81 def resource_manifest proposal.class.resource_manifest end |
#title(html_escape: false, all_locales: false) ⇒ Object
Render the proposal title
Returns a String.
35 36 37 38 39 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 35 def title(html_escape: false, all_locales: false) return unless proposal super(proposal.title, html_escape, all_locales) end |
#versions ⇒ Object
Returns the proposal versions, hiding not published answers
Returns an Array.
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'app/presenters/decidim/proposals/proposal_presenter.rb', line 58 def versions version_state_published = false pending_state_change = nil proposal.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["decidim_proposals_proposal_state_id"] = parsed_state_change(*pending_state_change) if pending_state_change pending_state_change = nil elsif version.changeset["decidim_proposals_proposal_state_id"] pending_state_change = version.changeset.delete("decidim_proposals_proposal_state_id") end next if version.event == "update" && Decidim::Proposals::DiffRenderer.new(version).diff.empty? version end.compact end |