unbound imagination - a blog about programming

Rails Plugin: Simple Nav

May 04, 2008

So I've been on kind of a plugin creating binge in the past few weeks, but I promise this is the last one in this stretch. Basically, I took my blog and some other projects I've been working recently and extract the things that I felt were plugin worthy because either they are generic enough to be used on almost every site (this navigation helper and the javascript dependency helper) or it was not super specific and could be used by others the TextMate Syntax Highlighting plugin.

Anyway, this plugin is super simple to configure. It aims to centralize the navigation related logic such as which links a logged in/out user sees and when a certain link gets marked as "selected". It's broken down into 3 components for configuration:

  1. The Links that your site has for navigation (all of them, regardless if they are going to show up on every request)
  2. The order to display them for this request. This order can be any subset of the above list.
  3. The process to select the tab that is currently marked with the "selected" css class. (this part is broken into a basic and advanced version)

There is extensive documentation to explain all of the configuration in the README and the nav_helper that you can generate using script/generate.

It's hosted on GitHub at http://github.com/arya/simple_nav. As always, contributions and suggestions are highly encouraged.

Comments

posted by Rob Olson on 05/04/08 03:43 PM PDT

Would this be useful for a website where navigation is not controlled with tabs but still has links for navigation?

posted by Arya Asemanfar on 05/04/08 03:45 PM PDT

Yep. You can make it look like anything you want using CSS. The outputted HTML is just list (ul and li) elements so it's not specific to any particular navigation paradigm.

posted by Aaron H. on 05/15/08 10:04 AM PDT

That seems a lot like Ryan Heath's Navigation Helper plugin.

http://rpheath.com/posts/309-rails-plugin-navigation-helper http://github.com/rpheath/navigation_helper/tree/master

posted by Arya Asemanfar on 05/15/08 10:30 AM PDT

Hi Aaron,

I looked at Ryan Heath's nav helper and I respectfully disagree. Yes, they both are navigation plugins, but we took completely different approaches to building them. The main reason I released mine as a plugin is the "selection" logic. I hated having to specify "current_tab" at every turn, so my plugin uses a completely different approach to solving that. You may have not seen any of that from just reading the post. Take a look a look the README for an example or even check out the source and try using it.

Anyway, I hope you see why I chose to release this is a separate plugin and hopefully you'll try using it and providing feedback like you did for Ryan Heath's plugin :)

Update: Also, notice that using Ryan Heath's plugin, you can only specify links' visibility based on authorized/unauthorized while with this plugin, there is no limit to how many configurations you have (i.e. un-logged in, logged in, admin, etc).

posted by Nate L on 05/20/08 08:49 AM PDT

Hi Arya,
Thanks for the great plugin! I was curious if it was possible to use your tool for multiple navs in a single page? For example, can you use it for a main Nav and then also for a sub-nav on the same page?

posted by Arya Asemanfar on 05/20/08 10:26 AM PDT

Hi Nate,

At the current state of the plugin, the answer is no, it is limited to one set of navigation links per page. But if you'd like to work on adding it and submitting a pull request on GitHub, that would be a great contribution :) I do agree with you, that is something that would be useful so I will work on it as well in the coming weeks when I get some free time.

Thanks for the feedback.

posted by Nate L on 05/22/08 02:00 PM PDT

Cool.. I'll check it out, and see if I can find some time to add that. Thanks!


Leave a Comment