Sha256: 3ce3b9d5b91ce03ce78e70319d31e55d01ffc84659f77913658adaaaffb414ac

Contents?: true

Size: 919 Bytes

Versions: 2

Compression:

Stored size: 919 Bytes

Contents

# = bootstrap_flash
module BootstrapFlashHelper
  ALERT_TYPES = [:success, :info, :warning, :danger] unless const_defined?(:ALERT_TYPES)

  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)

      Array(message).each do |msg|
        text = content_tag(:div,
                           content_tag(:button, raw("×"), :class => "close", "data-dismiss" => "alert") +
                           msg, :class => "alert fade in alert-#{type} #{options[:class]}")
        flash_messages << text if msg
      end
    end
    flash_messages.join("\n").html_safe
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
teleporter-0.0.34 lib/generators/initial/templates/bootstrap/bootstrap_flash_helper.rb
teleporter-0.0.33 lib/generators/initial/templates/bootstrap/bootstrap_flash_helper.rb