Sha256: 48225866a960a9e9d53b3ae4512ad0f826a18c4f55b6d5287454e74f5e4d4273

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

require 'webgen/tag'

module Webgen::Tag

  # Generates a breadcrumb trail for the page. This is especially useful when pages are in deep
  # hierarchies of directories.
  class BreadcrumbTrail

    include Webgen::Tag::Base

    # Create the breadcrumb trail.
    def call(tag, body, context)
      out = []
      node = context.content_node

      omit_index_path = if node.meta_info.has_key?('omit_index_path')
                          node['omit_index_path']
                        else
                          param('tag.breadcrumbtrail.omit_index_path')
                        end
      omit_index_path = omit_index_path && node.parent.routing_node(node.lang) == node

      node = node.parent if omit_index_path

      until node == node.tree.dummy_root
        context.dest_node.node_info[:used_nodes] << node.routing_node(context.dest_node.lang).absolute_lcn
        context.dest_node.node_info[:used_nodes] << node.absolute_lcn
        out.push(context.dest_node.link_to(node.in_lang(context.content_node.lang)))
        node = node.parent
      end
      out[0] = '' if param('tag.breadcrumbtrail.omit_last') && !omit_index_path
      out = out.reverse.join(param('tag.breadcrumbtrail.separator'))
      log(:debug) { "Breadcrumb trail for <#{context.dest_node.absolute_lcn}>: #{out}" }
      out
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
webgen-0.5.1 lib/webgen/tag/breadcrumbtrail.rb