Menu Helper plugin

Plugin details

Menu Helper adds a helper method for generating a menubar.
The generation of a menubar's structure can often be a repetitive and unDRY process. A standard using unordered lists is generally followed when creating a menubar. menu_helper attempts to following this standard in addition to automatically adding ids, classes for selected menus, and default urls each menu is linked to (base on various information, such as the name of the menu).

Websitehttp://wiki.pluginaweek.org/Menu_helper Repositoryhttp://svn.pluginaweek.org/trunk/menu_helper/ Author Aaron Pfeifer Tags menu, helper LicenseMIT

Documentation

Install the plugin:
ruby script/plugin install http://svn.pluginaweek.org/trunk/menu_helper/

routes.rb:

  ActionController::Routing::Routes.draw do |map|
    map.with_options(:controller => 'site') do |site|
      site.home '', :action => 'index'
    end
    
    map.with_options(:controller => 'about_us') do |about_us|
      about_us.about_us     'about_us',             :action => 'index'
      about_us.contact      'about_us/contact',     :action => 'contact'
      about_us.who_we_are   'about_us/who_we_are',  :action => 'who_we_are'
    end
    
    map.with_options(:controller => 'products') do |products|
      products.products 'products', :action => 'index'
    end
    
    map.with_options(:controller => 'services') do |services|
      services.services 'services', :action => 'index'
    end
  end


_menubar.rhtml:

  <%=
    menu_bar do |main|
      main.menu :home
      main.menu :products
      main.menu :services
      main.menu :about_us do |about_us|
        about_us.menu :overview, 'Overview', about_us_url
        about_us.menu :who_we_are
        about_us.menu :contact, 'Contact Us'
      end
      main.menu :search, 'Search!', 'http://www.google.com', :class => 'ir'
    end
  %>


Output (formatted for sanity):

  < ul id="menubar">
    < li id="home">< a href="http://example.com/">Home< /a>< /li>
    < li id="products">< a href="http://example.com/products">Products< /a>< /li>
    < li id="services">< a href="http://example.com/services">Services< /a>< /li>
    < li class="selected" id="about_us">< a href="http://example.com/about_us">About Us< /a>
      < ul id="about_us_menubar">
        < li id="overview">< a href="http://example.com/about_us">Overview< /a>< /li>
        < li class="selected" id="who_we_are">< a href="http://example.com/about_us/who_we_are">Who We Are< /a>< /li>
        < li class="last" id="contact">< a href="http://example.com/about_us/contact">Contact Us< /a>< /li>
      < /ul>
    < li class="search ir" id="search">< a href="http://www.google.com">Search!< /a>< /li>
  < /ul>

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | Back in time (1 older version) | Last edited by: obrie572, about 7 hours ago