class Webgen::Tree

Represents a tree of nodes.

Attributes

dummy_root[R]

The dummy root.

This is the default node that gets created when the Tree is created so that the real root node can be treated like any other node. It has only one child, namely the real root node of the tree.

node_access[R]

Direct access to the hashes for node resolving.

Only use this for reading purposes! If you just want to get a specific node for an alcn/acn/destination path, use node instead.

website[R]

The website to which the Tree object belongs.

Public Class Methods

new(website)

Create a new Tree object for the website.

Public Instance Methods

[](path)

Access a node via its :alcn.

delete_node(node)

Delete the node and all of its children from the tree.

The message :before_node_deleted is sent with the to-be-deleted node before the node is actually deleted from the tree.

node(path, type = :alcn)

Access a node via a path of a specific type.

If type is :alcn (default) then path has to be an absolute localized canonical name, if type is acn then path has to be an absolute canonical name and if type is :dest_path then path needs to be a destination path.

Returns the requested Node or nil if such a node does not exist.

register_node(node)

Utility method called by Node#initialize. This method should not be used directly!

resolve_node(path, lang, msg_on_failure = false)

Return the node representing the given path which can be an alcn/acn/destination path (name resolution is done in the specified order). The path has to be absolute, i.e. starting with a slash.

If the path is an alcn and a node is found, it is returned. If the path is an acn, the correct localized node according to lang is returned or if no such node exists but an unlocalized version does, the unlocalized node is returned. If the path is a destination path, the node with this destination path is returned.

If no node is found for the given path or if the path is invalid, nil is returned and, if msg_on_failure is true, the message :node_resolution_failed (with parameters path and lang) is dispatched.

root()

The real root node of the tree.

translate_node(node, lang)

Return the translation of the node to the language lang or, if no such node exists, an unlocalized version of the node. If no such node is found either, nil is returned.

translations(node)

Return all translations of the node.