Class: Bootstrap5Helper::Callout

Inherits:
Component show all
Defined in:
lib/bootstrap5_helper/callout.rb

Overview

Builds a Toast component.

Instance Method Summary collapse

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, context_or_options = nil, opts = {}, &block) ⇒ Callout

Parameters:

  • template (ActionView)
    • Template in which your are binding too.
  • context_or_options (NilClass|String|Symbol|Hash) (defaults to: nil)
    • Bootstrap class context, or options hash.
  • opts (Hash) (defaults to: {})

Options Hash (opts):

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


14
15
16
17
18
19
20
21
22
23
# File 'lib/bootstrap5_helper/callout.rb', line 14

def initialize(template, context_or_options = nil, opts = {}, &block)
  super(template)
  @context, args = parse_context_or_options(context_or_options, opts)

  @attrs   = args
  @id      = @attrs.delete(:id)    { nil }
  @class   = @attrs.delete(:class) { '' }
  @data    = @attrs.delete(:data)  { {} }
  @content = block || proc { '' }
end

Instance Method Details

#header(text_or_options = nil, opts = {}, &block) ⇒ String

Creates the header component for the Callout.

Parameters:

  • text_or_options (String|Hash) (defaults to: nil)
  • opts (Hash) (defaults to: {})

Options Hash (opts):

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

Returns:

  • (String)


34
35
36
37
# File 'lib/bootstrap5_helper/callout.rb', line 34

def header(text_or_options = nil, opts = {}, &block)
  text = text_or_options.is_a?(String) ? text_or_options : nil
  (config({ callouts: :header }, :h4), text, opts, &block)
end

#to_sString

Returns a string representation of the component.

Returns:

  • (String)


43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/bootstrap5_helper/callout.rb', line 43

def to_s
  (
    :div,
    {
      id:    @id,
      class: container_class,
      data:  @data
    }.merge(@attrs)
  ) do
    @content.call(self)
  end
end