Template Sections |
| Section | Description |
|---|
init
required: yes [ top ] |
The init section contains template script which is
executed before any files are generated. This allows you to
initialize and build external data sources or other resources. For
(really) simple templates the file generation data is can be hard
coded into the init section.
The init section also allows you to specify the names of the the
files to generate using template service methods such as _setFileNameRoots, _setFileNameRoot, _setFullFileName, _setFileNamePrefix and _setFileNameSuffix.
Example:
<% init!
_setFileNameRoots( new String[] { "fileOne", "fileTwo" } );
_setFileNameSuffix( ".xml" );
String[] data = new String[] { "one", "two" };
%>
|
declare
required: no [ top ] |
The declare section allows you to insert supporting
script into the template. Supporting script might consist of named
constant declarations, utility code or other methods which provide
support for the main file generation script.
Note: The abbreviation <%! ... %> can also be
used to insert script into the declare section. In
fact, this is the normal way to do this.
In version 0.1, this section had the name support which can
still be used in version 0.3 templates. The support
section is however deprecated and may be removed from future
versions.
Example:
<% declare!
private static final int CODE_RED = 1;
private static final int CODE_BLUE = 2;
private static final int CODE_GREEN = 3;
private int parseCode( String rCodeName ) {
if( "red".equals( rCodeName ) ) return CODE_RED;
if( "blue".equals( rCodeName ) ) return CODE_BLUE;
if( "green".equals( rCodeName ) ) return CODE_GREEN;
return -1;
}
%>
|
body
required: yes [ top ] |
This is the default section into which template script and text is
inserted. The default section can be changed using the section directive.
|
cleanup
required: no [ top ] |
The cleanup section contains template script which is
executed after all files are generated. This allows you to release
any resources used during file generation.
Example:
<% cleanup!
databaseConnection.close();
%>
|
header
required: no [ top ] |
This section can be used to insert a header into the code writer source code.
Example:
<% header!
#!/usr/local/bin/perl
# Perl Code Writer
%>
|
footer
required: no [ top ] |
This section can be used to insert a footer into the code writer source code.
Example:
<% footer!
/* Copyright Notice */
%>
|
import
required: no [ top ] |
When generating files using Java as the template script language it
may be necessary to import utility or other classes. The
import section can be used to specify a list of import
statements for the CodeWriter.
The contents of the import section are inserted
verbatim into the CodeWriter source code in the appropriate location for
Java import statements. Note: the syntax differs slightly from JSP
syntax; you write the import statements as you normally would, not as comma separated class names.
Example:
<% import!
import java.util.Vector;
import java.util.Hashtable;
%>
|
prewrite
required: no [ top ] |
This section can be used to execute template script before file
generation begins. It is mostly useful for debugging.
Note: per file initialisation script source code should be placed
at the top of the template file, after the init section and inserted directly as template
script into the default section. There is no need to treat it
specially.
|
postwrite
required: no [ top ] |
This section can be used to execute template script after file
generation ends. It is mostly useful for debugging, but can also be
used to perform additional actions on the generated files, such as
compiling them.
Note: per file cleanup script source code should be placed
at the end of the template file and thus inserted directly as template
script into the default section. There is no need to treat it
specially.
|