Skip to content

guydou/easy_navigation

 
 

Repository files navigation

Easy Navigation

Full stack Rails gem/plugin for drop down/tabbed navigation.

Requirements

  • Rails 2.3.2

  • jQuery 1.5 (using jRails)

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

After installation run the generator to place default stylesheet and javscript code (jQuery):

script/generate easy_navigation

To create your menus 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

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

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

Internationalization (i18n)

If you want to use internationalization, set the option :i18n => true like this:

EasyNavigation::Builder.config do |map|
  map.navigation :default, :i18n => true do |navigation|
  ...
  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

Helper Options

:i18n             => Set to "true" to use i18n internationalization.
: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_empty_tab(id, text, url, class_name)
  content_tag("li", link_to(text, url, :class => 'tab_link'),
    :id => id, :class => class_name)
end

def render_tab(id, text, url, menus_html, class_name)
  content_tag(:li, "#{link_to(text, url, :class => 'tab_link')} #{content_tag(:ul, menus_html, :id => "#{id}_menus", :style => "display:none;")}",
    :id => id, :class => class_name)
end

Menus

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

Separators

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

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 rails

Resources

Stars

Watchers

Forks

Packages

No packages published