Module Nav
In: nav.rb

Nav - dynamic web navigation

If you're just getting started, please see the README and INSTALL files first.

This module generates hyperlinks to aid in navigating a web site. Public methods breadcrumbs and fisheye both return chunks of HTML code that indicate where a given document lies within a document hierarchy. sitemap attempts to create an overview of the entire site's structure without any additional "you are here" information.

How we build navigation elements

First we extract the URL of the current document (the one invoking this module, that is) from environment variables. Then we split that URL into a list of tokens representing a path through the document hierarchy. For example, the URL

   /research/probability/seminars/index.html

yields the token sequence

   ['research', 'probability', 'seminars']

(Note that index files don't have corresponding tokens, but their parent directories do.)

If we're lucky, this sequence maps directly onto the filesystem path where the "seminars" page lives:

   DOCUMENT_ROOT/research/probability/seminars

(For how we handle the less lucky cases, see BOGONODE in the Installation section.)

We then walk this filesystem path and pick up metadata along the way. (A page and its associated metadata is known as a Node. See Nav::Node for details.) In cases where a token corresponds to a directory with an index file (as with all the tokens in our list above), we look for a metadata file in that directory named nav.txt (the name is customizable: see METADATA_FILENAME in nav.rb). If the token corresponds to an HTML file instead of a directory, then we scan the file for specially-named <meta> tags. (See the Metadata syntax section for details.)

Methods
breadcrumbs    fisheye    site_root_url    sitemap   
Classes and Modules
Class Nav::Cache
Class Nav::Node
Class Nav::Tokens
Public Class methods
site_root_url()
breadcrumbs(cache_only=false, url=caller_url)

Returns a list of HTML hyperlinks one could follow to reach the page currently being viewed. The link for the current page has a CSS class of "active" and is surrounded by <strong> tags (for the benefit of browsers that don't understand CSS).

If cache_only is true, do not consult the filesystem for node data under any circumstance. Obviously a cache must be available in this case.

fisheye(cache_only=false, url=caller_url)

Returns a set of nested HTML "unordered lists" (<ul>) containing links to pages on the breadcrumb trail (see breadcrumbs) and their children.

If cache_only is true, do not consult the filesystem for node data under any circumstance. Obviously a cache must be available in this case.

sitemap(cache_only=false, node=nil, current_depth=0, max_depth=SITEMAP_DEPTH)

Attempts to return a map of the entire site by traversing children of the root node. It can therefore only show branches of the tree that are explicitly mentioned in author-created metadata. Nodes that are hidden? are omitted, along with their children.

If cache_only is true, do not consult the filesystem for node data under any circumstance. Obviously a cache must be available in this case.

Returns a set of recursively nested unordered lists (<ul>) following the document hierarchy down to a level specified by max_depth, for example:

 <ul>
   <li>
     Home
     <ul>
       <li>
          foo
          <ul><li>zot</li></ul>
       </li>
       <li>bar<li>
       <li>baz</li>
     </ul>
   </li>
 </ul>

If the hierarchy has more than three branches at the top level, they will be split into two separate sub-lists to permit two-column presentation via style sheets. (The second list will have the class "col2".)

 <ul>
   <li>
     Home
     <ul>
       <li>
          foo
          <ul><li>zot</li></ul>
       </li>
       <li>bar<li>
     </ul>
     <ul class="col2">
       <li>baz</li>
       <li>quux</li>
     </ul>
   </li>
 </ul>