module Webgen::Tag::BreadcrumbTrail

Generates a breadcrumb trail for the page. Such a breadcrumb trail is especially useful when pages are in deep hierarchies of directories.

Public Class Methods

call(tag, body, context) click to toggle source

Create the breadcrumb trail.

   # File lib/webgen/tag/breadcrumb_trail.rb
12 def self.call(tag, body, context)
13   options = {
14     :alcn => context.content_node.alcn,
15     :start_level => context[:config]['tag.breadcrumb_trail.start_level'],
16     :end_level => context[:config]['tag.breadcrumb_trail.end_level'],
17     :omit_dir_index => context[:config]['tag.breadcrumb_trail.omit_dir_index']
18   }
19   context.website.ext.item_tracker.add(context.dest_node, :nodes,
20                                        ['Webgen::Tag::BreadcrumbTrail', 'nodes'], options, :meta_info)
21 
22   context[:nodes] = nodes(context.website, options)
23   Webgen::Tag.render_tag_template(context, 'breadcrumb_trail')
24 end
nodes(website, options) click to toggle source

Return the list of nodes that make up the breadcrumb trail of a node while respecting the parameters.

The options hash needs to include the following keys:

:alcn

The alcn of the node for which the breadcrumb trail should be generated.

:start_level

The start level (an index into an array).

:end_level

The end level (an index into an array).

:omit_dir_index

If set, omits the last path component if it is a directory index.

   # File lib/webgen/tag/breadcrumb_trail.rb
43 def self.nodes(website, options)
44   node = website.tree[options[:alcn]]
45   nodes = []
46   omit_dir_index = if node.meta_info.has_key?('omit_dir_index')
47                      node['omit_dir_index']
48                    else
49                      options[:omit_dir_index]
50                    end
51 
52   node = node.parent if omit_dir_index && node.parent.proxy_node(node.lang) == node
53 
54   until node == website.tree.dummy_root
55     nodes.unshift(node)
56     node = node.parent
57   end
58   nodes[options[:start_level]..options[:end_level]].to_a
59 end