jmejia/store_engine

View on GitHub
app/helpers/bootstrap_flash_helper.rb

Summary

Maintainability
A
1 hr
Test Coverage
module BootstrapFlashHelper
  ALERT_TYPES = [:error, :info, :success, :warning]

  def bootstrap_flash
    flash_messages = []
    flash.each do |type, message|

      next if message.blank?

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

      flash_helper(flash_messages, type, message)

    end
    flash_messages.join("\n").html_safe
  end

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