Class: Bootstrap5Helper::Card
- Defined in:
- lib/bootstrap5_helper/card.rb
Overview
Used to build Bootstrap Card components. Cards are wildly used through Bootstrap 4.
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 |
# File 'lib/bootstrap5_helper/card.rb', line 15 def initialize(template, opts = {}, &block) super(template) @id = opts.fetch(:id, '') @class = opts.fetch(:class, '') @data = opts.fetch(:data, nil) @content = block || proc { '' } end |
Instance Method Details
#body(tag, opts) ⇒ String #body(opts) ⇒ String
Builds the Body component.
68 69 70 71 72 73 74 75 76 |
# File 'lib/bootstrap5_helper/card.rb', line 68 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.
96 97 98 99 100 101 102 103 104 |
# File 'lib/bootstrap5_helper/card.rb', line 96 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.
41 42 43 44 45 46 47 48 49 |
# File 'lib/bootstrap5_helper/card.rb', line 41 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.
197 198 199 200 |
# File 'lib/bootstrap5_helper/card.rb', line 197 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.
209 210 211 212 |
# File 'lib/bootstrap5_helper/card.rb', line 209 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.
222 223 224 |
# File 'lib/bootstrap5_helper/card.rb', line 222 def (args = {}, &block) build_base_component(:div, 'img-overlay', args, &block) end |
#subtitle(tag, opts) ⇒ String #subtitle(opts) ⇒ String
Builds a Title component.
150 151 152 153 154 155 156 157 158 |
# File 'lib/bootstrap5_helper/card.rb', line 150 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.
177 178 179 180 181 182 183 184 185 |
# File 'lib/bootstrap5_helper/card.rb', line 177 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.
123 124 125 126 127 128 129 130 131 |
# File 'lib/bootstrap5_helper/card.rb', line 123 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.
230 231 232 233 234 |
# File 'lib/bootstrap5_helper/card.rb', line 230 def to_s content_tag :div, id: @id, class: "card #{@class}", data: @data do @content.call(self) end end |