Navigation Tags help

Hi folks,

I have a set of navigation tags here:
http://svn.artofmission.com/svn/plugins/radiant/plugins/
navigation_tags/

Basically, it lets you build nested navigation like you see here:
http://radiant.artofmission.com/blog/

The idea is to expand the navigation below the page that you’re
currently on. So if you’re on the “About” page, you see only the two
top-level items, but if you go to the “Blog” page, you see that
page’s sub-pages in the nav.

The trouble is that the tags are very slow - rendering the page can
take as long as 2-3 seconds on a big site. (Once the page is cached,
it loads very quickly of course.) If anyone would like to help me
figure out how to make this work faster, your help would be much
appreciated!

Here are the snippets that I use to generate that navigation:

SNIPPET: nav

SNIPET: sub-nav
<r:unless_content part=“no-map”>
<li<r:if_self> class=“current”</r:if_self>><r:link />
<r:if_children>
<r:if_ancestor_or_self>


    <r:children:each>
    <r:snippet name=“sub-nav” />
    </r:children:each>

</r:if_ancestor_or_self>
</r:if_children>

As far as I can tell, it’s the “if_ancestor_or_self” tag that’s
slowing it down. Here is the content of navigation_tags.rb:

module StandardTags
include Radiant::Taggable

Inspired by this thread:

http://www.mail-archive.com/[email protected]/

msg03234.html
desc %{
Renders the contained element if the current item is an ancestor
of the current page or if it is the page itself.
}
tag “if_ancestor_or_self” do |tag|
tag.expand if (tag.globals.actual_page.ancestors +
[tag.globals.actual_page]).include?(tag.locals.page)
end

desc %{
Renders the contained element if the current item is also the
current page.
}
tag “if_self” do |tag|
tag.expand if tag.locals.page == tag.globals.actual_page
end

desc %{
Renders the contained elements only if the current contextual
page has children.

 *Usage:*
 <pre><code><r:if_children>...</r:if_children></code></pre>

}
tag “if_children” do |tag|
children = tag.locals.page.children
tag.expand if children.size > 0
end

end

One optimization you might be able to make to the if_ancestor_or_self
(which normally could result in tons of DB calls) is to match the URL of
the page in the iteration against the actual page. If the first part
matches, then expand. Of course, this breaks if your site gets complex
– virtual pages and such are the usual culprits.

tag ‘if_ancestor_or_self’ do |tag|
tag.expand if
tag.globals.actual_page.url.starts_with?(tag.locals.page.url)
end

Cheers,

Sean

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs