Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Rails plugin to create a set of links that share common attributes
Ruby
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
test
.gitignore
README.rdoc
Rakefile
init.rb
link_block.gemspec

README.rdoc

LinkBlock

LinkBlock lets you create a bunch of links that share options.

Examples

<%- link_block :controller => 'main' do |lb| -%>
  <%= lb.link_to 'Home', :action => 'index' %>
  <%= lb.link_to 'Products', :action => 'products' %>
  <%= lb.link_to 'Locations', :action => 'locations' %>
  <%= lb.link_to 'Contact', :action => 'contact' %>
<%- end -%>

is the same as doing:

<%= link_to 'Home', :controller => 'main', :action => 'index' %>
<%= link_to 'Products', :controller => 'main', :action => 'products' %>
<%= link_to 'Locations', :controller => 'main', :action => 'locations' %>
<%= link_to 'Contact', :controller => 'main', :action => 'contact' %>

It also supports merging html options:

<%- link_block {:controller => 'main'}, {:class => 'side_bar_link'} do |lb| -%>
  <%= lb.link_to 'Home', :action => 'index' %>
<%- end -%>

And appending to string routes (if you INSIST on using string routes) instead of hashes:

<%- link_block '/main/' do |lb| -%>
  <%= lb.link_to 'Index Page', 'index' %>
<%- end -%>

The current link gets a link_block_current appended to the class list. This can be changed through the LinkBlock::Config object:

LinkBlock::Config.current_link_class = "different_name"

or turned off via:

LinkBlock::Config.current_link_enabled = false

Todo

Now relies on PlugTest for testing. github.com/ryana/plug_test

Thanks

Shameless Plug

Recommend me on Working With Rails (workingwithrails.com/recommendation/new/person/14860-ryan-angilly) or give me a shout out on Twitter (twitter.com/angilly) @angilly if you think this is awesome.

MIT License

Copyright © 2008 Ryan Angilly

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Something went wrong with that request. Please try again.