class Webgen::Context

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

About ↑

A context object provides information about the render context as well as access to the website that is rendered. The needed context variables are stored in the options hash. You can set any options you like, however, there are two noteworthy options:

:content

The content string that should be processed. This option is always set.

:chain

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

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

Adding custom methods ↑

If you want to add custom methods to each context object of your website that is created, you just need to define one or more modules in which your custom methods are defined and then add the modules to the 'website.ext.context_modules' array.

Here is a simple example:

module MyContextMethods

  def my_method
    # do something useful here
  end

end

website.ext.context_modules << MyContextMethods

Attributes

options[R]

Processing options.

persistent[R]

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

website[R]

The website object to which the render context belongs.

Public Class Methods

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

Create a new Context object belonging to the website object website.

All modules listed in the array 'website.ext.context_modules' are automatically used to extend the Context object.

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

:content

Is set to an empty string.

# File lib/webgen/context.rb, line 72
def initialize(website, options = {}, persistent = {})
  @website = website
  (website.ext.context_modules || []).each {|m| self.extend(m)}
  @options = {:content => '', :chain => []}.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 88
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 93
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 83
def clone(options = {})
  self.class.new(@website, @options.merge(options), @persistent)
end
content() click to toggle source

Return the :content option.

# File lib/webgen/context.rb, line 98
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 103
def content=(value)
  @options[:content] = value
end