Class: Bulmacomp::CardComponent
- Inherits:
-
ViewComponent::Base
- Object
- ViewComponent::Base
- Bulmacomp::CardComponent
- Defined in:
- app/components/bulmacomp/card_component.rb
Overview
Make an html structure for a bulma card
Instance Method Summary collapse
-
#call ⇒ String
Html_safe card.
-
#card_content ⇒ Object
return [String] content section if yield is present.
-
#card_footer ⇒ Object
return [String] footer section if a footer is present.
-
#card_image ⇒ Object
return [String] image section if :image is set.
-
#card_title ⇒ String
Title section if :title is set.
-
#initialize(title: nil, image: nil, footer: nil, **opts) ⇒ CardComponent
constructor
A new instance of CardComponent.
Constructor Details
#initialize(title: nil, image: nil, footer: nil, **opts) ⇒ CardComponent
Returns a new instance of CardComponent.
24 25 26 27 28 29 30 |
# File 'app/components/bulmacomp/card_component.rb', line 24 def initialize(title: nil, image: nil, footer: nil, **opts) super @title = title @image = image @footer = @opts = { class: 'card' }.merge(opts) end |
Instance Method Details
#call ⇒ String
Returns html_safe card.
33 34 35 |
# File 'app/components/bulmacomp/card_component.rb', line 33 def call tag.div safe_join([card_title, card_image, card_content, ]), **@opts end |
#card_content ⇒ Object
return [String] content section if yield is present
62 63 64 |
# File 'app/components/bulmacomp/card_component.rb', line 62 def card_content tag.div(tag.div(content, class: 'content'), class: 'card-content') if content end |
#card_footer ⇒ Object
return [String] footer section if a footer is present
71 72 73 |
# File 'app/components/bulmacomp/card_component.rb', line 71 def tag.div @footer, class: 'card-footer' if @footer end |
#card_image ⇒ Object
return [String] image section if :image is set
51 52 53 |
# File 'app/components/bulmacomp/card_component.rb', line 51 def card_image tag.div(tag.figure(image_tag(@image, alt: @title), class: 'image'), class: 'card-image') if @image end |
#card_title ⇒ String
Returns title section if :title is set.
42 43 44 |
# File 'app/components/bulmacomp/card_component.rb', line 42 def card_title tag.div(tag.div(@title, class: 'card-header-title'), class: 'card-header') if @title end |