Method: Statixite::ApplicationHelper#bootstrap_flash

Defined in:
app/helpers/statixite/application_helper.rb

#bootstrap_flash(options = {}) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/helpers/statixite/application_helper.rb', line 6

def bootstrap_flash(options = {})
  flash_messages = []
  flash.each do |type, message|
    # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
    next if message.blank?

    type = type.to_sym
    type = :success if type == :notice
    type = :danger  if type == :alert
    type = :danger  if type == :error
    next unless ALERT_TYPES.include?(type)

    tag_class = options.extract!(:class)[:class]
    tag_options = {
      class: "alert fade in alert-#{type} #{tag_class}"
    }.merge(options)

    close_button = (:button, raw("×"), class: "close", "data-dismiss" => "alert")

    Array(message).each do |msg|
      text = (:div, close_button + msg.html_safe, tag_options)
      flash_messages << text if msg
    end
  end
  flash_messages.join("\n").html_safe
end