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.

Parameters:

  • text (String)

    the text to render in the alert

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :style (String)

    the style of alert to render

  • :block (Boolean) — default: false

    indicates if the alert should render with block style



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
45
46
47
48
49
50
51
52
53
54
# File 'lib/rails-bootstrap-helpers/helpers/alert_helper.rb', line 15

def bs_alert (text, options = {})
  options = options.deep_dup
  cls = "alert"
  type = options.delete(:type)

  if type
    ActiveSupport::Deprecation.warn "Usage of the option `:type` is deprecated. Please use the `:style` option instead"
  end

  if style = options.delete(:style) || type
    style = style.to_s

    if style == "notice"
      style = "success"
    end

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

  if style = options.delete(:block)
    cls << " alert-block"
  end

  append_class!(options, cls)

  if options.delete(:dismiss_button)
     :div, class: cls do
      button =  :button, "×",
        type: "button",
        class: "close",
        :"data-dismiss" => "alert"

      button + text
    end
  else
     :div, text, options
  end
end