Class: Decidim::Debates::DebatePresenter

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

Overview

Decorator for debates

Instance Method Summary collapse

Methods included from ResourceHelper

#linked_classes_filter_values_for, #linked_classes_for, #linked_resources_for, #resource_locator, #resource_title

Methods included from TranslationsHelper

empty_translatable, ensure_translatable, multi_translation, translated_in_current_locale?

Methods included from TranslatableAttributes

#default_locale?

Methods inherited from ResourcePresenter

#handle_locales

Methods included from SanitizeHelper

#decidim_html_escape, #decidim_sanitize, #decidim_sanitize_editor, #decidim_sanitize_newsletter, #decidim_url_escape, included

Instance Method Details

#authorObject


17
18
19
20
21
22
23
24
25
# File 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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 'decidim-debates/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