Class: Webgen::SourceHandler::Directory

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

Overview

Handles directory source paths.

Instance Method Summary collapse

Methods included from WebsiteAccess

included, website

Methods included from Base

#create_node, #node_exists?, #output_path, #page_from_path

Methods included from Base::OutputPathHelpers

#standard_output_path

Methods included from Loggable

#log, #puts

Constructor Details

#initializeDirectory

:nodoc:



11
12
13
# File 'lib/webgen/sourcehandler/directory.rb', line 11

def initialize # :nodoc:
  website.blackboard.add_service(:create_directories, method(:create_directories))
end

Instance Method Details

#content(node) ⇒ Object

Return an empty string to signal that the directory should be written to the output.



30
31
32
# File 'lib/webgen/sourcehandler/directory.rb', line 30

def content(node)
  ''
end

#create_directories(parent, dirname, path) ⇒ Object

Recursively create the directories specified in dirname under parent (a leading slash is ignored). The path path is the path that lead to the creation of these directories.



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/webgen/sourcehandler/directory.rb', line 17

def create_directories(parent, dirname, path)
  dirname.sub(/^\//, '').split('/').each do |dir|
    dir_path = Webgen::Path.new(File.join(parent.absolute_lcn, dir, '/'), path)
    nodes = website.blackboard.invoke(:create_nodes, parent.tree, parent.absolute_lcn,
                                       dir_path, self) do |dir_parent, dir_path|
      node_exists?(dir_parent, dir_path) || create_node(dir_parent, dir_path)
    end
    parent = nodes.first
  end
  parent
end