Class: Bootstrap4Helper::Alert
- 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
-
#close_button ⇒ String
The dissmiss button, if the element has one.
-
#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Alert
constructor
Class constructor.
-
#to_s ⇒ String
Used to render out the Alert component.
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
13 14 15 16 17 18 19 20 21 |
# File 'lib/bootstrap4_helper/alert.rb', line 13 def initialize(template, = nil, opts = {}, &block) super(template) @context, args = parse_arguments(, opts) @id = args.fetch(:id, nil) @class = args.fetch(:class, '') @dismissible = args.fetch(:dismissible, false) @content = block || proc { '' } end |
Instance Method Details
#close_button ⇒ String
The dissmiss button, if the element has one.
27 28 29 30 31 |
# File 'lib/bootstrap4_helper/alert.rb', line 27 def content_tag(:button, class: 'close', data: { dismiss: 'alert' }, aria: { label: 'Close' }) do content_tag(:span, aria: { hidden: true }) { '×'.html_safe } end end |
#to_s ⇒ String
Used to render out the Alert component.
37 38 39 40 41 42 |
# File 'lib/bootstrap4_helper/alert.rb', line 37 def to_s content_tag :div, id: @id, class: container_class do concat(@dismissible ? : '') @content.call(self) end end |