Method: Webgen::Node#initialize
- Defined in:
- lib/webgen/node.rb
#initialize(parent, cn, dest_path, meta_info = {}) ⇒ Node
Create a new Node instance.
parent(immutable)-
The parent node under which this nodes should be created.
cn(immutable)-
The canonical name for this node. Needs to be of the form ‘basename.ext’ or ‘basename’ where
basenamedoes not contain any dots. Also, thebasenamemust not include a language part! dest_path(immutable)-
The full output path for this node. If this node is a directory, the path must have a trailing slash (‘dir/’). If it is a fragment, it has to include a hash sign. This can also be an absolute path like example.com.
meta_info-
A hash with meta information for the new node.
The language of a node is taken from the meta information lang and the entry is deleted from the meta information hash. The language cannot be changed afterwards! If no lang key is found, the node is unlocalized.
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/webgen/node.rb', line 79 def initialize(parent, cn, dest_path, = {}) @parent = parent @children = [] @cn = cn.freeze @dest_path = dest_path.freeze @lang = Webgen::LanguageManager.language_for_code(.delete('lang')) @lang = nil unless is_file? @lcn = Webgen::Path.lcn(@cn, @lang).freeze @acn = (@parent.kind_of?(Webgen::Node) ? @parent.acn.sub(/#.*$/, '') + @cn : '').freeze @alcn = (@parent.kind_of?(Webgen::Node) ? @parent.alcn.sub(/#.*$/, '') + @lcn : '').freeze @meta_info = @node_info = {} @level = -1 @tree = @parent (@level += 1; @tree = @tree.parent) while @tree.kind_of?(Webgen::Node) @tree.register_node(self) @parent.children << self unless @parent == @tree end |