template.rb

Path: rdoc/template.rb
Last Update: Tue Mar 13 02:06:40 -0500 2007

Cheap-n-cheerful HTML page template system. You create a template containing:

  • variable names between percent signs (%fred%)
  • blocks of repeating stuff:
      START:key
        ... stuff
      END:key
    

You feed the code a hash. For simple variables, the values are resolved directly from the hash. For blocks, the hash entry corresponding to key will be an array of hashes. The block will be generated once for each entry. Blocks can be nested arbitrarily deeply.

The template may also contain

  IF:key
    ... stuff
  ENDIF:key

stuff will only be included in the output if the corresponding key is set in the value hash.

Usage: Given a set of templates T1, T2, etc

           values = { "name" => "Dave", state => "TX" }

           t = TemplatePage.new(T1, T2, T3)
           File.open(name, "w") {|f| t.write_html_on(f, values)}
        or
           res = ''
           t.write_html_on(res, values)

[Validate]

ruby-doc.org is hosted and maintained by James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, Arizona. The site was created in 2002 as part of the Ruby Documentation Project to promote the Ruby language and to help other Ruby hackers.

Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.

For more information on the Ruby programming language, visit ruby-lang.org.

Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.