Class | Webgen::Context |
In: |
lib/webgen/context.rb
lib/webgen/context/render.rb lib/webgen/context/nodes.rb lib/webgen/context/tags.rb |
Parent: | Object |
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:
The persistent options hash is shared by all cloned Context objects.
options | [RW] | Processing options. |
persistent | [R] | The persistent options. Once initialized, all cloned objects refer to the same hash. |
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:
# File lib/webgen/context.rb, line 46 46: def initialize(options = {}, persistent = {}) 47: @options = { 48: :content => '', 49: :processors => Webgen::ContentProcessor::AccessHash.new 50: }.merge(options) 51: @persistent = persistent 52: end
Return the value of the option name.
# File lib/webgen/context.rb, line 61 61: def [](name) 62: @options[name] 63: end
Set the option name to the given +value.
# File lib/webgen/context.rb, line 66 66: def []=(name, value) 67: @options[name] = value 68: end
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 14: def dest_node 15: @options[:dest_node] || self.content_node 16: end
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:
# File lib/webgen/context/render.rb, line 25 25: def render_block(name_or_hash) 26: name_or_hash = {:name => name_or_hash} if name_or_hash.kind_of?(String) 27: website.cache.instance('Webgen::ContentProcessor::Blocks').render_block(self, name_or_hash) 28: end
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 14: def tag(name, params = {}, body = '') 15: website.cache.instance('Webgen::ContentProcessor::Tags').process_tag(name, params, body, self) 16: end