Class: Bootstrap5Helper::Card
- Defined in:
- lib/bootstrap5_helper/card.rb
Overview
Used to build Bootstrap Card components..
Instance Method Summary collapse
-
#body(*tag_or_options, &block) ⇒ String
Builds the Body component.
-
#footer(*tag_or_options, &block) ⇒ String
Builds the Footer component.
-
#header(*tag_or_options, &block) ⇒ String
Builds the Header component.
-
#image(src, opts = {}) ⇒ String
Simple image element for cards.
-
#image_cap(src, type = :top, opts = {}) ⇒ String
Builds an Image Cap component.
-
#image_overlay(args = {}, &block) ⇒ String
Builds a Img Overlay component.
-
#initialize(template, opts = {}, &block) ⇒ Card
constructor
Used to initialize a new Card component.
-
#subtitle(*tag_or_options, &block) ⇒ String
Builds a Title component.
-
#text(*tag_or_options, &block) ⇒ String
Builds a Text component.
-
#title(*tag_or_options, &block) ⇒ String
Builds a Title component.
-
#to_s ⇒ String
Outputs the Object in its String representation.
Methods inherited from Component
#capture, #concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #parse_text_or_options, #uuid
Constructor Details
#initialize(template, opts = {}, &block) ⇒ Card
Used to initialize a new Card component.
15 16 17 18 19 20 21 22 23 |
# File 'lib/bootstrap5_helper/card.rb', line 15 def initialize(template, opts = {}, &block) super(template) @attrs = opts @id = @attrs.delete(:id) { '' } @class = @attrs.delete(:class) { '' } @data = @attrs.delete(:data) { {} } @content = block || proc { '' } end |
Instance Method Details
#body(tag, opts) ⇒ String #body(opts) ⇒ String
Builds the Body component.
69 70 71 72 73 74 75 76 77 |
# File 'lib/bootstrap5_helper/card.rb', line 69 def body(*, &block) tag, args = (*, {}) build_base_component( tag || config({ cards: :body }, :div), :body, args, &block ) end |
#footer(tag, opts) ⇒ String #footer(opts) ⇒ String
Builds the Footer component.
97 98 99 100 101 102 103 104 105 |
# File 'lib/bootstrap5_helper/card.rb', line 97 def (*, &block) tag, args = (*, {}) build_base_component( tag || config({ cards: :footer }, :div), :footer, args, &block ) end |
#header(tag, opts) ⇒ String #header(opts) ⇒ String
Builds the Header component.
42 43 44 45 46 47 48 49 50 |
# File 'lib/bootstrap5_helper/card.rb', line 42 def header(*, &block) tag, args = (*, {}) build_base_component( tag || config({ cards: :header }, :h5), :header, args, &block ) end |
#image(src, opts = {}) ⇒ String
Simple image element for cards.
198 199 200 201 |
# File 'lib/bootstrap5_helper/card.rb', line 198 def image(src, opts = {}) (opts[:class] ||= '') << ' card-img' @template.image_tag(src, opts) end |
#image_cap(src, type = :top, opts = {}) ⇒ String
Builds an Image Cap component.
210 211 212 213 |
# File 'lib/bootstrap5_helper/card.rb', line 210 def image_cap(src, type = :top, opts = {}) (opts[:class] ||= '') << " card-img-#{type}" @template.image_tag(src, opts) end |
#image_overlay(args = {}, &block) ⇒ String
Builds a Img Overlay component.
223 224 225 |
# File 'lib/bootstrap5_helper/card.rb', line 223 def (args = {}, &block) build_base_component(:div, 'img-overlay', args, &block) end |
#subtitle(tag, opts) ⇒ String #subtitle(opts) ⇒ String
Builds a Title component.
151 152 153 154 155 156 157 158 159 |
# File 'lib/bootstrap5_helper/card.rb', line 151 def subtitle(*, &block) tag, args = (*, {}) build_sub_component( tag || config({ cards: :subtitle }, :h6), :subtitle, args, &block ) end |
#header(tag, opts) ⇒ String #header(opts) ⇒ String
Builds a Text component.
178 179 180 181 182 183 184 185 186 |
# File 'lib/bootstrap5_helper/card.rb', line 178 def text(*, &block) tag, args = (*, {}) build_sub_component( tag || config(:card_text, :p), :text, args, &block ) end |
#title(tag, opts) ⇒ String #title(opts) ⇒ String
Builds a Title component.
124 125 126 127 128 129 130 131 132 |
# File 'lib/bootstrap5_helper/card.rb', line 124 def title(*, &block) tag, args = (*, {}) build_sub_component( tag || config({ cards: :title }, :h5), :title, args, &block ) end |
#to_s ⇒ String
Outputs the Object in its String representation.
231 232 233 234 235 236 237 238 239 240 241 242 |
# File 'lib/bootstrap5_helper/card.rb', line 231 def to_s content_tag( :div, { id: @id, class: "card #{@class}", data: @data }.merge(@attrs) ) do @content.call(self) end end |