Mikhail Kryshen
Tema user manual
Introduction
Tema is a macro processor and template engine. It reads the input file recursively expanding any macro found in the text.
Distinctive features:
- Extensible: implement new functions as Java classes.
- Database access.
- Processes and outputs data as early as possible (function could start to output data before all it's arguments are read and parsed).
- Apache Ant integration.
Tema macro has the following syntax:
<%function_list{:|#|\|`}[escape]text%>[escape]
function_list is the list of text-processing functions.
Functions will be applied to text in reverse order.
text could contain space-separated list of arguments
followed by arbitrary data. Number of arguments is determined by the last
function in the function_list.
[arg1 arg2...] [data]
The text is separated from the list of functions by one of the following characters:
- ':' – process text recursively.
- '#' – parse text but do not replace any embedded macro.
- '\', '`' – do not parse text (ignore any '<%' sequences).
escape is either '\' or '\\':
- \ – the following newline symbol will be removed;
- \\ – the following sequence of the whitespace characters will be removed.
You could use '[%' and '%]' character sequences to denote macro as an alternative to '<%' and '%>'.
Every function returns integer value. The general convention is to return non-zero for successful operation. The value of the macro substitution is the return value of the first function in the function list. The value of any Tema text is the sum value of all macro in the text, except the value of the text without any macro equals -1.
Internally, Tema function could be represented by any Java object.
Instances of kryshen.tema.Function and kryshen.tema.Context are handled
specially. For any other type of object, function output would be the value
returned by the method toString().
Built-in functions
Notice: some functions are not yet described in this manual. For the complete list of built-in functions refer to the API documentation and source code.
[%!\ comment %]).
Data: variable value
Output: function data
next_arg, data, and has_more_data
functions to access function arguments.
Data: code
Output: name
define function.
Parses the next argument from the calling function input.
define function.
Outputs remaining text passed to the calling function.
define function. Returns non-zero value if
the calling function has more input data available.
Data: static variable value (optional)
Output: function data
Output: nothing
Output: function output
Output: name
Output: output generated by the code
s1 with s2 in data.
Output: text with escaped XML special characters
Output: XML CDATA section containing the text
Input / output
src to dest.
Output: dest
Data: text
Output: name
Output: File contents.
Output: Result of processing the template.
Output: Path constructed from the base directory and file name.
Conditionals
Output: Function data if it's value is non-zero or empty text.
Data: text
Database
load function
before using db_connect
(e.g. <%load:driver sun.jdbc.odbc.JdbcOdbcDriver%>).
Data: resource
Data: SQL statement
db_query function.
Output: value from the query result.
db_query function.
Running Tema
Change to the dist subdirectory in the distribution package and issue the following command:
java -jar tema.jar [options] [files]
The following options are recognized:
--demo— run demo console with a code example;-h, --help— print help message;--input-encoding <arg>— set the input encoding;--log <arg>— log all error messages to the specified file;-o, --output <arg>— set the output file;--output-encoding <arg>— set the output encoding;-v, --version— print the version information and exit.