Sha256: e4b0e75ebdb775a9034983a89cce1c334683bca81a10682be94f576195a076e8

Contents?: true

Size: 1.38 KB

Versions: 10

Compression:

Stored size: 1.38 KB

Contents

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

module Webgen::SourceHandler

  # This source handler should be used for handling nodes that are created during the write
  # phase.
  class Memory

    include Webgen::WebsiteAccess
    include Base

    def initialize #:nodoc:
      website.blackboard.add_listener(:node_flagged) do |node, *flags|
        node.tree[node.node_info[:memory_source_alcn]].flag(:dirty) if node.node_info[:memory_source_alcn]
      end
    end

    # Create a node for the +path+. The +source_alcn+ specifies the node that creates this memory
    # node when written. You have two options for providing the content for this node: either you
    # set +data+ to a string (or a Webgen::Path::SourceIO object) or you provide a block which takes
    # the created node as argument and returns a string (or a Webgen::Path::SourceIO object).
    def create_node(path, source_alcn, data = nil)
      super(path) do |node|
        node.node_info[:memory_source_alcn] = source_alcn
        (@data ||= {})[node.alcn] = lambda { data || yield(node) }
      end
    end

    # Return the content of the memory +node+. If the memory node was not created in this webgen
    # run, it will be flagged for reinitialization (and therefore recreation).
    def content(node)
      if @data && @data[node.alcn]
        @data[node.alcn].call
      else
        node.flag(:reinit)
        nil
      end
    end

  end

end

Version data entries

10 entries across 10 versions & 2 rubygems

Version Path
gettalong-webgen-0.5.9.20090620 lib/webgen/sourcehandler/memory.rb
gettalong-webgen-0.5.9.20090626 lib/webgen/sourcehandler/memory.rb
webgen-0.5.17 lib/webgen/sourcehandler/memory.rb
webgen-0.5.15 lib/webgen/sourcehandler/memory.rb
webgen-0.5.14 lib/webgen/sourcehandler/memory.rb
webgen-0.5.13 lib/webgen/sourcehandler/memory.rb
webgen-0.5.12 lib/webgen/sourcehandler/memory.rb
webgen-0.5.11 lib/webgen/sourcehandler/memory.rb
webgen-0.5.10 lib/webgen/sourcehandler/memory.rb
webgen-0.5.9 lib/webgen/sourcehandler/memory.rb