Sha256: 1539b99be252f746d634bb0f67631c56d23eeba7580a2a4a2080834c92ce2c0b

Contents?: true

Size: 1.21 KB

Versions: 2

Compression:

Stored size: 1.21 KB

Contents

require 'railsstrap/classes/base'

module Railsstrap
  module Helpers
    def bootstrap_flash(options = {})

      flash_messages = []
      close_button = content_tag(:button, raw('×'), :type => 'button', :class => 'close', 'data-dismiss' => 'alert')

      flash.each do |type, message|
        default_opts = {
          show_close: true,
          type: :info,
          container_tag: :div,
          animation: 'animate fade show'
        }
        opts = default_opts.merge(options)

        # Skip empty messages, e.g. for devise messages set to nothing in a locale file.
        next if message.blank?

        type = type.to_sym
        type = :info if type == :notice
        type = :warning if type == :alert
        type = :danger if type == :error
        next unless Railsstrap::Classes::Base.variant_types.include?(type)

        Array(message).each do |msg|

          text = content_tag(opts[:container_tag],
                             (opts[:show_close] ? close_button : '') +
                               msg.html_safe, :class => "alert #{opts[:animation]} alert-#{type} #{opts[:class]}")
          flash_messages << text if msg
        end
      end
      flash_messages.join("\n").html_safe
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
railsstrap-4.0.0.beta3 lib/railsstrap/helpers/flash_helper.rb
railsstrap-4.0.0.beta2 lib/railsstrap/helpers/flash_helper.rb