Module: RailsBootstrapHelpers::Helpers::AlertHelper

Defined in:
lib/rails-bootstrap-helpers/helpers/alert_helper.rb

Instance Method Summary collapse

Instance Method Details

#bs_alert(text, options = {}) ⇒ Object

Renders a Bootstrap alert with the given text.

Options



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/rails-bootstrap-helpers/helpers/alert_helper.rb', line 13

def bs_alert (text, options = {})
  cls = "alert"

  if type = options[:type]
    type = type.to_s

    if type == "notice"
      type = "success"
    end

    unless type == "warning" || type == "default"
      cls << " alert-#{type}"
    end
  end

  if type = options[:block]
    cls << " alert-block"
  end

  if dismiss_button = options[:dismiss_button]
     :div, class: cls do
      button =  :button, "×",
        type: "button",
        class: "close",
        :"data-dismiss" => "alert"

      button + text
    end
  else
     :div, text, class: cls
  end
end