# frozen_string_literal: true module Decidim module Proposals # # Decorator for proposals # class ProposalPresenter < SimpleDelegator include Rails.application.routes.mounted_helpers include ActionView::Helpers::UrlHelper include ActionView::Helpers::SanitizeHelper include Decidim::SanitizeHelper def author @author ||= if official? Decidim::Proposals::OfficialAuthorPresenter.new else coauthorship = coauthorships.first if coauthorship.user_group Decidim::UserGroupPresenter.new(coauthorship.user_group) elsif coauthorship.author.is_a?(Decidim::User) Decidim::UserPresenter.new(coauthorship.author) elsif coauthorship.author.is_a?(Decidim::Meeting) Decidim::MeetingPresenter.new(coauthorship.author) end end end def proposal __getobj__ end def proposal_path Decidim::ResourceLocatorPresenter.new(proposal).path end def display_mention link_to title, proposal_path end # Render the proposal title # # links - should render hashtags as links? # extras - should include extra hashtags? # # Returns a String. def title(links: false, extras: true, html_escape: false) text = proposal.title text = decidim_html_escape(text) if html_escape renderer = Decidim::ContentRenderers::HashtagRenderer.new(text) renderer.render(links: links, extras: extras).html_safe end def body(links: false, extras: true, strip_tags: false) text = proposal.body text = strip_tags(text) if strip_tags renderer = Decidim::ContentRenderers::HashtagRenderer.new(text) text = renderer.render(links: links, extras: extras).html_safe text = Decidim::ContentRenderers::LinkRenderer.new(text).render if links text end end end end