Sha256: 0c7da7e588d6f943e45c2ac40242679cd19105ab6b1ef5c08ab2f8116a7a7090

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

# -*- encoding: utf-8 -*-

module Webgen::SourceHandler

  # Simple source handler for copying files from the source tree, either verbatim or by applying a
  # content processor.
  class Copy

    include Webgen::WebsiteAccess
    include Base

    # 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.
    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

    # Return either the preprocessed content of the +node+ or the IO object for the node's source
    # path depending on the node type.
    def content(node)
      io = website.blackboard.invoke(:source_paths)[node.node_info[:src]].io
      if node.node_info[:preprocessor]
        context = Webgen::Context.new(:content => io.data, :chain => [node])
        website.blackboard.invoke(:content_processor, node.node_info[:preprocessor]).call(context)
        context.content
      else
        io
      end
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
gettalong-webgen-0.5.9.20090620 lib/webgen/sourcehandler/copy.rb