Parent

Included Modules

Class/Module Index [+]

Quicksearch

Webgen::Context

This class represents the context object that is passed, for example, to the call method of a content processor.

The needed context variables are stored in the options hash. You can set any options you like, however, there are three noteworthy options:

:content

The content string that should be processed.

:processors

Normally an ContentProcessor::AccessHash object providing access to all available content processors.

:chain

The chain of nodes that is processed. There are some utiltity methods for getting special nodes of the chain (see ref_node, content_node and dest_node).

The persistent options hash is shared by all cloned Context objects.

Attributes

options[RW]

Processing options.

persistent[R]

The persistent options. Once initialized, all cloned objects refer to the same hash.

Public Class Methods

new(options = {}, persistent = {}) click to toggle source

Create a new Context object. You can use the options hash to set needed options.

The following options are set by default and can be overridden via the options hash:

:content

Is set to an empty string.

:processors

Is set to a new AccessHash.

# File lib/webgen/context.rb, line 45
def initialize(options = {}, persistent = {})
  @options = {
    :content => '',
    :processors => Webgen::ContentProcessor::AccessHash.new
  }.merge(options)
  @persistent = persistent
end

Public Instance Methods

[](name) click to toggle source

Return the value of the option name.

# File lib/webgen/context.rb, line 60
def [](name)
  @options[name]
end
[]=(name, value) click to toggle source

Set the option name to the given +value.

# File lib/webgen/context.rb, line 65
def []=(name, value)
  @options[name] = value
end
clone(options = {}) click to toggle source

Create a copy of the current object. You can use the options parameter to override options of the current Context object in the newly created Context object.

# File lib/webgen/context.rb, line 55
def clone(options = {})
  self.class.new(@options.merge(options), @persistent)
end
content() click to toggle source

Return the :content option.

# File lib/webgen/context.rb, line 70
def content
  @options[:content]
end
content=(value) click to toggle source

Set the :content option to the given value.

# File lib/webgen/context.rb, line 75
def content=(value)
  @options[:content] = value
end
content_node() click to toggle source

Return the node that is ultimately rendered.

This node should be used, for example, for retrieving meta information.

# File lib/webgen/context/nodes.rb, line 29
def content_node
  @options[:chain] && @options[:chain].last
end
Also aliased as: node
dest_node() click to toggle source

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.

# File lib/webgen/context/nodes.rb, line 14
def dest_node
  @options[:dest_node] || self.content_node
end
node() click to toggle source
Alias for: content_node
ref_node() click to toggle source

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.

# File lib/webgen/context/nodes.rb, line 22
def ref_node
  @options[:chain] && @options[:chain].first
end
render_block(block_name)
click to toggle source
render_block(:name => block_name, :option => value, ...)

Render the named block and return the result.

This method uses the functionality of the content processor blocks for doing the actual work, so you may also want to look at Webgen::ContentProcessor::Blocks#render_block. You can call this method in two ways:

#render_block(block_name)

Renders the block named block_name of the next node in the current node chain. This is the version that most want to use since it is equivalent to the use of <webgen:block name="block_name" />. It is equivalent to #render_block(:name => block_name).

#render_block(opts_hash)

This version allows the same level of control over the output as the blocks content processor. For a list of valid options have a look at the documentation of the Webgen::ContentProcessor::Blocks#render_block method!

# File lib/webgen/context/render.rb, line 25
def render_block(name_or_hash)
  name_or_hash = {:name => name_or_hash} if name_or_hash.kind_of?(String)
  website.cache.instance('Webgen::ContentProcessor::Blocks').render_block(self, name_or_hash)
end
tag(name, params = {}, body = '') click to toggle source

Returns the result of evaluating the webgen tag name with the tag parameters params and the body in the current context.

Have a look at Webgen::Tag::Base for more information about webgen tags!

This method is useful when you want to have the functionality of webgen tags available but you don't want to use the content processor for them. Or, for example, if the used markup language uses a similar markup as webgen tags do and therefore you can't use the normal webgen tags content processor.

# File lib/webgen/context/tags.rb, line 14
def tag(name, params = {}, body = '')
  website.cache.instance('Webgen::ContentProcessor::Tags').process_tag(name, params, body, self)
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.