Sha256: ecd00a1728ee46f6a4cecdb033efabe415161a8d9ee96f85ecf6d227da4601e9

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

require 'action_view/helpers'

module FoundationRailsHelper
  module FlashHelper
    # <div class="alert-box [success alert secondary]">
    #   This is an alert box.
    #   <a href="" class="close">&times;</a>
    # </div>
    DEFAULT_KEY_MATCHING = {
      :alert     => :alert,
      :notice    => :success,
      :info      => :info,
      :secondary => :secondary,
      :success   => :success,
      :error     => :alert,
      :warning   => :warning
    }
    def display_flash_messages(key_matching = {})
      key_matching = DEFAULT_KEY_MATCHING.merge(key_matching)
      key_matching.default = :standard

      capture do
        flash.each do |key, value|
          next if FoundationRailsHelper.configuration.ignored_flash_keys.include? key.to_sym
          alert_class = key_matching[key.to_sym]
          concat alert_box(value, alert_class)
        end
      end
    end

  private

    def alert_box(value, alert_class)
      content_tag :div, :data => { :alert => "" }, :class => "alert-box #{alert_class}" do
        concat value
        concat close_link
      end
    end

    def close_link
      link_to("&times;".html_safe, "#", :class => :close)
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
foundation_rails_helper-1.2.2 lib/foundation_rails_helper/flash_helper.rb
foundation_rails_helper-1.2.1 lib/foundation_rails_helper/flash_helper.rb
foundation_rails_helper-1.1.0 lib/foundation_rails_helper/flash_helper.rb