gem install navlinks --source http://gemcutter.org
<html> <head> </head> <body> <ul id="nav"> <li><%= nav_link_to :home, root_path %></li> <li><%= nav_link_to :foo, foo_path %></li> </ul> <div id="content"> <%= yield %> </div> </body> </html>
Suppose we have following pages:
1. A home page that is rendered by +pages/home.html.erb+ template and that we want to belong to 'home' nav area. 2. A page where we show a Foo resource that is rendered by +foos/show.html.erb+ template and that we want to belong to 'foo' nav area.
Easy! Just assign the nav-areas at the top of the views like this:
<%- self.nav_area = :home -%>
<%- self.nav_area = :foo -%>
Now when someone is viewing the pages/home.html.erb
template, the ‘home’ anchor tag will have a class current
. If someone is viewing a foos/show.html.erb
template, then the ‘foo’ anchor tag will have a class current
. When viewing any other page, however, both of the navigation anchors will not have any classes.
navlinks
supports common localization but also allows some tricks. Suppose the localization file is as follows:
en: navigation: home: Go home home_current: At home
This causes the ‘home’ area description to be usually ‘Go home’. However if the user is looking at a page that belongs to ‘home’ nav area, it will display ‘At home’. Cool, huh?
By default the plugin decorates the ‘current’ area with brackets. It is possible to override this behavior by overriding decorate_current_label
method:
module ApplicationHelper # causes the current navigation label to be described as: # * home * def decorate_current_label( current_label ) "* #{current_label} *" end end
Now instead of [ home ] you will see * home *
Feel free to contact me with any questions/comments!