.\" DO NOT MODIFY THIS FILE! it was generated by rd2 .TH HTML::Template 3ruby "June 2002" .SH NAME HTML::Template \- Ruby extension for HTML::Template .SH DESCRIPTION .PP This module deals with HTML template by CGI scripts and use a complete selectivity between design and logic easily. You can deal with a nested block, a loop and a conditional expression. Simple example, see below. .fi .PP template file test.html .nf \& \& Test Template \& \& My Home Directory is \&

\& My Path is set to \& \& .fi Ruby script .nf \& require "html/template" \& tmpl = HTML::Template.new("./test.html") \& tmpl.param({ \& 'home' => ENV['HOME'], \& 'path' => ENV['PATH'] \& }) \& print "Content\-Type: text/html\\n\\n" \& print tmpl.output .fi .SH INSTALL .PP using install.rb .nf \& % tar xvzf html\-template\-x.xx.tar.gz \& % cd html\-template\-x.xx \& % ruby install.rb config \& % ruby install.rb setup \& % su \& # ruby install.rb install .fi .SH Template File .PP .SH TAGS .PP You can use original style tag or valid HTML comment style tag. .TP .fi .B .TP .fi .B When you call HTML::Template#param ({PARAMETER_NAME => VAL}), tags will be simply replaced to VAL. .TP .fi .B .TP .fi .B .TP .fi .B .TP .fi .B It allows you to separate a section of text and give it a name It would be able to make them loop or conditional expression. And, it can be nested. .TP .fi .B .TP .fi .B A file specified by FILE_NAME is simply inserted to a template file. The template file will be treated as a merged template. If you pass the path param to HTML::Template.new , include file will be searched under the path. .SH HTML::Template CLASS .PP .SH CLASS METHODS .PP .TP .fi .B HTML::Template.new(params = {}) Creates a HTML::Template object. Given a file name to its first argument, use this file as a template. Also you can pass params as Hash. The options are below .TP .B \(bu filename template filename .TP .B \(bu path template search path. you can specified as String or Array of String. .SH METHODS .PP .TP .fi .B HTML::Template#load(file) Load template file. .TP .fi .B HTML::Template#set_html(html) Setting up a string as a template. .TP .fi .B HTML::Template#param(hash = {}) .TP .fi .B HTML::Template#expand(hash = {}) Specifies a string or a loop by Hash for a substitute. When specifying more than a loop simultaneously, value of the hash becomes an array. .TP .fi .B HTML::Template#node(name) .TP .fi .B HTML::Template#loop(name) .TP .fi .B HTML::Template#cond(name) Stands a loop and a conditional expression specified by Retrieves HTML::TemplateNode object. .TP .fi .B HTML::Template#output .TP .fi .B HTML::Template#to_s Returns the final result. .SH HTML::TemplateNode CLASS .PP This is a class for a loop or a conditional expression. An instance consists of HTML::Template Class and HTML::TemplateNode CLASS. .SH METHODS .PP .TP .fi .B HTML::TemplateNode#node(name) Stands a loop or a conditional expression specified by Returns HTML::TemplateNode object. Is only used for nested. .TP .fi .B HTML::TemplateNode#param(hash = {}) .TP .fi .B HTML::TemplateNode#expand(hash = {}) .TP .fi .B HTML::TemplateNode#add(hash = {}) Specifies a string or a loop by Hash for a substitute. If you don't call the method, the block won't be displayed. .SH A LOOP .PP This sample is a displaying list of environment valiables. .nf \& \& \&

Env List

\&
\& \& :
\& \&
\& \& \& \& # In case of using it with iterator and replace data. \& require "html/template" \& tmpl = HTML::Template.new("filename" => "envlist.html") \& ENV.keys.sort.each do |k| \& tmpl.node("envlist").param({'key' => k, \& 'val' => ENV[k] \& }) \& end \& print "Content\-Type: text/html\\n\\n" \& print tmpl.output \& \& # In case of giving a loop as an array \& require "html/template" \& tmpl = HTML::Template.new("envlist.html") \& envlist = [] \& ENV.keys.sort.each do |k| \& envlist.push({'key' => k, \& 'val' => ENV[k] \& }) \& end \& tmpl.param({'envlist' => envlist}) \& print "Content\-Type: text/html\\n\\n" \& print tmpl.output .fi .SH A Conditional Expression .PP .nf \& \& \& \& This is True \& \&
\& \& \& This is False \& \&
\& \& \& \& \& \& require "html/template" \& tmpl = HTML::Template.new("cond.html") \& tmpl.param({'true' => {'foo' => 'foobar'} \& }) \& print "Content\-Type: text/html\\n\\n" \& print tmpl.output .fi The performed result is below, however, a part not specied with the method isn't displayed. .nf \& \& \& \& This is True \& foobar \&
\& \& .fi .SH An attached Sample. .PP .TP .fi .B env.rb This sample is a simply replacing valiables. .TP .fi .B envlist.rb This sample is a displaying list of environment valiables. This sample is a case for using with iterator. .TP .fi .B envlist2.rb Performed result is the same as the envlist.rb.'s. .TP .fi .B nest.rb A sample of a nested loop. .SH THANKS .PP English Documentation NAKAYAMA Nao thanks a lot :\-) .SH AUTHOR .PP Copyright 2001 IKEBE Tomohiro This library is free software; you can redistribute it and / or modify it under the same terms as Ruby itself. IKEBE Tomohiro