stackable_flash
===============
Allows flashes to stack intelligently, while preserving existing behavior of Rails' FlashHash.
Stackable Flash overrides the :[]= method of Rails' FlashHash with the result being that each flash key is an array.
It is designed following the "Principle of least surprise", so in most ways the flash works as it always has.
Only now you can push things onto the array with `:<<`, and generally interact with the flash as an array.
In order to be as compatible as possible with existing implementations of the FlashHash on websites, `:[]=` will still
replace the entire object at that key.
## Installation
Add this line to your application's Gemfile:
gem 'stackable_flash'
And then execute:
$ bundle
Or install it yourself as:
$ gem install stackable_flash
## Config (Optional)
In an environment file, or application.rb
# Here are a few ideas (Don't do them all, pick one):
# You can use a lambda instead of a proc
StackableFlash::Config.configure do
# Leave it as an array
config[:stack_with_proc] = Proc.new {|arr| arr }
# Make a set of statements separated by br tags
config[:stack_with_proc] = Proc.new {|arr| arr.join('
') } # THIS IS DEFAULT IF LEFT UNCONFIGURED
# Make a set of p tags:
config[:stack_with_proc] = Proc.new {|arr| arr.map! {|x| "
#{x}
"}.join } # Make an unordered list of tags: config[:stack_with_proc] = Proc.new {|arr| '#{x}
"}.join } } ) do flash[:notice] = 'original' flash[:notice] << 'message' flash[:notice] # => ['original','message'] # Uses the :stack_with_proc to transform flash[:notice].stack # => 'original
message
' end And StackableFlash.not_stacked do flash[:notice] = 'original' flash[:notice] << ' message' flash[:notice] # => 'original message' # Uses the :stack_with_proc to transform flash[:notice].stack # => NoMethodError !!! end ## Sightings This gem is used by the cacheable_flash gem to provide stacking flashes. You can check it out for a working example. ## Contributing 1. Fork it 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Added some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally. 6. Create new Pull Request == Copyright Licensed under the MIT License. - Copyright (c) 2012 Peter H. Boling (http://peterboling.com). See LICENSE for further details.