Method: Webgen::SourceHandler::Virtual#create_node

Defined in:
lib/webgen/sourcehandler/virtual.rb

#create_node(parent, path) ⇒ Object

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



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/webgen/sourcehandler/virtual.rb', line 18

def create_node(parent, path)
  page = page_from_path(path)
  nodes = []
  YAML::load(page.blocks['content'].content).each do |key, meta_info|
    key = Webgen::Common.absolute_path(key, parent.absolute_lcn) + (key =~ /\/$/ ? '/' : '')
    temp_parent = create_directories(parent.tree.root, File.dirname(key), path)

    meta_info ||= {}
    meta_info['modified_at'] = path.meta_info['modified_at']
    meta_info['no_output'] = true
    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)
      end
    end
  end if page.blocks.has_key?('content')
  nodes.compact
end