Class: Webgen::PathHandler::Virtual

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

Overview

Handles files which contain specifications for “virtual” nodes, ie. nodes that don’t have real source paths.

This can be used, for example, to provide multiple links to the same node or links to external URLs.

Constant Summary

Constants included from Base

Base::DEST_PATH_PARENT_SEGMENTS, Base::DEST_PATH_SEGMENTS

Instance Method Summary collapse

Methods included from PageUtils

#create_node, #parse_meta_info!

Methods included from Base

#initialize, #parse_meta_info!

Instance Method Details

#create_nodes(path, blocks) ⇒ Object

Create all virtual nodes which are specified in path.



22
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
49
50
51
52
53
54
55
56
57
# File 'lib/webgen/path_handler/virtual.rb', line 22

def create_nodes(path, blocks)
  if path.meta_info.delete(:virtual)
    create_node(path)
  else
    read_entries(blocks) do |key, meta_info|
      meta_info['modified_at'] = path.meta_info['modified_at']
      meta_info['no_output'] = true

      key = Webgen::Path.append(path.parent_path, key)
      parent_path = create_directories(File.dirname(key), 'modified_at' => meta_info['modified_at'])

      dest_path = meta_info.delete('dest_path') || key
      dest_path = if Webgen::Path.absolute?(dest_path)
                    dest_path
                  elsif dest_path =~ /^\//
                    "webgen:#{dest_path}"
                  else
                    "webgen:#{File.join(parent_path, dest_path)}"
                  end
      meta_info['dest_path'] = dest_path
      entry_path = Webgen::Path.new(key, meta_info)

      if key =~ /\/$/
        entry_path['handler'] = 'directory'
        @website.ext.path_handler.create_secondary_nodes(entry_path)
      else
        entry_path[:virtual] = true
        entry_path['handler'] = 'virtual'
        entry_path['node_class'] ||= Webgen::PathHandler::Base::Node.to_s
        @website.ext.path_handler.create_secondary_nodes(entry_path)
      end
    end

    nil
  end
end