Class: CommentComponent

Inherits:
Component show all
Defined in:
app/components/comment_component.rb

Overview

Comment — threaded comment display.

Usage:

Comment { |c|
  c.avatar { Image(src: "avatar.png") }
  c.author { text "Matt" }
  c. { text "Today at 5:42PM" }
  c.text_slot { text "Great post!" }
  c.actions { text '<a class="reply">Reply</a>'.html_safe }
}

Constant Summary

Constants inherited from Component

Component::HTML_OPTIONS

Instance Method Summary collapse

Methods inherited from Component

default, #initialize, #render_in, slot

Constructor Details

This class inherits a constructor from Component

Instance Method Details

#to_sObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/components/comment_component.rb', line 24

def to_s
  classes = class_names(
    { "collapsed" => collapsed },
    "comment"
  )

  avatar_el = @slots[:avatar] ? tag.a(class: "avatar") { @slots[:avatar] } : nil

  content_parts = [
    @slots[:author] ? tag.a(class: "author") { @slots[:author] } : nil,
    @slots[:metadata] ? tag.div(class: "metadata") { @slots[:metadata] } : nil,
    @slots[:text_slot] ? tag.div(class: "text") { @slots[:text_slot] } : nil,
    @slots[:actions] ? tag.div(class: "actions") { @slots[:actions] } : nil
  ].compact

  content_el = content_parts.any? ? tag.div(class: "content") { safe_join(content_parts) } : nil

  tag.div(class: classes) {
    safe_join([ avatar_el, content_el, @content.presence ])
  }
end