Class: Decidim::CollaborativeTexts::SuggestionPresenter

Inherits:
ResourcePresenter
  • Object
show all
Includes:
ApplicationHelper
Defined in:
app/presenters/decidim/collaborative_texts/suggestion_presenter.rb

Overview

Decorator for collaborative texts suggestions.

Instance Method Summary collapse

Instance Method Details

#originalObject



23
24
25
# File 'app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 23

def original
  @original ||= ActionView::Base.full_sanitizer.sanitize(changeset["original"]&.join(" ")&.strip).to_s
end

#safe_jsonObject



45
46
47
48
49
50
51
52
53
54
# File 'app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 45

def safe_json
  {
    id:,
    changeset:,
    summary:,
    status:,
    type:,
    createdAt: created_at
  }
end

#suggestionObject



27
28
29
# File 'app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 27

def suggestion
  __getobj__
end

#summaryObject

A summary to print in the UI



13
14
15
16
# File 'app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 13

def summary
  txt = type == :remove ? original : text
  @summary ||= I18n.t("decidim.collaborative_texts.suggestion.#{type}_html", text: txt.truncate(150))
end

#textObject

A text representation of the changeset. Without HTML.



19
20
21
# File 'app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 19

def text
  @text ||= ActionView::Base.full_sanitizer.sanitize(changeset["replace"]&.join(" ")&.strip).to_s
end

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

Render the suggestion title

Returns a String.



34
35
36
# File 'app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 34

def title(html_escape: false, all_locales: false)
  super(suggestion.document.title, html_escape, all_locales)
end

#typeObject



38
39
40
41
42
43
# File 'app/presenters/decidim/collaborative_texts/suggestion_presenter.rb', line 38

def type
  return :remove if text.blank?
  return :add if text.include?(original.to_s)

  :replace
end