ruby-tmpl: Reference
Code Examples - Download - FAQ - Home - Lists - Reference - Summary - ViewCVSRuby 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. |
Availability | 0.2.4 and higher |
Examples | See the examples section. |
^^ Top ^^
Template#to_s()
Description | Will compile and munge the output of the template and will return a copy of the string to the caller. |
Availability | 0.2.3 and higher |
Examples | r.print(tmpl)
puts tmpl.to_s |
^^ Top ^^
<?tmpl.docroot_include ?>
Attributes | Attribute | Value/Description | order | Determines whether or not the included file should be prepended or appended to the previous result. Valid attributes are append (default) and prepend . | spacer | String to use when appending or prepending the file to the result. Default is a breaking space character. |
|
Availability | 0.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. |
Notes | All 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=" " spacer=' - ' order='prepend' ?>
In script:
N/A
^^ Top ^^
<?tmpl.env ?>
Attributes | Attribute | Value/Description | name | Name of the ENV variable | default | If name is not a valid ENV key, the value of default will be used instead. |
|
Availability | 0.2.0 and higher |
Description | <?tmpl.env ?> is used to print out information in the scripts ENV hash. |
Notes | This 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 | Attribute | Value/Description | error_msg | The 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. | name | Name of the file to be included | ns | Name space that future variables will be called within | relative | If 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). |
|
Availability | 0.1 and higher |
Description | <?tmpl.file ?> is used to include other files. |
Notes | All 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=" " ?>
<?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 | Attribute | Value/Description | name | Name of the HTTP Header that was sent by the client. | default | If name is not a header sent by the client, the value of default will be used instead. |
|
Availability | 0.2.0 and higher |
Description | <?tmpl.http_headers_in ?> is used to include HTTP headers that were sent in by the client. |
Notes | None |
Example:
In template file:
<?tmpl.http_headers_in name="host" ?>
In script:
N/A
^^ Top ^^
<?tmpl.http_headers_out ?>
Attributes | Attribute | Value/Description | name | Name of the HTTP Header that was sent by the server. | default | If name is not a header sent by the server, the value of default will be used instead. |
|
Availability | 0.2.0 and higher |
Description | <?tmpl.http_headers_out ?> is used to include HTTP headers that were sent in by the client. |
Notes | None |
Example:
In template file:
<?tmpl.http_headers_out name="content-type" ?>
In script:
N/A
^^ Top ^^
<?tmpl.obj ?>
Availability | 0.2.4 and higher |
Attributes | Attribute | Value/Description | name | Name 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. |
Notes | Recursive 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 ?>
Availability | 0.2.1 and higher |
Attributes | Attribute | Value/Description | clear | If 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. | path | A 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. | show | If 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. | spacer | If 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. |
Notes | Recursive 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 ?>
Availability | 0.2.3 and higher |
Attributes | Attribute | Value/Description | name | The name of the session for the page. | show | If 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. |
Notes | The 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 ?>
Availability | 0.2.1 and higher |
Attributes | Attribute | Value/Description | name | The file name for the template to use. | show | If 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. |
Notes | The 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 ?>
Availability | 0.1 and higher |
Attributes | Attribute | Value/Description | name | Name of the variable to set in the Ruby script. | default | If 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. |
Notes | Recursive 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 $