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, #parent_node

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(path) ⇒ Object

Create all virtual nodes 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
# File 'lib/webgen/sourcehandler/virtual.rb', line 23

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

    key = Webgen::Path.make_absolute(path.parent_path, key) + (key =~ /\/$/ ? '/' : '')
    temp_parent = create_directories(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.alcn, output_path))

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