Class: FeedItemComponent

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

Overview

FeedItem — a single item/event in a Feed.

Usage:

FeedItem { |e|
  e.label { Image(src: "/images/avatar/small/elliot.jpg") }
  e.summary {
    LinkTo(class: "user") { "Elliot Fu" }
    text " added you as a friend"
  }
  e.date { "1 Hour Ago" }
  e.meta {
    LinkTo(class: "like") {
      Icon(name: "like")
      text " 4 Likes"
    }
  }
  e.extra_text { "Some additional text" }
  e.extra_images {
    LinkTo { Image(src: "/images/wireframe/image.png") }
  }
}

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



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'app/components/feed_item_component.rb', line 37

def to_s
  classes = class_names(
    { "disabled" => disabled },
    color,
    "event"
  )

  label_el = if @slots[:label]
    tag.div(class: "label") { @slots[:label] }
  end

  content_parts = []

  # Date can appear at the top of content (outside summary)
  if @slots[:date]
    content_parts << tag.div(class: "date") { @slots[:date] }
  end

  # Summary with optional inline date
  if @slots[:summary]
    summary_inner = @slots[:summary]
    if @slots[:date_inline]
      summary_inner = safe_join([ summary_inner, tag.div(class: "date") { @slots[:date_inline] } ])
    end
    content_parts << tag.div(class: "summary") { summary_inner }
  end

  if @slots[:extra_text]
    content_parts << tag.div(class: "extra text") { @slots[:extra_text] }
  end

  if @slots[:extra_images]
    content_parts << tag.div(class: "extra images") { @slots[:extra_images] }
  end

  if @slots[:meta]
    content_parts << tag.div(class: "meta") { @slots[:meta] }
  end

  loose_content = @slots.values.any? ? nil : @content.presence
  content_el = if content_parts.any? || loose_content.present?
    tag.div(class: "content") { safe_join([ *content_parts, loose_content ]) }
  end

  tag.div(**merge_html_options(class: classes)) {
    safe_join([ label_el, content_el ])
  }
end