Class: Webgen::SourceHandler::Virtual

Inherits:
Object
  • Object
show all
Includes:
Base, WebsiteAccess
Defined in:
lib/webgen/sourcehandler/virtual.rb

Overview

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.

Instance Method Summary collapse

Methods included from WebsiteAccess

included, website

Methods included from Base

#content, #node_exists?, #output_path, #page_from_path

Methods included from Base::OutputPathHelpers

#standard_output_path

Methods included from Loggable

#log, #puts

Constructor Details

#initializeVirtual

:nodoc:



17
18
19
20
# File 'lib/webgen/sourcehandler/virtual.rb', line 17

def initialize # :nodoc:
  website.blackboard.add_listener(:node_meta_info_changed?, method(:node_meta_info_changed?))
  @path_data = {}
end

Instance Method Details

#create_node(parent, path) ⇒ Object

Create all virtual nodes under parent which are specified in path.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/webgen/sourcehandler/virtual.rb', line 23

def create_node(parent, path)
  nodes = []
  read_data(path).each do |key, meta_info|
    cache_data = [key, meta_info.dup]

    key = Webgen::Common.absolute_path(key, parent.absolute_lcn) + (key =~ /\/$/ ? '/' : '')
    temp_parent = create_directories(parent.tree.root, File.dirname(key), path)

    output_path = meta_info.delete('url') || key
    output_path = (URI::parse(output_path).absolute? || output_path =~ /^\// ?
                   output_path : File.join(temp_parent.absolute_lcn, output_path))

    if key =~ /\/$/
      nodes << create_directory(temp_parent, key, path, meta_info)
    else
      nodes += website.blackboard.invoke(:create_nodes, parent.tree, temp_parent.absolute_lcn,
                                         Webgen::Path.new(key, path.source_path), self) do |cn_parent, cn_path|
        cn_path.meta_info.update(meta_info)
        super(cn_parent, cn_path, output_path) do |n|
          n.node_info[:sh_virtual_cache_data] = cache_data
        end
      end
    end
  end
  nodes.compact
end