Object
Handles files which contain specifications for “virtual” nodes, ie. nodes that don’t have real source path.
This can be used, for example, to provide multiple links to the same node.
Create all virtual nodes which are specified in path.
# File lib/webgen/sourcehandler/virtual.rb, line 23 23: def create_node(path) 24: nodes = [] 25: read_data(path).each do |key, meta_info| 26: cache_data = [key, meta_info.dup] 27: 28: key = Webgen::Path.make_absolute(path.parent_path, key) + (key =~ /\/$/ ? '/' : '') 29: temp_parent = create_directories(File.dirname(key), path) 30: 31: output_path = meta_info.delete('url') || key 32: output_path = (URI::parse(output_path).absolute? || output_path =~ /^\// ? 33: output_path : File.join(temp_parent.alcn, output_path)) 34: 35: if key =~ /\/$/ 36: nodes << create_directory(key, path, meta_info) 37: else 38: nodes += website.blackboard.invoke(:create_nodes, Webgen::Path.new(key, path.source_path), self) do |cn_path| 39: cn_path.meta_info.update(meta_info) 40: super(cn_path, :output_path => output_path) do |n| 41: n.node_info[:sh_virtual_cache_data] = cache_data 42: end 43: end 44: end 45: end 46: nodes.compact 47: end
Create the needed parent directories for a virtual node.
# File lib/webgen/sourcehandler/virtual.rb, line 71 71: def create_directories(dirname, path) 72: parent = website.tree.root 73: dirname.sub(/^\//, '').split('/').inject('/') do |parent_path, dir| 74: parent_path = File.join(parent_path, dir) 75: parent = create_directory(parent_path, path) 76: parent_path 77: end 78: parent 79: end
Create a virtual directory if it does not already exist.
# File lib/webgen/sourcehandler/virtual.rb, line 82 82: def create_directory(dir, path, meta_info = nil) 83: dir_handler = website.cache.instance('Webgen::SourceHandler::Directory') 84: parent = website.tree.root 85: website.blackboard.invoke(:create_nodes, 86: Webgen::Path.new(File.join(dir, '/'), path.source_path), 87: dir_handler) do |temp_path| 88: parent = dir_handler.node_exists?(temp_path) 89: if (parent && (parent.node_info[:src] == path.source_path) && !meta_info.nil?) || 90: !parent 91: temp_path.meta_info.update(meta_info) if meta_info 92: parent.flag(:reinit) if parent 93: parent = dir_handler.create_node(temp_path) 94: end 95: parent 96: end 97: parent 98: end
Check if the node is virtual and if, if its meta information has changed. This can only be the case if the node has been recreated in this run.
# File lib/webgen/sourcehandler/virtual.rb, line 102 102: def node_meta_info_changed?(node) 103: path = website.blackboard.invoke(:source_paths)[node.node_info[:src]] 104: return if node.node_info[:processor] != self.class.name || (path && !path.changed?) 105: 106: if !path 107: node.flag(:dirty_meta_info) 108: else 109: old_data = node.node_info[:sh_virtual_cache_data] 110: new_data = read_data(path).find {|key, mi| key == old_data.first} 111: node.flag(:dirty_meta_info) if !new_data || old_data.last != new_data.last 112: end 113: end
Read the entries from the virtual file data and yield the path, and the meta info hash for each entry. The parent parameter is used for making absolute path values if relative ones are given.
# File lib/webgen/sourcehandler/virtual.rb, line 56 56: def read_data(path) 57: if !@path_data.has_key?(path) || path.changed? 58: page = page_from_path(path) 59: @path_data[path] = YAML::load(page.blocks['content'].content).collect do |key, meta_info| 60: meta_info ||= {} 61: meta_info['modified_at'] = path.meta_info['modified_at'] 62: meta_info['no_output'] = true 63: [key, meta_info] 64: end if page.blocks.has_key?('content') 65: @path_data[path] ||= [] 66: end 67: @path_data[path] 68: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.