Skip to content

Commit

Permalink
changed the README to match the new configuration DSL.
Browse files Browse the repository at this point in the history
  • Loading branch information
mdeering committed Mar 19, 2011
1 parent 4aefc3f commit 3705a8d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 21 deletions.
51 changes: 37 additions & 14 deletions README.textile
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
h1. Flash Messages Helper

Ruby on Rails view helper for displaying html flash messages in your Rails applications.
A configurable Ruby on Rails view helper for displaying html flash messages in your Rails applications.

h2. Recent Changes

* 0.2.0
* Added a proper configuration DSL
* html_safe called on the output if available

h2. Install as a Ruby Gem

<pre>sudo gem install flash_messages_helper</pre>
<pre>gem install flash_messages_helper</pre>

h3. Rails 2

p. Then add the following line to your _environment.rb_

<pre>config.gem 'flash_messages_helper'</pre>

h3. Rails 3

<pre># Gemfile
gem 'flash_messages_helper'</pre>


h2. Installation as a Ruby on Rails Plugin

<pre>./script/plugin install git://github.com/mdeering/flash_messages_helper.git</pre>

h2. Usage

Once you have installed it as a plugin/gem in your rails app usage is simple. Just call the flash_messages function within you Rails layout or view file
Once you have installed it as a plugin/gem in your rails app usage is simple. Just call the flash_messages function within you Rails view file

<pre>flash_messages</pre>

h2. Configuration Points
h2. Configuration

h3. Changing the default id of the flash elements

Expand All @@ -31,10 +45,13 @@ By default the id of the flash message element will come through as flash-_error
* flash-warning
* _ect..._

To change this you can pass set a lambda that will get called with the key of the message type.
To change this use the _dom_id_ configuration attribute.

<pre># config/initializers/flash_messages_helper_settings.rb
ActionView::Base.flash_message_id_proc = lambda {|key| "#{key}-message"}</pre>
<pre><code># config/initializers/flash_messages_helper.rb
FlashMessagesHelper.configure do |config|
config.dom_id = lambda { |key| "#{key}-message" }
end
</code></pre>

A _error_ message will now displayed with the dom element id of _error-message_ rather then _flash-error_ throughout the application

Expand All @@ -49,21 +66,27 @@ By default the class of the flash message element will come through as _error-ty
* warning
* _ect..._

To change this you can pass set a lambda that will get called with the key of the message type.
To change this use the _css_class_ configuration attribute.

<pre># config/initializers/flash_messages_helper_settings.rb
ActionView::Base.flash_message_class_proc = lambda {|key| "#{key} hideable"}</pre>
<pre><code># config/initializers/flash_messages_helper.rb
FlashMessagesHelper.configure do |config|
config.css_class = lambda { |key| "#{key} dismissible" }
end
</code></pre>

A _error_ message will now displayed with the dom element class of _error hideable rather then _error_ throughout the application
A _error_ message will now displayed with the dom element class of _error dismissible rather then _error_ throughout the application

<pre><div class="error hideable" id="flash-error">There was an error!</div></pre>
<pre><div class="error dismissible" id="flash-error">There was an error!</div></pre>

h3. Changing the default html tag type of the flash elements

As a default the html tag used to wrap the flash messages is a div element. This can be easily globally changed with the following setting.

<pre># config/initializers/flash_messages_helper_settings.rb
ActionView::Base.flash_message_tag = :p</pre>
<pre><code># config/initializers/flash_messages_helper.rb
FlashMessagesHelper.configure do |config|
config.wrapper = :p
end
</code></pre>

With the above setting flash messages will be wrapped inside of a paragraph tag rather then a div.

Expand Down
13 changes: 6 additions & 7 deletions spec/flash_messages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
end

it 'will return a div with the error message' do
@controller.stub!(:flash).and_return({:error => 'There was an error'})
@controller.stub!(:flash).and_return({ :error => 'There was an error' })
@view.flash_messages.should == "<div class=\"error\" id=\"flash-error\">There was an error</div>"
end

{
:flash_message_class_proc => lambda { |key| "#{key}-message hiddable"},
:flash_message_id_proc => lambda { |key| "flash-#{key}-message"},
:flash_message_class_proc => lambda { |key| "#{key}-message hiddable" },
:flash_message_id_proc => lambda { |key| "flash-#{key}-message" },
:flash_message_tag => :p
}.each do |singleton_variable, value|
it "should give deprication warnings for 0.1.0 usage but still set configuration points" do
Expand All @@ -41,16 +41,15 @@

it 'will return a p with the error message and the defaults set differently' do
FlashMessagesHelper.configuration.wrapper = :p
@controller.stub!(:flash).and_return({:error => 'There was an error'})
@controller.stub!(:flash).and_return({ :error => 'There was an error' })
@view.flash_messages.should == "<p class=\"error\" id=\"flash-error\">There was an error</p>"
end

it 'will still honor the html options passed in' do
@controller.stub!(:flash).and_return({:error => 'There was an error'})
@controller.stub!(:flash).and_return({ :error => 'There was an error' })
@view.flash_messages(:class => 'my-class').should == "<div class=\"my-class\" id=\"flash-error\">There was an error</div>"
end

it 'will call html_safe on the return string if available' do
end
it 'will call html_safe on the return string if available'

end

0 comments on commit 3705a8d

Please sign in to comment.