Class: Decidim::Debates::DebatePresenter

Inherits:
ResourcePresenter
  • Object
show all
Includes:
ActionView::Helpers::DateHelper, ResourceHelper, TranslationsHelper
Defined in:
app/presenters/decidim/debates/debate_presenter.rb

Overview

Decorator for debates

Instance Method Summary collapse

Instance Method Details

#authorObject



17
18
19
20
21
22
23
24
25
# File 'app/presenters/decidim/debates/debate_presenter.rb', line 17

def author
  @author ||= if official?
                Decidim::Debates::OfficialAuthorPresenter.new
              elsif user_group
                Decidim::UserGroupPresenter.new(user_group)
              else
                Decidim::UserPresenter.new(super)
              end
end

#debateObject



13
14
15
# File 'app/presenters/decidim/debates/debate_presenter.rb', line 13

def debate
  __getobj__
end

#description(strip_tags: false, links: false, all_locales: false) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
# File 'app/presenters/decidim/debates/debate_presenter.rb', line 33

def description(strip_tags: false, links: false, all_locales: false)
  return unless debate

  handle_locales(debate.description, all_locales) do |content|
    content = strip_tags(content) if strip_tags
    renderer = Decidim::ContentRenderers::HashtagRenderer.new(content)
    content = renderer.render(links: links).html_safe
    content = Decidim::ContentRenderers::LinkRenderer.new(content).render if links
    content
  end
end

#groups_countObject



61
62
63
64
65
# File 'app/presenters/decidim/debates/debate_presenter.rb', line 61

def groups_count
  comments_authors.count do |author|
    author.is_a?(Decidim::UserGroup)
  end
end

#last_comment_atObject



45
46
47
48
49
# File 'app/presenters/decidim/debates/debate_presenter.rb', line 45

def last_comment_at
  return unless debate.last_comment_at

  time_ago_in_words(debate.last_comment_at)
end

#last_comment_byObject



51
52
53
# File 'app/presenters/decidim/debates/debate_presenter.rb', line 51

def last_comment_by
  debate.last_comment_by&.presenter
end

#participants_countObject



55
56
57
58
59
# File 'app/presenters/decidim/debates/debate_presenter.rb', line 55

def participants_count
  comments_authors.count do |author|
    author.is_a?(Decidim::User)
  end
end

#title(links: false, all_locales: false, html_escape: false) ⇒ Object



27
28
29
30
31
# File 'app/presenters/decidim/debates/debate_presenter.rb', line 27

def title(links: false, all_locales: false, html_escape: false)
  return unless debate

  super debate.title, links, html_escape, all_locales
end