Class: Webgen::SourceHandler::Copy
- Inherits:
-
Object
- Object
- Webgen::SourceHandler::Copy
- Includes:
- Base, WebsiteAccess
- Defined in:
- lib/webgen/sourcehandler/copy.rb
Overview
Simple source handler for copying files from the source tree, either verbatim or by applying a content processor.
Instance Method Summary collapse
-
#content(node) ⇒ Object
Return either the preprocessed content of the
node
or the IO object for the node’s source path depending on the node type. -
#create_node(path) ⇒ Object
Create the node for
path
.
Methods included from Base
#node_exists?, #output_path, #page_from_path, #parent_node
Methods included from Base::OutputPathHelpers
Methods included from Loggable
Methods included from WebsiteAccess
Instance Method Details
#content(node) ⇒ Object
Return either the preprocessed content of the node
or the IO object for the node’s source path depending on the node type.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/webgen/sourcehandler/copy.rb', line 30 def content(node) io = website.blackboard.invoke(:source_paths)[node.node_info[:src]].io if node.node_info[:preprocessor] is_binary = website.blackboard.invoke(:content_processor_binary?, node.node_info[:preprocessor]) context = Webgen::Context.new(:content => io.data(is_binary ? 'rb' : 'r'), :chain => [node]) website.blackboard.invoke(:content_processor, node.node_info[:preprocessor]).call(context) context.content else io end end |
#create_node(path) ⇒ Object
Create the node for path
. If the path
has the name of a content processor as the first part in the extension, it is preprocessed.
14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/webgen/sourcehandler/copy.rb', line 14 def create_node(path) if path.ext.index('.') processor, *rest = path.ext.split('.') if website.blackboard.invoke(:content_processor_names).include?(processor) path.ext = rest.join('.') else processor = nil end end super(path) do |node| node.node_info[:preprocessor] = processor end end |