Skip to content

ancorcruz/easy_navigation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Easy Navigation

Rails gem/plugin for generating a tabbed navigation for Rails.

Requirements

This gem/plugin is intented to be used with Rails 2.2 as it uses i18n

Install

Add the following line to your /config/environment.rb file:

config.gem "innetra-easy_navigation", 
  :lib => "easy_navigation", 
  :source => "http://gems.github.com"

And from the command line run:

rake gems:install

Install as a Plugin

If your rather prefer to install it as a plugin, from your application directory simply run:

script/plugin install git://github.com/innetra/easy_navigation.git

And you’re done!

Usage

Once installed simply create config/initializers/easy_navigation.rb file like this:

EasyNavigation::Builder.config do |map|
  map.navigation :default do |navigation|
    navigation.tab :home, :url => { :controller => "/dashboard", :action => "index"} do |tab|
      tab.menu :index, :url => { :controller => "/dashboard", :action => "index" } do |menu|
        menu.connect :controller => "dashboard"
      end
    end
    navigation.tab :contacts, :url => { :controller => "/contacts", :action => "index" } do |tab|
      tab.menu :index, :url => { :controller => "/contacts", :action => "index" } do |menu|
        menu.connect :controller => "/contacts"
        menu.connect :controller => "/contacts/people", :except => "new"
        menu.connect :controller => "/contacts/companies", :except => "new"
      end
      tab.menu :new_person, :url => { :controller => "/contacts/people", :action => "new" } do |menu|
        menu.connect :only => "new"
      end
      tab.menu :new_company, :url => { :controller => "/contacts/companies", :action => "new" } do |menu|
        menu.connect :only => "new"
      end
    end
    navigation.tab :admin, :url => { :controller => "/admin/users", :action => "index" } do |tab|
      tab.menu :index, :url => { :controller => "/admin/users", :action => "index" } do |menu|
        menu.connect :except => "new"
      end
      tab.menu :new, :url => { :controller => "/admin/users", :action => "new" } do |menu|
        menu.connect :only => "new"
      end
    end
  end
end

For internationalization, edit your “en-US.easy_navigation.yml” file like this:

en-US:
  navigation:
    default:                  # The name of your navigation menu
      home:                   # The name of your tab
        title: "Home"         # The title of your tab
        menus:                
          index: "Dashboard"  # The title for index action menu
          new: "New Page"     # The title for new action menu

As an example, to render you newly created menu called :default in your “layout/application.erb”:

<%= easy_navigation :default, options = {} %>

Helper Options

:navigation_class => Sets the class name for navigation menus (default: navigation).
:tab_class        => Sets the class name for tabs (default: tab).
:menu_class       => Sets the class name for menus (default: menu).
:separator_class  => Sets the class name for separators (default: sparator).
:separator        => Place a separator after each menu (default: false)

Render Customization

You may wan’t to change the way that the navigation menu gets rendered, if so simply override the following methods (from EasyNavigation::Helper):

Navigation Menus

def render_navigation(id, tabs_html, class_name)
  content_tag("ul", tabs_html, :id => id, :class => class_name)
end

Tabs

def render_tab(id, text, url, menus_html, class_name)
  content_tag("li",
    "#{link_to(t(text), url)} #{content_tag("ul", menus_html)}",
    :id => id, :class => class_name)
end

Menus

def render_menu(id, text, url, class_name)
  content_tag("li", link_to(t(text), url), :id => id, :class => class_name)
end

Separators

def render_separator(class_name)
  content_tag("li", "|", :class => class_name)
end

Pretty easy… right?

License

Copyright © 2008 Innetra Consultancy Services, S.C.

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.

About

Easy tabbed navigation plugin for rails2.x

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages