Sha256: f8d74ab1b2b36d94e94ed40de61cc04744d98810250af1690b51d26232692b52

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

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

module Webgen
  class Context

    # Provides quick access to special nodes of the node chain of a context object.
    module Nodes

      # Return the node which represents the file into which everything gets rendered.
      #
      # This is normally the same node as #content_node but can differ in special cases. For
      # example, when rendering the content of node called 'my.page' into the output of the node
      # 'this.page', 'this.page' would be the #dest_node and 'my.page' would be the #content_node.
      #
      # The #dest_node is not included in the chain but can be set via the option +:dest_node+!
      #
      # The returned node should be used as source node for calculating relative paths to other nodes.
      def dest_node
        @options[:dest_node] || self.content_node
      end

      # Return the reference node, ie. the node which provided the original content for this context
      # object.
      #
      # The returned node should be used, for example, for resolving relative paths.
      def ref_node
        @options[:chain] && @options[:chain].first
      end

      # Return the node that is ultimately rendered.
      #
      # This node should be used, for example, for retrieving meta information.
      def content_node
        @options[:chain] && @options[:chain].last
      end
      alias :node :content_node

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
webgen-1.2.0 lib/webgen/context/nodes.rb
webgen-1.1.0 lib/webgen/context/nodes.rb
webgen-1.0.0 lib/webgen/context/nodes.rb
webgen-1.0.0.beta3 lib/webgen/context/nodes.rb
webgen-1.0.0.beta2 lib/webgen/context/nodes.rb
webgen-1.0.0.beta1 lib/webgen/context/nodes.rb