# coding: UTF-8 # DOC: # We use Helper Methods for tree building, # because it's faster than View Templates and Partials # SECURITY note # Prepare your data on server side for rendering # or use h.html_escape(node.content) # for escape potentially dangerous content module RenderCommentsTreeHelper module Render class << self attr_accessor :h, :options # Main Helpers def controller @options[:controller] end def t str controller.t str end # Render Helpers def visible_draft? controller.try(:comments_view_token) == @comment.view_token end def moderator? controller.try(:current_user).try(:comments_moderator?, @comment) end # Render Methods 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 def draft_comment if visible_draft? || moderator? published_comment else "
  • #{ t('the_comments.waiting_for_moderation') } #{ h.link_to '#', '#comment_' + @comment.anchor }
    #{ children }
  • " end end def published_comment "
  • #{ avatar } #{ userbar }
    #{ @comment.content }
    #{ reply }
    #{ children }
  • " end def avatar "
    userpic #{ controls }
    " end def userbar anchor = h.link_to('#', '#comment_' + @comment.anchor) title = @comment.title.blank? ? t('the_comments.guest_name') : @comment.title "
    #{ title } #{ anchor }
    " end def moderator_controls if moderator? h.link_to(t('the_comments.edit'), h.edit_comment_url(@comment), class: :edit) end end def reply if @comment.depth < (@max_reply_depth - 1) "

    #{ t('the_comments.reply') }" end end def controls "

    #{ moderator_controls }
    " end def children "
      #{ options[:children] }
    " end end end end