class Bootstrap4Helper::Alert

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

Public Class Methods

new(template, context_or_options = nil, opts = {}, &block) click to toggle source

Class constructor

@param [Class] template - Template in which your are binding too. @param [NilClass|String|Symbol|Hash] context_or_options @param [Hash] opts @return [Alert]

Calls superclass method
# 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

Public Instance Methods

close_button() click to toggle source

The dissmiss button, if the element has one.

@return [String]

# File lib/bootstrap4_helper/alert.rb, line 27
def close_button
  content_tag(:button, class: 'close', data: { dismiss: 'alert' }, aria: { label: 'Close' }) do
    content_tag(:span, aria: { hidden: true }) { '×'.html_safe }
  end
end
to_s() click to toggle source

Used to render out the Alert component.

@return [String]

# File lib/bootstrap4_helper/alert.rb, line 37
def to_s
  content_tag :div, id: @id, class: container_class do
    concat(@dismissible ? close_button : '')
    @content.call(self)
  end
end

Private Instance Methods

container_class() click to toggle source

Used to get the container classes.

@return [String]

# File lib/bootstrap4_helper/alert.rb, line 50
def container_class
  "alert alert-#{@context} #{@class}"
end