Class: Webgen::ContentProcessor::Context
- Inherits:
-
Object
- Object
- Webgen::ContentProcessor::Context
- Includes:
- WebsiteAccess
- Defined in:
- lib/webgen/contentprocessor/context.rb
Overview
The context object that is passed 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 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).
Instance Attribute Summary collapse
-
#options ⇒ Object
Processing options.
Instance Method Summary collapse
-
#[](name) ⇒ Object
Return the value of the option
name. -
#[]=(name, value) ⇒ Object
Set the option
nameto the given +value. -
#clone(options = {}) ⇒ Object
Create a copy of the current object.
-
#content ⇒ Object
Return the
:contentoption. -
#content=(value) ⇒ Object
Set the
:contentoption to the givenvalue. -
#content_node ⇒ Object
Return the node that is ultimately rendered.
-
#dest_node ⇒ Object
Return the node which represents the file into which everything gets rendered.
-
#initialize(options = {}) ⇒ Context
constructor
Create a new Context object.
-
#ref_node ⇒ Object
Return the reference node, ie.
Methods included from WebsiteAccess
Constructor Details
#initialize(options = {}) ⇒ Context
Create a new Context object. You can use the options hash to set needed options. The :content option is set to an empty string if not specified in options and :processors is set to a new AccessHash if not specified in options.
25 26 27 28 29 30 |
# File 'lib/webgen/contentprocessor/context.rb', line 25 def initialize( = {}) = { :content => '', :processors => Webgen::ContentProcessor::AccessHash.new }.merge() end |
Instance Attribute Details
#options ⇒ Object
Processing options
20 21 22 |
# File 'lib/webgen/contentprocessor/context.rb', line 20 def end |
Instance Method Details
#[](name) ⇒ Object
Return the value of the option name.
39 40 41 |
# File 'lib/webgen/contentprocessor/context.rb', line 39 def [](name) [name] end |
#[]=(name, value) ⇒ Object
Set the option name to the given +value.
44 45 46 |
# File 'lib/webgen/contentprocessor/context.rb', line 44 def []=(name, value) [name] = value end |
#clone(options = {}) ⇒ Object
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.
34 35 36 |
# File 'lib/webgen/contentprocessor/context.rb', line 34 def clone( = {}) self.class.new(.merge()) end |
#content ⇒ Object
Return the :content option.
49 50 51 |
# File 'lib/webgen/contentprocessor/context.rb', line 49 def content [:content] end |
#content=(value) ⇒ Object
Set the :content option to the given value.
54 55 56 |
# File 'lib/webgen/contentprocessor/context.rb', line 54 def content=(value) [:content] = value end |
#content_node ⇒ Object
Return the node that is ultimately rendered.
This node should be used, for example, for retrieving meta information.
83 84 85 |
# File 'lib/webgen/contentprocessor/context.rb', line 83 def content_node [:chain] && [:chain].last end |
#dest_node ⇒ Object
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.
68 69 70 |
# File 'lib/webgen/contentprocessor/context.rb', line 68 def dest_node [:dest_node] || self.content_node end |
#ref_node ⇒ Object
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.
76 77 78 |
# File 'lib/webgen/contentprocessor/context.rb', line 76 def ref_node [:chain] && [:chain].first end |