class Webgen::PathHandler::Copy

Simple path handler for copying files from the source to the destination, either without changing anything or by applying one or more content processors.

Public Instance Methods

content(node) click to toggle source

Return the processed content of the node if the pipeline meta info key is specified or the IO object for the node's source path.

   # File lib/webgen/path_handler/copy.rb
36 def content(node)
37   if pipeline = node.meta_info['pipeline']
38     pipeline = @website.ext.content_processor.normalize_pipeline(pipeline)
39     is_binary = @website.ext.content_processor.is_binary?(pipeline.first)
40     context = Webgen::Context.new(@website, :chain => [node],
41                                   :content => node.node_info[:path].data(is_binary ? 'rb' : 'r'))
42     pipeline.each {|processor| @website.ext.content_processor.call(processor, context)}
43     context.content
44   else
45     node.node_info[:path]
46   end
47 end
create_nodes(path) click to toggle source

Create the node for path.

See the user documentation for detailed information about how the content processor pipeline can be specified.

   # File lib/webgen/path_handler/copy.rb
18 def create_nodes(path)
19   if !path.meta_info.has_key?('pipeline')
20     pipeline = []
21     exts = path.ext.split('.')
22     pipeline << exts.shift while exts.length > 1 && @website.ext.content_processor.registered?(exts.first)
23     if (data = @website.ext.content_processor.map_extension(exts.last))
24       pipeline << data.first
25       exts[-1] = data.last
26     end
27     path.meta_info['pipeline'] = pipeline unless pipeline.empty?
28     path.ext = exts.join('.')
29   end
30 
31   create_node(path)
32 end