Object
Processes special webgen tags to provide dynamic content.
webgen tags are an easy way to add dynamically generated content to websites, for example menus or breadcrumb trails.
Replace all webgen tags in the content of context with the rendered content.
# File lib/webgen/contentprocessor/tags.rb, line 23 def call(context) replace_tags(context) do |tag, param_string, body| log(:debug) { "Replacing tag #{tag} with data '#{param_string}' and body '#{body}' in <#{context.ref_node}>" } process_tag(tag, param_string, body, context) end context end
Process the tag and return the result. The parameter params needs to be a Hash holding all needed and optional parameters for the tag or a parameter String in YAML format and body is the optional body for the tag. context needs to be a valid Webgen::Context object.
# File lib/webgen/contentprocessor/tags.rb, line 34 def process_tag(tag, params, body, context) result = '' processor = processor_for_tag(tag) if !processor.nil? params = if params.kind_of?(String) processor.create_tag_params(params, context.ref_node) else processor.create_params_hash(params, context.ref_node) end processor.set_params(params) result, process_output = processor.call(tag, body, context) processor.set_params(nil) result = call(context.clone(:content => result)).content if process_output else raise Webgen::RenderError.new("No tag processor for '#{tag}' found", self.class.name, context.dest_node, context.ref_node) end result end
Return the tag processor for tag or nil if tag is unknown.
# File lib/webgen/contentprocessor/tags.rb, line 155 def processor_for_tag(tag) map = website.config['contentprocessor.tags.map'] klass = if map.has_key?(tag) map[tag] elsif map.has_key?(:default) map[:default] else nil end klass.nil? ? nil : website.cache.instance(klass) end
Generated with the Darkfish Rdoc Generator 2.