Class: Bootstrap4Helper::Card

Inherits:
Component show all
Defined in:
lib/bootstrap4_helper/card.rb

Overview

Used to build Bootstrap Card components. Cards are wildly used through Bootstrap 4.

Instance Method Summary collapse

Methods inherited from Component

#capture, #concat, #config, #content_tag, #parse_arguments, #uuid

Constructor Details

#initialize(template, opts = {}, &block) ⇒ Card

Used to initialize a new Card component.

Options Hash (opts):

  • :id (String)
  • :class (String)
  • :data (Hash)


15
16
17
18
19
20
21
22
# File 'lib/bootstrap4_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(args = {}, &block) ⇒ String

Builds the Body component.

Options Hash (args):

  • :id (String)
  • :class (String)
  • :data (Hash)


44
45
46
# File 'lib/bootstrap4_helper/card.rb', line 44

def body(args = {}, &block)
  build_base_component :body, args, &block
end

Builds the Footer component.

Options Hash (args):

  • :id (String)
  • :class (String)
  • :data (Hash)


56
57
58
# File 'lib/bootstrap4_helper/card.rb', line 56

def footer(args = {}, &block)
  build_base_component :footer, args, &block
end

#header(args = {}, &block) ⇒ String

Builds the Header component.

Options Hash (args):

  • :id (String)
  • :class (String)
  • :data (Hash)


32
33
34
# File 'lib/bootstrap4_helper/card.rb', line 32

def header(args = {}, &block)
  build_base_component :header, args, &block
end

#image_overlay(args = {}, &block) ⇒ String

Builds a Img Overlay component.

Options Hash (args):

  • :id (String)
  • :class (String)
  • :data (Hash)


92
93
94
# File 'lib/bootstrap4_helper/card.rb', line 92

def image_overlay(args = {}, &block)
  build_base_component 'img-overlay', args, &block
end

#text(args = {}, &block) ⇒ String

Builds a Text component.

Options Hash (args):

  • :id (String)
  • :class (String)
  • :data (Hash)


80
81
82
# File 'lib/bootstrap4_helper/card.rb', line 80

def text(args = {}, &block)
  build_sub_component config(:card_text, :p), :text, args, &block
end

#title(args = {}, &block) ⇒ String

Builds a Title component.

Options Hash (args):

  • :id (String)
  • :class (String)
  • :data (Hash)


68
69
70
# File 'lib/bootstrap4_helper/card.rb', line 68

def title(args = {}, &block)
  build_sub_component config(:card_title, :h5), :title, args, &block
end

#to_sString

Outputs the Object in its String representation.



100
101
102
103
104
# File 'lib/bootstrap4_helper/card.rb', line 100

def to_s
   :div, id: @id, class: "card #{@class}", data: @data do
    @content.call(self)
  end
end