Class: Fabulator::Template::Parser

Inherits:
Object
  • Object
show all
Includes:
StandardTags, Taggable
Defined in:
lib/fabulator/template/parser.rb

Instance Method Summary collapse

Methods included from Taggable

included, last_description, last_description=, #render_tag, tag_descriptions, #tag_descriptions, #tags

Instance Method Details

#parse(context, text) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/fabulator/template/parser.rb', line 6

def parse(context, text)
  if !@context
    @context = Context.new(self)
  end
  if !@parser
    @parser = Radius::Parser.new(@context, :tag_prefix => 'r')
  end
  @context.globals.context = context

  # N.B.: these substitutions work around a bug in Radius that shows
  #       up when working with XML+namespaces

  text.gsub!(/&/, '&')
  text.gsub!(/<\//, '&lt;/')
  text.gsub!(/&lt;\/r:/, '</r:')

  r = @parser.parse(text)

  r.gsub!(/&lt;\//, '</')
  r.gsub!(/&amp;/, '&')

  begin
    Fabulator::Template::ParseResult.new(r)
  rescue => e
    "<!-- unable to parse XML: #{e} -->" + r
  end
end