Sha256: 4cf6ead9ea3f106e0b5c62680e2f81ff6839f63b2dc76be8589bcbd1029ec53e

Contents?: true

Size: 1.34 KB

Versions: 7

Compression:

Stored size: 1.34 KB

Contents

# frozen_string_literal: true

module Decidim
  module Plans
    #
    # Decorator for plans
    #
    class PlanPresenter < SimpleDelegator
      include Rails.application.routes.mounted_helpers
      include ActionView::Helpers::UrlHelper
      include TranslatableAttributes
      include Plans::RichPresenter

      def author
        coauthorship = coauthorships.first
        @author ||= if coauthorship.user_group
                      Decidim::UserGroupPresenter.new(coauthorship.user_group)
                    else
                      Decidim::UserPresenter.new(coauthorship.author)
                    end
      end

      def plan
        __getobj__
      end

      def plan_path
        Decidim::ResourceLocatorPresenter.new(plan).path
      end

      def title
        plain_content(translated_attribute(plan.title))
      end

      def body
        fields = plan.sections.map do |section|
          content = plan.contents.find_by(section: section)
          next if content.nil?

          section_title = plain_content(translated_attribute(content.title))
          section_body = plain_content(translated_attribute(content.body))
          "<dt>#{section_title}</dt> <dd>#{section_body}</dd>"
        end

        "<dl>#{fields.join("\n")}</dl>".html_safe
      end

      def display_mention
        link_to title, plan_path
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
decidim-plans-0.18.2 app/presenters/decidim/plans/plan_presenter.rb
decidim-plans-0.18.1 app/presenters/decidim/plans/plan_presenter.rb
decidim-plans-0.18.0 app/presenters/decidim/plans/plan_presenter.rb
decidim-plans-0.17.0 app/presenters/decidim/plans/plan_presenter.rb
decidim-plans-0.16.9 app/presenters/decidim/plans/plan_presenter.rb
decidim-plans-0.16.8 app/presenters/decidim/plans/plan_presenter.rb
decidim-plans-0.16.7 app/presenters/decidim/plans/plan_presenter.rb