Class: Decidim::Plans::PlanPresenter

Inherits:
SimpleDelegator
  • Object
show all
Includes:
ActionView::Helpers::UrlHelper, RichPresenter, TranslatableAttributes
Defined in:
app/presenters/decidim/plans/plan_presenter.rb

Overview

Decorator for plans

Instance Method Summary collapse

Methods included from RichPresenter

#plain_content, #rich_content

Instance Method Details

#authorObject



14
15
16
17
18
19
20
21
# File 'app/presenters/decidim/plans/plan_presenter.rb', line 14

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

#bodyObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'app/presenters/decidim/plans/plan_presenter.rb', line 35

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

#display_mentionObject



48
49
50
# File 'app/presenters/decidim/plans/plan_presenter.rb', line 48

def display_mention
  link_to title, plan_path
end

#planObject



23
24
25
# File 'app/presenters/decidim/plans/plan_presenter.rb', line 23

def plan
  __getobj__
end

#plan_pathObject



27
28
29
# File 'app/presenters/decidim/plans/plan_presenter.rb', line 27

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

#titleObject



31
32
33
# File 'app/presenters/decidim/plans/plan_presenter.rb', line 31

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