Module: AlertBoxHelper
- Includes:
- ActionView::Helpers
- Defined in:
- app/helpers/alert_box_helper.rb
Instance Method Summary collapse
- #alert_box(content_or_options = nil, options = {}, &block) ⇒ Object
- #alert_type(type) ⇒ Object
- #dismiss_button ⇒ Object
- #render_alert_box(options, dismissible, content, &block) ⇒ Object
Instance Method Details
#alert_box(content_or_options = nil, options = {}, &block) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'app/helpers/alert_box_helper.rb', line 4 def alert_box(=nil, ={}, &block) if .is_a?(Hash) = else content = end dismissible = .delete(:dismiss).present? klass = .delete(:class) type = alert_type(.delete(:type)) prepend_class(, 'alert', type, klass) [:role] = 'alert' render_alert_box(, dismissible, content, &block) end |
#alert_type(type) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'app/helpers/alert_box_helper.rb', line 21 def alert_type(type) case type.try(:to_sym) when :info 'alert-info' when :success 'alert-success' when :warning 'alert-warning' when :danger 'alert-danger' else 'alert-info' end end |
#dismiss_button ⇒ Object
36 37 38 39 |
# File 'app/helpers/alert_box_helper.rb', line 36 def "<button type='button' class='close' data-dismiss='alert'" \ "aria-label='Close'><span aria-hidden='true'>×</span></button>" end |
#render_alert_box(options, dismissible, content, &block) ⇒ Object
41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/alert_box_helper.rb', line 41 def render_alert_box(, dismissible, content, &block) content_tag :div, do if dismissible ( + (content.presence || capture(&block))).html_safe else content.presence || capture(&block) end end end |