module Webgen::PathHandler::Base

This module provides the helper methods needed by most, if not all, path handlers.


It provides default implementations of all methods expected by Webgen::PathHandler except create_nodes, namely initialize, parse_meta_info! and content.

The most important method used when implementing a path handler is probably create_node which should be used in create_nodes to create an actual Webgen::Node object from a Webgen::Path object.

The following utility methods are also provided:



Public Class Methods


Initialize the path handler with the given Website object.

Public Instance Methods


Update path.meta_info with meta information found in the content of the path.

This default parse_meta_info! method does nothing and should be overridden in path handlers that know that additional meta information can be found in the content of the path itself.

Note that the return values of this method are given as extra parameters to the create_nodes method. If you don't handle extra parameters, return an empty array.

Protected Instance Methods

create_node(path) { |node| ... }

Create a node from path, if possible, and yield the fully initialized node if a block is given as well as return it.

Note that the block should be used when the newly created node need to be modified because the returned node can also be a reused node (in case the information in the supplied path applies uniquely to an already existing node)!

The node class to be used for the to-be-created node can be specified via `path.meta_info`. This is normally used by specific path handlers to provide custom node classes.

The default base node class can be changed by setting `path.meta_info`. Note that the `node_class` key takes precedence over this key!

The parent node under which the new node should be created can optionally be specified via 'path.meta_info'. This node processing information has to be set to the alcn of an existing node.

If no node can be created (e.g. when 'path.meta_info' is set), nil is returned.

On the created node, the node information :path is set to the given path and :path_handler to the path handler instance.

dest_path(parent, path)

Construct the destination path for the given path and parent node.

See the user documentation for how a destination path is constructed and which configuration options are used!

First it is checked if a node with the constructed destination path already exists. If it exists, the language part is forced to be in the destination path and the resulting destination path is returned.


Retrieve the node class that should be used for the given path.

node_exists?(path, dest_path)

Check if the node alcn or the destination path, which would be created by create_node for the given paths, exists.


Return the parent node for the given path.