Documentation - Ruby
Quick start
gem install domtempl
require 'domtempl'
Reading the template
l = DOMtempl.new('path/to/template.html')
or
l = DOMtempl.new('<html><p data-var="foo"></p></html>', DOMtempl::FRAGMENT);
Reading variables defined/expected by template
l = DOMtempl.new('<html><p data-var="foo">Boo</p></html>', DOMtempl::FRAGMENT);
print l.vars
#{'foo' : 'Boo'}
Writing variables
l.assign("foo", "Hello world")
You can also assign variables by accessing the vars public property,
l.vars['foo'] = "Hello world"
has the same effect.
Writing output
l.out()
which is a shorthand for
html = l.dump()
print html
Writing XML output
print l.dumpXML();
#or
l.outXML()
Same as above, but produces XML instead of HTML.
Complete example
require 'domtempl'
l = DOMtempl.new('<html><p data-var="animal">cat</p></html>', DOMtempl::FRAGMENT);
print l.vars
#{'animal' : 'cat'}
l.assign("animal", "dog")
l.out()
#<html><p>dog</p></html>