Sha256: 9c99ba89fef27e705531991d11b405c186e678538d947050df3200a578d77cc7

Contents?: true

Size: 995 Bytes

Versions: 1

Compression:

Stored size: 995 Bytes

Contents

module FlushingFlash
  module ActionViewMethods
    def self.included(base)
      base.extend ClassMethods
      base.send :include, InstanceMethods
    end
    
    module ClassMethods
    end
    
    module InstanceMethods
      def has_flash?(target=:default)
        pull_flash(target).any?
      end
      
      def flush_flash(target=:default, options={})
        msgs = pull_flash(target)
        using_template = options[:using]
        
        if msgs.any?
          if using_template
            render partial: using_template, locals: { messages: msgs }
          else
            msgs.collect do |msg|
              content_tag :div, class: "alert-message #{msg[:message_type]} fade in" do
                concat link_to("x", "#", class: "close")
                concat content_tag(:p, msg[:content].html_safe)
              end
            end.join.html_safe
          end
        end
      end
    end
  end
end

ActionView::Base.send :include, FlushingFlash::ActionViewMethods

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
flushing-flash-0.2.3 lib/flushing-flash/action_view_methods.rb