require 'tempura/template' ## Template template_html = <
nameauthor
(will be replaced with a name of each item) (will be replaced with an author of each item)
name: author:
END_OF_TEMPLATE_HTML ## Model class Item attr_reader :name, :author def initialize(name, author) @name = name @author = author end end class ItemContainer attr_reader :items def initialize @items = [] end def add(name, author) @items << Item.new(name, author) end end ## Real Data data = ItemContainer.new data.add("Ruby", "matz") data.add("Perl", "Larry Wall") data.add("Python", "Guido") ## Expand tmpl = Tempura::Template.new_with_string(template_html) tmpl.default_action = "myapp.cgi" ## Print result puts tmpl.expand(data) __END__ # Result
nameauthor
Ruby matz
Perl Larry Wall
Python Guido
name: author: