class Webgen::PathHandler::MetaInfo
Handles meta information paths which provide meta information for other paths.
Public Class Methods
new(website)
click to toggle source
Upon creation the path handler registers itself as listener for the :apply_meta_info_to_path and :after_node_created hooks so that it can apply the meta information.
Calls superclass method
Webgen::PathHandler::Base::new
# File lib/webgen/path_handler/meta_info.rb 19 def initialize(website) 20 super 21 @website.blackboard.add_listener(:apply_meta_info_to_path, 'path_handler.meta_info', 22 &method(:apply_meta_info_to_path)) 23 @website.blackboard.add_listener(:after_node_created, 'path_handler.meta_info', 24 :before => 'item_tracker.node_meta_info', &method(:after_node_created)) 25 @paths = [] 26 @alcns = [] 27 end
Public Instance Methods
create_nodes(path, blocks)
click to toggle source
Create a meta info node from path
.
# File lib/webgen/path_handler/meta_info.rb 30 def create_nodes(path, blocks) 31 @paths += add_data(path, blocks['paths'], 'paths') 32 entries = add_data(path, blocks['alcn'], 'alcn') 33 @alcns += entries 34 update_existing_nodes(entries) 35 36 nil 37 end
Private Instance Methods
add_data(path, content, block_name)
click to toggle source
Add the data from the given page block to the hash.
# File lib/webgen/path_handler/meta_info.rb 44 def add_data(path, content, block_name) 45 entries = [] 46 if content && (data = YAML::load(content)) 47 data.each do |(*keys), value| 48 value = Marshal.dump(value) 49 keys.each {|key| entries << [Webgen::Path.append(path.parent_path, key), value]} 50 end 51 end 52 entries 53 rescue Exception => e 54 raise Webgen::NodeCreationError.new("Could not parse block '#{block_name}': #{e.message}", "path_handler.meta_info") 55 end
after_node_created(node)
click to toggle source
Update the meta information of a matched alcn after the node has been created.
# File lib/webgen/path_handler/meta_info.rb 76 def after_node_created(node) 77 @alcns.each do |pattern, mi| 78 node.meta_info.update(Marshal.load(mi)) if Webgen::Path.matches_pattern?(node.alcn, pattern) 79 end 80 end
apply_meta_info_to_path(path)
click to toggle source
Update the meta info of matched path before a node is created.
# File lib/webgen/path_handler/meta_info.rb 67 def apply_meta_info_to_path(path) 68 hash = {} 69 @paths.each do |pattern, mi| 70 hash.merge!(Marshal.load(mi)) if Webgen::Path.matches_pattern?(path, pattern) 71 end 72 path.meta_info.replace(hash.merge!(path.meta_info)) if hash.length > 0 73 end
update_existing_nodes(entries)
click to toggle source
Update already existing nodes with meta information from the given meta info node.
# File lib/webgen/path_handler/meta_info.rb 58 def update_existing_nodes(entries) 59 @website.tree.node_access[:alcn].each do |alcn, node| 60 entries.each do |pattern, mi| 61 node.meta_info.update(Marshal.load(mi)) if Webgen::Path.matches_pattern?(alcn, pattern) 62 end 63 end 64 end