Forum: Ruby on Rails styles for tabnav plugin

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Star B. (Guest)
on 2007-03-06 15:46
Hi all,

I'm using the tabnav plugin for a community project and I think it is
quite comfortable to use.

But, when I have many tabbed screens in my app, I have to generate many
corresponding xyz_tabnav.rb models. Now for each of these models there
seems to be one template xyz_tybnav.rhtml which contains the style for
the corresponding tabnav.

In my app ALL tabbed screens will have the SAME style (as I would assume
for most apps in general). Does it mean that I have to maintain many of
these style files for all the tabbed screens redundantly?

Or can I consolidate the one style for all tabbed screens?

Cheers,

Star
KRD (Guest)
on 2007-03-06 17:17
(Received via mailing list)
I modified the 'def tabnav tabnav_sym method' from tabnav's
application_helper_extension.rb to check the tabnav_sym to determine
the object being rendered. Based on that information, I select the
partial to use for the rendering. I do a bit of code in the
application.rhtml layout using @first_render or getting the controller
name directly to select the tabnav to display and pass that to the
start tabnav tag.

I now have two partials (two nested tab styles) that replace what
would have been over 15 tabnav partials for my application. I don't
know if this will work with the newer versions, but it solved my
problem.

Example with a nested tabnav:

app/views/layouts/application.rhtml:

<%= render_partial 'common/header' -%>

<%= start_tabnav :main -%>
    <%
    case @first_render
        when /^admin/
            tabnav_set = :admin
        when /^home/
            tabnav_set = :home
    end %>
    <%= start_tabnav tabnav_set -%>
    <!-- start content -->
    <%= yield -%>
    <%= end_tabnav -%>
    <!-- end content -->
<%= end_tabnav -%>

<%= render_partial 'common/footer' -%>

tabnav application_helper.rb:

  # Selects the correct template to use for rendering the selected
  # tabnav object.
  def tabnav tabnav_sym
    # Set the name of the template
    if tabnav_sym.id2name == 'main'
      tabnav_template = 'main'
    else
      tabnav_template = 'secondary'
    end

    # Render the tabnav partial
    result = capture do
      render :partial => "tabnav/#{tabnav_template}_tabnav",
             :locals => { :tabs => tabnav_sym.to_tabnav.tabs }
    end
    result
  end



On Mar 6, 6:46 am, Star B. <removed_email_address@domain.invalid>
Star B. (Guest)
on 2007-03-06 18:28
Sounds good.

Another solution could be to change the tabnav renderer in a way that
not the tabnav class name is used to generate the style name but that a
style name could be set via a method "set_style" in the tabnav class
definition (like "add_tab").

KRD wrote:
> I modified the 'def tabnav tabnav_sym method' from tabnav's
> application_helper_extension.rb to check the tabnav_sym to determine
> the object being rendered. Based on that information, I select the
> partial to use for the rendering. I do a bit of code in the
> application.rhtml layout using @first_render or getting the controller
> name directly to select the tabnav to display and pass that to the
> start tabnav tag.
Paolo D. (Guest)
on 2007-03-16 15:39
You can specify the Tabnav's class prefix with:

class BasicTabnav < Tabnav::Base
    html_options :class => 'inner_tabnav'

    add_tab
      ...
    end
end

This overrides the default class naming, so you can share the same style
for every  Tabnav. Then I'd remove the partials and move my CSS code
inside the main .css file.
Star B. (Guest)
on 2007-03-20 09:22
Paolo D. wrote:
> You can specify the Tabnav's class prefix with:
>
> class BasicTabnav < Tabnav::Base
>     html_options :class => 'inner_tabnav'
>
>     add_tab
>       ...
>     end
> end
>
> This overrides the default class naming, so you can share the same style
> for every  Tabnav. Then I'd remove the partials and move my CSS code
> inside the main .css file.

Thanks! That was the only thing missing...
This topic is locked and can not be replied to.