Class: Webgen::ContentProcessor::Tags

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Loggable

#log, #puts

Methods included from WebsiteAccess

included, website

Constructor Details

#initializeTags

: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

#call(context) ⇒ Object

Replace all webgen tags in the content of context with the rendered content.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/webgen/contentprocessor/tags.rb', line 24

def call(context)
  replace_tags(context.content, context.ref_node) do |tag, param_string, body|
    log(:debug) { "Replacing tag #{tag} with data '#{param_string}' and body '#{body}' in <#{context.ref_node.absolute_lcn}>" }

    result = ''
    processor = processor_for_tag(tag)
    if !processor.nil?
      processor.set_params(processor.create_tag_params(param_string, context.ref_node))
      result, process_output = processor.call(tag, body, context)
      processor.set_params(nil)

      result = call(context.clone(:content => result)).content if process_output
    end

    result
  end
  context
end