SourceForge Logo

ruby-tmpl: Reference

Code Examples - Download - FAQ - Home - Lists - Reference - Summary - ViewCVS

Ruby Reference

Tag Reference


Template#set_obj(key, obj)

Description Used to specify the name and object that are to be used by the <?tmpl.obj?> tag.
Availability0.2.4 and higher
ExamplesSee the examples section.
^^ Top ^^

Template#to_s()

DescriptionWill compile and munge the output of the template and will return a copy of the string to the caller.
Availability0.2.3 and higher
Examplesr.print(tmpl)
puts tmpl.to_s
^^ Top ^^

<?tmpl.docroot_include ?>

Attributes
AttributeValue/Description
orderDetermines whether or not the included file should be prepended or appended to the previous result. Valid attributes are append(default) and prepend.
spacerString to use when appending or prepending the file to the result. Default is a breaking space character.
Availability0.2.0 and higher
Description<?tmpl.docroot_include ?> is used to create a dynamic string based on the repeated inclusion of multiple files with the same name, but in different directories. Files are included from the deepest path back to the document_root. This tag is often used to create title's bread crumbs, or navigational elements.
NotesAll attributes and behaviors that are valid with the <?tmpl.file ?> tag are inherited with <?tmpl.docroot_include ?>.

Examples:

In template file:
<?tmpl.docroot_include name="breadcrumb.tmpl" spacer=" " ?>
<?tmpl.docroot_include name="title.tmpl" error_msg="&nbsp;" spacer=' - ' order='prepend' ?>

In script:
N/A

^^ Top ^^

<?tmpl.env ?>

Attributes
AttributeValue/Description
nameName of the ENV variable
defaultIf name is not a valid ENV key, the value of default will be used instead.
Availability0.2.0 and higher
Description<?tmpl.env ?> is used to print out information in the scripts ENV hash.
NotesThis is case sensitive.
If you would like to get a list of all of the ENV variables, try using something similar to:
ENV.each_key { |key| r.print("#{key} #{ENV[key]}<br>") } in a mod_ruby script.

Example:

In template file:
<?tmpl.env name="HTTP_USER_AGENT" ?>
<?tmpl.env name="USER" ?>

In script:
N/A

^^ Top ^^

<?tmpl.file ?>

Attributes
AttributeValue/Description
error_msgThe text to return to the client in the event that the file isn't found. An empty string or non-breaking space character is a valid and effective way to quell the default error message.
nameName of the file to be included
nsName space that future variables will be called within
relativeIf the relative attribute is omitted or set to no, then the ruby-tmpl engine will include the file relative to the request's DOCROOT or script's path (i.e. not the templating directory).
Availability0.1 and higher
Description<?tmpl.file ?> is used to include other files.
NotesAll files that are included will be parsed by ruby-tmpl. Recursive file and variable includes are permitted. See ?<tmpl.var?> and the test output for more information on name spaces.

Examples:

In template file:
<?tmpl.file name="data.txt" ?>
<?tmpl.file name=".header.tmpl" error_msg="&nbsp;" ?>
<?tmpl.file name="dumped_database_info.html" error_msg="Unavailable" ?>
<?tmpl.file name="widget.tmpl" ns="login"?>

In script:
N/A

^^ Top ^^

<?tmpl.http_headers_in ?>

Attributes
AttributeValue/Description
nameName of the HTTP Header that was sent by the client.
defaultIf name is not a header sent by the client, the value of default will be used instead.
Availability0.2.0 and higher
Description<?tmpl.http_headers_in ?> is used to include HTTP headers that were sent in by the client.
NotesNone

Example:

In template file:
<?tmpl.http_headers_in name="host" ?>

In script:
N/A

^^ Top ^^

<?tmpl.http_headers_out ?>

Attributes
AttributeValue/Description
nameName of the HTTP Header that was sent by the server.
defaultIf name is not a header sent by the server, the value of default will be used instead.
Availability0.2.0 and higher
Description<?tmpl.http_headers_out ?> is used to include HTTP headers that were sent in by the client.
NotesNone

Example:

In template file:
<?tmpl.http_headers_out name="content-type" ?>

In script:
N/A

^^ Top ^^

<?tmpl.obj ?>

Availability0.2.4 and higher
Attributes
AttributeValue/Description
nameName of the object in the template. The object is assigned in the Ruby script with the Template#set_obj() method.
Description<?tmpl.obj ?> is used to include objects that respond to the Template#to_html() method.
NotesRecursive substitution is possible. <tmpl.obj> supports name spaces. See <?tmpl.file?> and test output for more details on name spaces.

Example:

In template file:
<?tmpl.obj name="table"?>
<?tmpl.var name="color" ns="top"?> (in file w/ name space top)

In script (table1 needs to respond to the to_html() method. See the the examples for a full example):
tmpl.set('my table', table1)

^^ Top ^^

<?tmpl.path ?>

Availability0.2.1 and higher
Attributes
AttributeValue/Description
clearIf a path is being set and clear is set to a value other than no, then the path will be cleared before the new path is set. If clear is omitted or set to no then the path value will be appended.
pathA string specifying the path to be used to search for files. If you wish to pass multiple directories, simply use a colon character (:) to delimit the directories.
showIf show is set to a value other than no, then ruby-tmpl will print out the path. Multiple entires are delimited with the spacer character. This tag will show the resulting path after the path has been modified.
spacerIf there are multiple directories in the path, this string will be used to separate the result. Default is set to the colon character :.
Description<?tmpl.path ?> is used to set or show ruby-tmpl's path. The path is used when determining what directories to search in for including files.
NotesRecursive substitution is possible.

Example:

In template file:
<?tmpl.path show="true" path="/www" ?>
<?tmpl.path path="/www/tmpl:../tmpl" clear="yes" show="true" ?>

In script:
tmpl.path = '/www/tmpl:./tmpl'
tmpl.path = '/www/tmpl'
tmpl.path_append = '/www/data/host.example.com/tmpl'

^^ Top ^^

<?tmpl.session ?>

Availability0.2.3 and higher
Attributes
AttributeValue/Description
nameThe name of the session for the page.
showIf show is set to a value other than no, then ruby-tmpl will print out the session for the current request. If the attribute is not set, then the tag will return the current session.
Description<?tmpl.session ?> is used to set or show ruby-tmpl's current session.
NotesThe session can only be set once. Calls to session in either a script or a template file that set a new session will cause ruby-tmpl to raise an error.

Example:

In template file:
<?tmpl.session name="a_session" show="true" ?>
<?tmpl.style ?>

In script:
tmpl.session = 'a_session'
session = tmpl.session

^^ Top ^^

<?tmpl.style ?>

Availability0.2.1 and higher
Attributes
AttributeValue/Description
nameThe file name for the template to use.
showIf show is set to a value other than no, then ruby-tmpl will print out the style or template currently in use. This tag will show the resulting path after the style has been modified.
Description<?tmpl.style ?> is used to set or show ruby-tmpl's style. The <?tmpl.style ?> tag is used to allow data documents to determine how they wish to be displayed without the use of an external script.
NotesThe style of a page can be changed mid-way through a document. Recursive substitution is possible.

Example:

In template file:
<?tmpl.style name="main.tmpl" show="true" ?>
<?tmpl.style name="alternate.tmpl" ?>

In script:
tmpl.file = 'main.tmpl'

^^ Top ^^

<?tmpl.var ?>

Availability0.1 and higher
Attributes
AttributeValue/Description
nameName of the variable to set in the Ruby script.
defaultIf name is not set in the script, the value of default will be used instead.
Description<?tmpl.var ?> is used to include variables or content set by the calling script.
NotesRecursive substitution is possible. See <?tmpl.file?> and test output for more details on name spaces.

Example:

In template file:
<?tmpl.var name="test" ?>
<?tmpl.var name="color" ?> (in file w/ name space top)

In script:
tmpl.set('test', "ruby-tmpl test substitution")
tmpl.set('top:color', 'blue')

^^ Top ^^
$Id: reference.tmpl,v 1.8 2002/04/22 22:37:16 thetitan Exp $