Class Nav::Node
In: nav.rb
Parent: Object

Nav::Node

A node stores metadata about a unique document: a human-readable name, a URL for the document, a list of child nodes (pages one level down on this branch of the document tree), etc.

The metadata is extracted from one of two places. If the node corresponds to an index file, then we check for a specially named plain-text file (see METADATA_FILENAME) in the directory where that index file lives. Otherwise, if the node is a file, we scan that file for embedded <meta> tags. Entirely dynamically-generated pages are not supported.

Each node is identified by a unique sequence of tokens indicating its location in the web server's filesystem. We use tokens instead of URLs because a single web page may be identified by multiple URLs, yet we need a unique identifier. See Nav::Tokens.

Fetching metadata

For the node identified by the tokens

  ['groups', 'research', 'probability']

we will check if

 DOCUMENT_ROOT/groups/research/probability

is a directory; if so, we'll look in

 DOCUMENT_ROOT/groups/research/probability/<METADATA_FILE>

for our metadata. If the directory does not exist, we'll check for a file named

 DOCUMENT_ROOT/groups/research/probability

and, if it exists, we will scan it for specially-named <meta> tags.

Finally, if we can't find any metadata, we'll return a dummy node with no children. Its name will be the last token in the URL (for local URLs) or the entire URL (for absolute URLs)

Accessible instance variables

@url

an absolute URL to this node on our server, e.g., "/research/probability". It's also a relative path in file system where the node can be found under document_root. This value also serves as a unique identifier when storing or retrieving nodes from a database.

@name

The human-readable label for this node, e.g., "Probability research group"

Methods
children    collapsible?    debug    each_child    fetch    fetch_metadata_from_filesystem    handle_config_setting    hidden?    is_root?    new    num_children    path    stale?    to_html   
Attributes
:name  [R] 
:url  [R] 
Public Class methods
fetch(url='', check_cache_only=false)

Returns the most recent data available for a node with this URL

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

new(url, name='', child_urls=[], last_cached=nil, collapsible=false, hidden=false)
Public Instance methods
debug(str)
is_root?()

Is this node the root of the document tree?

collapsible?()

When building a fisheye view, should we hide the children of this node that aren't on the breadcrumb trail? i.e., children whose URLs are part of the URL of the current page? (Returns @collapsible.)

hidden?()

When building a fisheye view or sitemap, should we hide this node if it isn't on breadcrumb trail? i.e., if its URL is part of the URL for the current page? (Returns @hidden.)

stale?()

Is this node's on-disk metadata (in nav.txt or <meta> tags) fresher than the data we have cached for it? Returns true if no cache is available at all.

path()

Returns an absolute path to where this node lives in the filesystem.

children(cache_only=false)

Returns a list of URLs for the immediate children of this node

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.

num_children()
each_child(cache_only=false) {|Node.fetch(url, cache_only)| ...}

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.

to_html(active=false)

Returns a HTML hyperlink to this node. If "active" is true, the hyperlink is embedded in <strong> tags.

handle_config_setting(key, val)

Given a key/value pair from a metadata source, set the appropriate instance variable (if any).

fetch_metadata_from_filesystem()

Refresh this node's cached metadata with info culled from nav.txt files, or embedded in HTML <meta> tags.