Class Webgen::SourceHandler::Virtual
In: lib/webgen/sourcehandler/virtual.rb
Parent: Object
Error RenderError CommandNotFoundError LoadError NodeCreationError ::Rake::TaskLib WebgenTask Helpers Configuration Node Context\n[lib/webgen/context.rb\nlib/webgen/context/nodes.rb\nlib/webgen/context/render.rb\nlib/webgen/context/tags.rb] Tree FileSystem Sitemap Copy Feed Virtual Sitemap Directory Page Fragment Template Metainfo Memory Coderay Sitemap IncludeFile BreadcrumbTrail Langbar TikZ Menu Tags Fragments Resource Website Tidy Head Kramdown Less Xmllint Blocks Comparable Language Path StandardError CmdParse::CommandParser CommandParser CmdParse::Command RunCommand WebguiCommand CreateCommand ApplyCommand WebsiteAccess Main Loggable OutputPathHelpers ExecuteCommand Link Date Relocatable Metainfo ::Kramdown::Converter::Html KramdownHtmlConverter Cache Blackboard WebsiteManager Logger Page ProxyNode Utils Scss RDoc Sass Erb RDiscount Erubis Haml Maruku Builder RedCloth AccessHash TarArchive Stacked FileSystem lib/webgen/cache.rb lib/webgen/error.rb lib/webgen/languages.rb lib/webgen/context/render.rb lib/webgen/website.rb lib/webgen/blackboard.rb lib/webgen/tree.rb lib/webgen/websitemanager.rb lib/webgen/logger.rb lib/webgen/configuration.rb lib/webgen/path.rb lib/webgen/webgentask.rb lib/webgen/page.rb lib/webgen/node.rb ClassMethods WebsiteAccess lib/webgen/cli/run_command.rb lib/webgen/cli/utils.rb lib/webgen/cli/apply_command.rb lib/webgen/cli/webgui_command.rb lib/webgen/cli.rb lib/webgen/cli/create_command.rb Color CLI LanguageManager lib/webgen/output/filesystem.rb Output lib/webgen/common/sitemap.rb Common lib/webgen/sourcehandler/memory.rb lib/webgen/sourcehandler/metainfo.rb lib/webgen/sourcehandler/copy.rb lib/webgen/sourcehandler/directory.rb lib/webgen/sourcehandler.rb lib/webgen/sourcehandler/page.rb lib/webgen/sourcehandler/template.rb lib/webgen/sourcehandler/fragment.rb lib/webgen/sourcehandler/sitemap.rb lib/webgen/sourcehandler/virtual.rb lib/webgen/sourcehandler/feed.rb OutputPathHelpers Base SourceHandler lib/webgen/tag/coderay.rb lib/webgen/tag/relocatable.rb lib/webgen/tag/menu.rb lib/webgen/tag/langbar.rb lib/webgen/tag/executecommand.rb lib/webgen/tag/breadcrumbtrail.rb lib/webgen/tag/metainfo.rb lib/webgen/tag/includefile.rb lib/webgen/tag/link.rb lib/webgen/tag/date.rb lib/webgen/tag/tikz.rb lib/webgen/tag/sitemap.rb Base Tag lib/webgen/contentprocessor/less.rb lib/webgen/contentprocessor/scss.rb lib/webgen/contentprocessor/blocks.rb lib/webgen/contentprocessor/rdoc.rb lib/webgen/contentprocessor/sass.rb lib/webgen/contentprocessor/erb.rb lib/webgen/contentprocessor/rdiscount.rb lib/webgen/contentprocessor/tags.rb lib/webgen/contentprocessor/erubis.rb lib/webgen/contentprocessor/kramdown/html.rb lib/webgen/contentprocessor/haml.rb lib/webgen/contentprocessor/maruku.rb lib/webgen/contentprocessor/xmllint.rb lib/webgen/contentprocessor/kramdown.rb lib/webgen/contentprocessor/head.rb lib/webgen/contentprocessor/builder.rb lib/webgen/contentprocessor/tidy.rb lib/webgen/contentprocessor/redcloth.rb lib/webgen/contentprocessor/fragments.rb lib/webgen/contentprocessor.rb ContentProcessor lib/webgen/source/tararchive.rb lib/webgen/source/stacked.rb lib/webgen/source/resource.rb lib/webgen/source/filesystem.rb Source Loggable Webgen dot/m_82_0.png

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.

Methods

Included Modules

Base Webgen::WebsiteAccess

Public Instance methods

Create all virtual nodes which are specified in path.

[Source]

    # 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

Private Instance methods

Create the needed parent directories for a virtual node.

[Source]

    # 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.

[Source]

    # 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.

[Source]

     # 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.

[Source]

    # 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

[Validate]