Sha256: 5717af9c36b36763c18e417add019c6031c45cbcdf6a9aff0b8fd0c527ba74ca

Contents?: true

Size: 1.52 KB

Versions: 3

Compression:

Stored size: 1.52 KB

Contents

# frozen_string_literal: true

module Decidim
  module Proposals
    #
    # Decorator for proposals
    #
    class ProposalPresenter < SimpleDelegator
      include Rails.application.routes.mounted_helpers
      include ActionView::Helpers::UrlHelper

      def author
        @author ||= if official?
                      Decidim::Proposals::OfficialAuthorPresenter.new
                    else
                      coauthorship = coauthorships.first
                      if coauthorship.user_group
                        Decidim::UserGroupPresenter.new(coauthorship.user_group)
                      else
                        Decidim::UserPresenter.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)
        renderer = Decidim::ContentRenderers::HashtagRenderer.new(proposal.title)
        renderer.render(links: links, extras: extras).html_safe
      end

      def body(links: false, extras: true)
        renderer = Decidim::ContentRenderers::HashtagRenderer.new(proposal.body)
        renderer.render(links: links, extras: extras).html_safe
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-proposals-0.16.1 app/presenters/decidim/proposals/proposal_presenter.rb
decidim-proposals-0.17.0 app/presenters/decidim/proposals/proposal_presenter.rb
decidim-proposals-0.16.0 app/presenters/decidim/proposals/proposal_presenter.rb