Class: Bootstrap3Helper::Alert
- Defined in:
- lib/bootstrap3_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
Used to generate Bootstrap alert components quickly.
-
#to_s ⇒ String
Used to render out the Alert component.
Methods inherited from Component
#concat, #config, #content_tag, #parse_arguments, #parse_context_or_options, #parse_tag_or_options, #uuid
Constructor Details
#initialize(template, context_or_options = nil, opts = {}, &block) ⇒ Alert
Used to generate Bootstrap alert components quickly.
15 16 17 18 19 20 21 22 23 |
# File 'lib/bootstrap3_helper/alert.rb', line 15 def initialize(template, = nil, opts = {}, &block) super(template) @context, args = (, 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.
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/bootstrap3_helper/alert.rb', line 29 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
Concat needs to be used to add the content of the button to the output buffer. For some reason, if though the block returns a String, trying to add that string to the dismiss button string, returns with the dismiss button missing. Was forced to caoncat the button to the current output buffer in order to get it to persist after the block call.
Used to render out the Alert component.
50 51 52 53 54 55 |
# File 'lib/bootstrap3_helper/alert.rb', line 50 def to_s content_tag :div, id: @id, class: container_class do concat(@dismissible ? : '') @content.call(self) end end |