Module: Dorsale::CommentsHelper

Included in:
AllHelpers
Defined in:
app/helpers/dorsale/comments_helper.rb

Instance Method Summary collapse

Instance Method Details

#comments_for(commentable) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
# File 'app/helpers/dorsale/comments_helper.rb', line 2

def comments_for(commentable)
  comments    = policy_scope(::Dorsale::Comment).where(commentable: commentable)
  new_comment = new_comment_for(commentable)

  render(
    :partial => "dorsale/comments/comments",
    :locals  => {
      :comments    => comments,
      :new_comment => new_comment,
    },
  )
end

#new_comment_for(commentable) ⇒ Object



15
16
17
# File 'app/helpers/dorsale/comments_helper.rb', line 15

def new_comment_for(commentable)
  policy_scope(Dorsale::Comment).new(commentable: commentable, author: current_user)
end

#truncate_comment_text(text) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'app/helpers/dorsale/comments_helper.rb', line 23

def truncate_comment_text(text)
  text      = text.to_s
  truncated = false

  if text.to_s.count("\n") > 3
    text      = text.split("\n")[0, 3].join("\n")
    truncated = true
  end

  if text.to_s.length > 300
    text      = truncate(text, length: 200)
    truncated = true
  end

  text2html(text) if truncated
end

#truncate_comments_in_this_page?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'app/helpers/dorsale/comments_helper.rb', line 19

def truncate_comments_in_this_page?
  params[:controller].include?("customer_vault")
end