Class: Bootstrap4Helper::Alert

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

Overview

The Alert helper is meant to help you rapidly build Bootstrap Alert components quickly and easily. The dissmiss button is optional.

Instance Method Summary collapse

Methods inherited from Component

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

Constructor Details

#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Alert

Class constructor

Parameters:

  • template (Class)
    • Template in which your are binding too.

  • context_or_options (NilClass|String|Symbol|Hash) (defaults to: nil)
  • opts (Hash) (defaults to: {})


13
14
15
16
17
18
19
20
21
# File 'lib/bootstrap4_helper/alert.rb', line 13

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

  @id          = args.fetch(:id,          nil)
  @class       = args.fetch(:class,       '')
  @dismissible = args.fetch(:dismissible, false)
  @content     = block || proc { '' }
end

Instance Method Details

#close_buttonString

The dissmiss button, if the element has one.

Returns:

  • (String)


27
28
29
30
31
# File 'lib/bootstrap4_helper/alert.rb', line 27

def close_button
  (:button, class: 'close', data: { dismiss: 'alert' }, aria: { label: 'Close' }) do
    (:span, aria: { hidden: true }) { '×'.html_safe }
  end
end

#to_sString

Used to render out the Alert component.

Returns:

  • (String)


37
38
39
40
41
42
# File 'lib/bootstrap4_helper/alert.rb', line 37

def to_s
   :div, id: @id, class: container_class do
    concat(@dismissible ? close_button : '')
    @content.call(self)
  end
end