What changes in the new Widgets Tabnav?

Posted by Paolo Mon, 03 Sep 2007 14:14:00 GMT

Hi guys, I just gotten back from my one-week vacation in Egypt and imagine what I found on my email inbox? Wow… a bunch of people are giving us feedback on the new Tabnav widget just a few days after its public release.

So let’s dig some changes between the old version and the new one:

Tabnav didn’t highlight with URLs beginning with a slash

Let’s consider this scenario:

add_tab do |t|
  t.named 'Cat'
  t.links_to :controller => '/cats'
end 

This didn’t correctly highlight on :controller => 'cats' beacuse of the leading slash of the controller parameter. Now thanks to Cédric Deltheil this issue as been solved. I’ve never experienced this problem myself… It’s difficult to fix something if you don’t know it’s broken :-) (Cédric pointed me to an old Peter Salomon comment rearding this issue. I didn’t get notified about that comment… so I apologize. I start hating typo, I promise we’ll move to a new blogging system soon).

Where’s my beloved show_if method?

show_if was a very useful method in the old Tabnav. You could set a condition to show or hide specific tabs (eg Administration tabs). Well, we got rid of that. With the new Widgets version the Tabnav definition is backed up by a partial, no more a specific model. That allows us to use pure ruby conditional code to add tabs whenever we want to. And that’s just because the tabnav definition gets reevaluated for every request.

One example is better that a thousand words: look at the if modifier at the end of the 2nd tab:

<% 
render_tabnav :main, :generate_css => true do
    add_tab do |t|
        t.named 'Home'
        t.links_to :controller => 'home'
    end

    add_tab do |t| 
        t.named 'Users'
        t.links_to :controller => 'users'
    end if current_user.admin?
end
%> 

You can also enclose one or more add_tab inside a if/unless block like this:

if @admin
  add_tab do |t| 
        t.named 'Users'
        t.links_to :controller => 'users'
  end 

  add_tab do |t| 
        t.named 'Customers'
        t.links_to :controller => 'customers'
  end 
end

It’s clear now that the show_if method wasn’t really necessary and was difficult to use because of the procs. Now you can just use your view’s params/variables/helpers as conditions.

True dynamic tabs

The facts that Tabnav is now a helper leads to another big improvement. You can now have true dynamic tabs. The default generated Tabnav now generates something like this:

render_tabnav :main, 
              :generate_css => true do 

  controller_names.each do |name|
    add_tab do |t|
      t.named name.camelize
      t.titled "Go to #{name.camelize}"
      t.links_to :controller => name
    end
  end

end 

What does that mean? It dynamically generates a tab for every controller, just like the scaffold does with column names! Of course you’ve got to customize that, but it shows the power that this version brings to you.

You can now have a tab for every user like 37signals’s Highrise does! Just imagine something like this:

render_tabnav :contacts, 
              :generate_css => true do 

  @contacts.each do |contact|
    add_tab do |t|
      t.named contact.name
      t.links_to :controller => 'contacts', :action => 'show', :id => contact.id
    end
  end

end 

No more start/end

Another little improvement: Tabnav’s content are now specified as a block.

# old version
<%= start_tabnav :main %>
  ...
<%= end_tabnav %>

#new widget version
<% tabnav :main do %>
  ...
<% end %>

It’s just a lot more Rubysh now… Hope you enjoy the improvements. If you experience issues just drop us a line.

A big thank you to Cédric Deltheil, Mark Swinson, Denis Bruléand and Glenn West for their feedback!

Posted in  | Tags , , ,  | 5 comments | no trackbacks

Trackbacks

Use the following link to trackback from your own site:
http://blog.seesaw.it/articles/trackback/215936

Comments

  1. Avatar LGS said 11 days later:

    Hi all, seems very nice & I’d like to have a try, but I can’t get it :

    C:\rails_apps\stubapp>ruby script/plugin source svn://svn.seesaw.it/widgets/trunk Added 1 repositories.

    C:\rails_apps\stubapp>ruby script/plugin install svn://svn.seesaw.it/widgets/trunk A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

    ... not a firewall cut cause the other install actually works.

  2. Avatar Jamal said 27 days later:

    Me too,

    I cannot get the plugin?

  3. Avatar andrea said 40 days later:

    i have the same problem, i can’t install plugin with rails script

  4. Avatar laurance said 52 days later:

    me too, still can’t get plugin from svn://svn.seesaw.it/widgets/trunk as of Oct. 25 @ 3:00 pm EST.

  5. Avatar Bradley Gessler said 86 days later:

    My only gripe was that the tabs were all slapped inside of a tag. Since

      is already a block, this didn’t seem necessary.

      The great news is that it was super easy to open up the source and remove all of the div tags!

Comments are disabled


SeeSaw srl - Via Monte Pasubio, 8 37126 Verona - tel +39 045 4857457 fax 045 4851151 P.Iva 03609790237