Class: Bootstrap5Helper::Alert
- Defined in:
- lib/bootstrap5_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, #parse_context_or_options, #parse_tag_or_options, #parse_text_or_options, #uuid
Constructor Details
#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Alert
Class constructor
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/bootstrap5_helper/alert.rb', line 16 def initialize(template, = nil, opts = {}, &block) super(template) @context, args = (, opts) @id = args.fetch(:id, uuid) @class = args.fetch(:class, '') @data = args.fetch(:data, {}) @dismissible = args.fetch(:dismissible, false) @content = block || proc { '' } end |
Instance Method Details
#close_button ⇒ String
The dissmiss button, if the element has one.
31 32 33 34 35 36 37 38 39 |
# File 'lib/bootstrap5_helper/alert.rb', line 31 def content_tag( :button, '', class: 'btn-close', data: { 'bs-dismiss' => 'alert' }, aria: { label: 'Close' } ) end |
#to_s ⇒ String
Used to render out the Alert component.
45 46 47 48 49 50 |
# File 'lib/bootstrap5_helper/alert.rb', line 45 def to_s content_tag(:div, id: @id, class: container_class, data: @data) do concat(@dismissible ? : '') @content.call(self) end end |