Blog / Announcing: Tabnav

Alex Tomlins
July 30, 2010

I’ve just released a new gem called Tabnav. It’s a Rails helper for generating navbars. It allows you to specify highlighting rules for each nav item in a clean way without lots of conditionals in your views.

It is loosely based on the widget from rails-widgets, and uses a similar DSL. You may ask why I bothered writing this if something similar already exists. Well, simply, there are some things about the rails-widgets implementation that I really don’t like. Specifically, it hijacks javascript_include_tag to insert it’s own javascript. This sort of thing should be explicit. Also the markup it generates could be cleaner - it has some unnecessary extra tags in it, and repeated class names. I created this to clean up these problems, and add new features. I’ve added support for custom partials for tab contents, and I plan to add support for nested menus in the next version.

So how does it work? Well, that’s easiest to show with some examples…

A Basic Navbar

In the view:

  rendertabnav do |n|
    n.addtab do |t|
      t.named "Home"
      t.linksto rootpath
      t.highlightson :controller => :home, :action => :index
    n.addtab do |t|
      t.named "Froobles"
      t.linksto frooblespath
      t.highlightson :controller => :froobles

When rendering the home page

It allows lots of control over the generated markup:

In the view:

On froobles/index outputs:

and if that’s not enough for you, you can even specify your own partial to be used to render the tab contents.

Check out the github project page for full documentation etc. For feature requests or bug reports use the github issue tracker.