Module: Bootstrap::AlertHelper
- Defined in:
- app/helpers/bootstrap/alert_helper.rb
Overview
Rails helpers for producing Bootstrap alert boxes.
Constant Summary collapse
- InvalidAlertTypeError =
Class.new(StandardError)
- ALERT_ATTRIBUTES =
%w(default success info warning danger)
- COMPILED_ALERT_CLASSES =
ALERT_ATTRIBUTES.map{|a| "alert-#{a}"}
Instance Method Summary collapse
-
#alert(text, alert_type, options = {}) ⇒ String
Returns html for alert.
-
#alert_close(show = true) ⇒ String
Return an alert box close button.
-
#alert_heading(heading) ⇒ String
Return an alert heading.
Instance Method Details
#alert(text, alert_type, options = {}) ⇒ String
Returns html for alert
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/helpers/bootstrap/alert_helper.rb', line 32 def alert(*args, &block) body = alert_body(args, &block) = (args.) = ensure_class(, 'alert') = add_alert_classes(, args) heading = .delete(:heading) show_close = .delete(:close) != false = ensure_class(, 'alert-dismissible') if show_close content_tag(:div, ) do alert_close(show_close) + alert_heading(heading) + body end end |
#alert_close(show = true) ⇒ String
Return an alert box close button
51 52 53 54 |
# File 'app/helpers/bootstrap/alert_helper.rb', line 51 def alert_close(show=true) return '' unless show content_tag(:button, '×'.html_safe, class: 'close', data: {dismiss: 'alert'}, aria: {label: "Close"}) end |
#alert_heading(heading) ⇒ String
Return an alert heading
59 60 61 62 |
# File 'app/helpers/bootstrap/alert_helper.rb', line 59 def alert_heading(heading) return '' unless heading.present? content_tag(:h4, heading) end |