Coder Social home page Coder Social logo

simple_navigation's Introduction

Simple Navigation

Ruby on Rails gem/plugin for drop down/tabbed navigation.

Requirements

  • Rails 2.3.x (may work with older versions, not tested)

Install

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

config.gem "mexpolk-simple_navigation",
    :lib => "simple_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/mexpolk/simple_navigation.git

And you're done!

Usage

To create your menus create config/initializers/simple_navigation.rb file like this:

SimpleNavigation::Builder.config do |map|
    map.navigation :default do |navigation|

        # Root menu without child elements (menus) that points to /dashboard
        navigation.menu :home, :url => { :controller => "home", :action => "index"}

        # Root menu with child menus without anchor link
        navigation.menu :contacts do |contacts|

            # Child menu with many possible urls (or many controllers and actions)
            contacts.menu :list, :url => { :controller => "contacts", :action => "index" } do |contact_list|

                # This menu will marked as current when you're on the following
                # controllers and actions (including the controller and action
                # specified in the :url option):
                contact_list.connect :controller => "contacts" # ...current on any action from this controller
                contact_list.connect :controller => "people", :except => "new"
                contact_list.connect :controller => "companies", :except => "new"

            end

            # Another submenu that points to /person/new
            contacts.menu :new_person, :url => { :controller => "people", :action => "new" }

            # Another submenu that points to /company/new
            contacts.menu :new_company, :url => { :controller => "companies", :action => "new" }

        end

        # Another root menu with nested submenus
        navigation.tab :admin, :url => { :controller => "users", :action => "index" } do |admin|
            admin.menu :users, :url => { :controller => "users", :action => "index" } do |users|
                users.menu :reports, :url => { :controller => "user_reports", :action => "index" } do |reports|
                    reports.menu :activity, :url => { :controller => "user_reports", :action => "activity" }
                    reports.menu :login_atempts, :url => { :controller => "user_reports", :action => "login_atempts" }
                end
                users.menu :new_user, :url => { :controller => "users", :action => "new" }
            end
        end
    end
end

To render you newly created menu called :default, in your default layout (layout/application.html.erb):

<%= simple_navigation :default %>

Internationalization (i18n)

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

SimpleNavigation::Builder.config do |map|
    map.navigation :default, :i18n => true do |navigation|
        ...
    end
end

And add to your config/locales files (e.g. es-MX.yml) the following:

es-MX:
    simple_navigation:
        default:                         # The name of your navigation menu
            home:                          # The name of your root menu
                title: "Inicio"              # The translated title for your root menu
                menus:
                    index: "Panel de Control"  # The title for index action child menu
                    new: "Nueva Página"        # The title for new action child menu

License

Copyright (c) 2008 Iván "Mexpolk" Torres

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.

simple_navigation's People

Contributors

ivantorresedge avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

simple_navigation's Issues

Internationalization (i18n) Translation Problems

Simple Navigation does not prefix i18n labels with simple_navigation. Right now configuration should work like this:

es-MX:
  default:
    menus:
      categories:
        title: "Categorías"
      resources:
        title: "Equipo"

Where it should be:

es-MX:
  simple_navigation:
    default:
      menus:
        categories:
          title: "Categorías"
        resources:
          title: "Equipo"

Formating

Would it be possible to have the code cleaned up that is outputted? Right now everything comes out on 1 line and it would be nice if it was per line.


  • something

  • whatever

instead of
<ul><li>something</li><li>whatever</li></ul>

Would be great for readability...

current location

Hi,
could you plz modify your plugin to add possibility to create menu links to current location, but with additional parameters? Currently i'm using something like

  navigation.menu :en, "Eng", :url => {:controller => "", :action => "", :locale => 'en'}
  navigation.menu :ru, "Rus", :url => {:controller => "", :action => "", :locale => 'ru'} 

url should accept lambdas

That would be good if SimpleNavigation::Item would accept lambdas as url attr. That way I can use routes for resources. I extended SimpleNavigation::Item as:
class SimpleNavigation::Item
def url; @url.is_a?(Proc) ? @url.call : @url; end
end
Now In SimpleNavigation::Configuration.run block I can do next:
primary.item :edit, 'edit', lambda { edit_apartment_path @apartment }, :unless => lambda { @apartment.nil? }

Menu element class

Is there a way to specify a diffrent class to the "ul" element that gets created?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.