Class: Webgen::ContentProcessor::Tags
- Inherits:
-
Object
- Object
- Webgen::ContentProcessor::Tags
- Includes:
- Loggable, WebsiteAccess
- Defined in:
- lib/webgen/contentprocessor/tags.rb
Overview
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.
Defined Under Namespace
Classes: ProcessingStruct
Constant Summary
- BRACKETS_RE =
/([{}])/
Instance Method Summary (collapse)
-
- (Object) call(context)
Replace all webgen tags in the content of context with the rendered content.
-
- (Tags) initialize
constructor
:nodoc:.
-
- (Object) process_tag(tag, params, body, context)
Process the tag and return the result.
Methods included from Loggable
Methods included from WebsiteAccess
Constructor Details
- (Tags) initialize
:nodoc:
18 19 20 21 |
# File 'lib/webgen/contentprocessor/tags.rb', line 18 def initialize #:nodoc: @start_re = /(\\*)\{#{website.config['contentprocessor.tags.prefix']}(\w+)(::?)/ @end_re = /(\\*)\{#{website.config['contentprocessor.tags.prefix']}(\w+)\}/ end |
Instance Method Details
- (Object) call(context)
Replace all webgen tags in the content of context with the rendered content.
24 25 26 27 28 29 30 |
# File 'lib/webgen/contentprocessor/tags.rb', line 24 def call(context) (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 |
- (Object) process_tag(tag, params, body, context)
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.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/webgen/contentprocessor/tags.rb', line 35 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 |