public
Description: A Rails plugin for easy (nested) tabbed navigation
Homepage: http://jordi.github.com/tab_tab/
Clone URL: git://github.com/jordi/tab_tab.git
name age message
file .gitignore Wed Feb 11 14:06:08 -0800 2009 First version [jordi]
file CHANGES Sun Mar 29 07:35:22 -0700 2009 Filename consistency [jordi]
file MIT-LICENSE Wed Feb 11 14:06:08 -0800 2009 First version [jordi]
file README.rdoc Fri Feb 20 16:10:46 -0800 2009 Killed tab_helper_helper in favor of multiple m... [jordi]
file Rakefile Mon Mar 02 09:27:13 -0800 2009 Trying to stay out of Ruby 1.9's way [jordi]
file init.rb Sun Mar 29 07:35:22 -0700 2009 Filename consistency [jordi]
file install.rb Wed Feb 11 14:06:08 -0800 2009 First version [jordi]
directory lib/ Sun Mar 29 07:35:22 -0700 2009 Filename consistency [jordi]
directory tasks/ Wed Feb 11 14:06:08 -0800 2009 First version [jordi]
directory test/ Sat Mar 28 22:38:39 -0700 2009 Testing the helper helpers explicitly [jordi]
file uninstall.rb Wed Feb 11 14:06:08 -0800 2009 First version [jordi]
README.rdoc

tab_tab is an MVC-violating (there, you’ve been warned) plugin that allows for easy tabbed navigation, without forcing your controllers to be named in any given way.

It makes for very clean views with zero tab navigation logic. On your controllers:

  class ElephantsController < ApplicationController

    tab :elephants
  end

On your views:

  <ul>
    <%= tab('/e', :elephants) -%>  # This will be <li class="active">...
    <%= tab('/h', :hippos)    -%>
  </ul>

That’s the simplest case. You can also nest:

  class ElephantsController < ApplicationController

    tab :animals => :elephants  # or tab 'animals', 'elephants'
  end

And on the view (notice the two levels of "active"):

  <ul id="first-level-tabs">
    <%= tab('/a', :animals) -%>  # <li class="active">...
    <%= tab('/p', :plants)  -%>
  </ul>

  <ul id="second-level-tabs">
    <%= tab('/a/e', :animals => :elephants) -%>  # <li class="active">...
    <%= tab('/a/h', :animals => :hippos)    -%>
  </ul>

You can also nest in the view using the tabs_for helper. The example above would become:

  <ul id="second-level-tabs">
    <% tabs_for :animals do |animal| %>
      <%= animal.tab('/a/e', :elephants) -%>  # <li class="active">...
      <%= animal.tab('/a/h', :hippos)    -%>
    <% end %>
  </ul>

And you can also call the tab method at "runtime" on your controllers (which means you can use it on before_filters, and/or with custom if/unless branch logic based on request parameters), like so:

  class ElephantsController < ApplicationController

    tab :animals => :elephants

    def edit
      tab :animals => { :elephants => :edit }
    end
  end

The tab helper in the view is hardcoded to produce an HTML list element with a link inside. Overriding it is easy, since it actually delegates all of the who’s-the-current-tab logic to helper methods (See TabTab::ViewHelpers).

CSS is on you. Patches welcome.

Copyright © 2009 Jordi Bunster <jordi@bunster.org>, released under the MIT license