Module: RenderCommentsTreeHelper::Render

Defined in:
app/helpers/render_comments_tree_helper.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.hObject

Returns the value of attribute h.



13
14
15
# File 'app/helpers/render_comments_tree_helper.rb', line 13

def h
  @h
end

.optionsObject

Returns the value of attribute options.



13
14
15
# File 'app/helpers/render_comments_tree_helper.rb', line 13

def options
  @options
end

Class Method Details

.avatarObject



77
78
79
80
81
82
# File 'app/helpers/render_comments_tree_helper.rb', line 77

def avatar
  "<div class='userpic'>
    <img src='#{ @comment.avatar_url }' alt='userpic' />
    #{ controls }
  </div>"
end

.childrenObject



106
107
108
# File 'app/helpers/render_comments_tree_helper.rb', line 106

def children
  "<ol class='nested_set'>#{ options[:children] }</ol>"
end

.controllerObject

Main Helpers



16
17
18
# File 'app/helpers/render_comments_tree_helper.rb', line 16

def controller
  @options[:controller]
end

.controlsObject



102
103
104
# File 'app/helpers/render_comments_tree_helper.rb', line 102

def controls
  "<div class='controls'>#{ moderator_controls }</div>"
end

.draft_commentObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'app/helpers/render_comments_tree_helper.rb', line 47

def draft_comment
  if visible_draft? || moderator?
    published_comment
  else
    "<li class='draft'>
      <div class='comment draft' id='comment_#{@comment.anchor}'>
        #{ t('the_comments.waiting_for_moderation') }
        #{ h.link_to '#', '#comment_' + @comment.anchor }
      </div>
      #{ children }
    </li>"
  end
end

.moderator?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'app/helpers/render_comments_tree_helper.rb', line 29

def moderator?
  controller.try(:current_user).try(:comments_moderator?, @comment)
end

.moderator_controlsObject



90
91
92
93
94
# File 'app/helpers/render_comments_tree_helper.rb', line 90

def moderator_controls
  if moderator?
    h.link_to(t('the_comments.edit'), h.edit_comment_url(@comment), class: :edit)
  end
end

.published_commentObject



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/helpers/render_comments_tree_helper.rb', line 61

def published_comment
  "<li>
    <div id='comment_#{@comment.anchor}' class='comment #{@comment.state}' data-comment-id='#{@comment.to_param}'>
      <div>
        #{ avatar }
        #{ userbar }
        <div class='cbody'>#{ @comment.content }</div>
        #{ reply }
      </div>
    </div>

    <div class='form_holder'></div>
    #{ children }
  </li>"
end

.render_node(h, options) ⇒ Object

Render Methods



34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/helpers/render_comments_tree_helper.rb', line 34

def render_node(h, options)
  @h, @options = h, options
  @comment     = options[:node]

  @max_reply_depth = options[:max_reply_depth] || TheComments.config.max_reply_depth

  if @comment.draft?
    draft_comment
  else @comment.published?
    published_comment
  end
end

.replyObject



96
97
98
99
100
# File 'app/helpers/render_comments_tree_helper.rb', line 96

def reply
  if @comment.depth < (@max_reply_depth - 1)
    "<p class='reply'><a href='#' class='reply_link'>#{ t('the_comments.reply') }</a>"
  end
end

.t(str) ⇒ Object



20
21
22
# File 'app/helpers/render_comments_tree_helper.rb', line 20

def t str
  controller.t str
end

.userbarObject



84
85
86
87
88
# File 'app/helpers/render_comments_tree_helper.rb', line 84

def userbar
  anchor = h.link_to('#', '#comment_' + @comment.anchor)
  title  = @comment.title.blank? ? t('the_comments.guest_name') : @comment.title
  "<div class='userbar'>#{ title } #{ anchor }</div>"
end

.visible_draft?Boolean

Render Helpers

Returns:

  • (Boolean)


25
26
27
# File 'app/helpers/render_comments_tree_helper.rb', line 25

def visible_draft?
  controller.try(:comments_view_token) == @comment.view_token
end