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
# 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)

  @id      = args.fetch(:id,    nil)
  @class   = args.fetch(:class, '')
  @data    = args.fetch(: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)


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

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)


42
43
44
45
46
# File 'lib/bootstrap5_helper/callout.rb', line 42

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