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 Nodes#ref_node, Nodes#content_node and 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
72 def initialize(website, options = {}, persistent = {})
73   @website = website
74   (website.ext.context_modules || []).each {|m| self.extend(m)}
75   @options = {:content => '', :chain => []}.merge(options)
76   @persistent = persistent
77 end

Public Instance Methods

[](name) click to toggle source

Return the value of the option name.

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

Set the option name to the given +value.

   # File lib/webgen/context.rb
93 def []=(name, value)
94   @options[name] = value
95 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
83 def clone(options = {})
84   self.class.new(@website, @options.merge(options), @persistent)
85 end
content() click to toggle source

Return the :content option.

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

Set the :content option to the given value.

    # File lib/webgen/context.rb
103 def content=(value)
104   @options[:content] = value
105 end