Class: CardComponent
- Defined in:
- app/components/card_component.rb
Overview
Card — content cards with multiple regions.
Usage:
Card(fluid: true) { |c|
c.image { Image(src: "photo.jpg") }
c.header { text "Title" }
c. { text "Subtitle" }
c.description { text "Body text" }
c.extra { text "Extra content" }
}
Constant Summary
Constants inherited from Component
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_s ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'app/components/card_component.rb', line 28 def to_s classes = class_names( "ui", color, { "fluid" => fluid, "centered" => centered, "raised" => raised, "link" => link || href }, "card" ) image_el = @slots[:image] ? tag.div(class: "image") { @slots[:image] } : nil content_parts = [ @slots[:header] ? tag.div(class: "header") { @slots[:header] } : nil, @slots[:meta] ? tag.div(class: "meta") { @slots[:meta] } : nil, @slots[:description] ? tag.div(class: "description") { @slots[:description] } : nil ].compact content_el = content_parts.any? ? tag.div(class: "content") { safe_join(content_parts) } : nil extra_el = @slots[:extra] ? tag.div(class: "extra content") { @slots[:extra] } : nil # Only include @content when no slots are used (block-only mode) loose_content = @slots.values.any? ? nil : @content.presence inner = safe_join([ image_el, content_el, loose_content, extra_el ]) if href tag.a(**(class: classes, href: href)) { inner } else tag.div(**(class: classes)) { inner } end end |