Object
Handles meta information files which provide meta information for other files.
Upon creation the object registers itself as listener for some node hooks.
# File lib/webgen/sourcehandler/metainfo.rb, line 17 17: def initialize 18: website.blackboard.add_listener(:node_meta_info_changed?, method(:node_meta_info_changed?)) 19: website.blackboard.add_listener(:before_node_created, method(:before_node_created)) 20: website.blackboard.add_listener(:before_node_deleted, method(:before_node_deleted)) 21: website.blackboard.add_listener(:after_node_created, method(:after_node_created)) 22: self.nodes ||= [] 23: end
Create a meta info node from path.
# File lib/webgen/sourcehandler/metainfo.rb, line 26 26: def create_node(path) 27: page = page_from_path(path) 28: super(path) do |node| 29: [[:mi_paths, 'paths'], [:mi_alcn, 'alcn']].each do |mi_key, block_name| 30: node.node_info[mi_key] = {} 31: if page.blocks.has_key?(block_name) && (data = YAML::load(page.blocks[block_name].content)) 32: data.each do |key, value| 33: key = Webgen::Path.make_absolute(path.parent_path, key) 34: node.node_info[mi_key][key] = value 35: end 36: end 37: end 38: 39: mark_all_matched_dirty(node, :no_old_data) 40: 41: website.cache.permanent[[:sh_metainfo_node_mi, node.alcn]] = { 42: :mi_paths => node.node_info[:mi_paths], 43: :mi_alcn => node.node_info[:mi_alcn] 44: } 45: 46: self.nodes << node unless self.nodes.include?(node) 47: self.nodes = self.nodes.sort_by {|n| n.alcn} 48: end 49: end
Update the meta information of a matched alcn after the node has been created.
# File lib/webgen/sourcehandler/metainfo.rb, line 99 99: def after_node_created(node) 100: self.nodes.each do |n| 101: n.node_info[:mi_alcn].each do |pattern, mi| 102: node.meta_info.update(mi) if node =~ pattern 103: end 104: end 105: end
Update the meta info of matched path before a node is created.
# File lib/webgen/sourcehandler/metainfo.rb, line 90 90: def before_node_created(path) 91: self.nodes.each do |node| 92: node.node_info[:mi_paths].each do |pattern, mi| 93: path.meta_info.update(mi) if Webgen::Path.match(path, pattern) 94: end 95: end 96: end
Delete the meta info node node from the internal array.
# File lib/webgen/sourcehandler/metainfo.rb, line 119 119: def before_node_deleted(node) 120: return unless node.node_info[:processor] == self.class.name 121: mark_all_matched_dirty(node, :force) 122: website.cache.permanent.delete([:sh_metainfo_node_mi, node.alcn]) 123: self.nodes.delete(node) 124: end
Mark all nodes that are matched by a path or an alcn specifcation in the meta info node node as dirty.
# File lib/webgen/sourcehandler/metainfo.rb, line 83 83: def mark_all_matched_dirty(node, option = nil) 84: node.tree.node_access[:alcn].each do |path, n| 85: n.flag(:dirty_meta_info) if meta_info_changed?(node, n, option) 86: end 87: end
Return true if any meta information for node provided by mi_node has changed.
# File lib/webgen/sourcehandler/metainfo.rb, line 64 64: def meta_info_changed?(mi_node, node, option = nil) 65: cached = website.cache.permanent[[:sh_metainfo_node_mi, mi_node.alcn]] 66: (mi_node.node_info[:mi_paths].any? do |pattern, mi| 67: Webgen::Path.match(node.node_info[:creation_path], pattern) && 68: (option == :force || (!cached && option == :no_old_data) || mi != cached[:mi_paths][pattern]) 69: end || mi_node.node_info[:mi_alcn].any? do |pattern, mi| 70: node =~ pattern && (option == :force || (!cached && option == :no_old_data) || mi != cached[:mi_alcn][pattern]) 71: end || (option == :no_old_data && cached && 72: ((cached[:mi_paths].keys - mi_node.node_info[:mi_paths].keys).any? do |p| 73: Webgen::Path.match(node.node_info[:creation_path], p) 74: end || (cached[:mi_alcn].keys - mi_node.node_info[:mi_alcn].keys).any? do |p| 75: node =~ p 76: end) 77: ) 78: ) 79: end
Check if the node has meta information from any meta info node and if so, if the meta info node in question has changed.
# File lib/webgen/sourcehandler/metainfo.rb, line 109 109: def node_meta_info_changed?(node) 110: self.nodes.each do |n| 111: if n.flagged?(:created) && meta_info_changed?(n, node) 112: node.flag(:dirty_meta_info) 113: return 114: end 115: end 116: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.