Template Directives |
| Directive | Parameters | Description |
|---|
conf
required: yes [ top ] | Settings list: | | | template settings
|
|
Allows you to set configuration settings inside the
template. Usually placed near the top of the template. The setting
main.JostracaVersion must be contained in
the conf directive. You usually also specify the
setting main.TemplateScript here.
These settings have a higher precedence than the system settings,
but a lower precedence than settings specfied on the command line
using the -D option.
Example:
<% @conf
main.JostracaVersion = 0.3
main.TemplateScript = java
%>
|
section
required: no [ top ] | Section name: | | | new default section
| Section script: | | | first block of template script
|
|
By default, Jostraca inserts the template script and text into the
body section of the CodeWriter program. The body
section is executed once for each template.
The section directive allows you to change the default
section. This means that template text and script are inserted
directly into the specified section. You can then use the
<% ... %> syntax outside the main body of
the template text. This allows you to use blocks of template text as
macros.
Note: To reset the default section to body, use the
section directive again. If the section name parameter
is not specified, its value is assumed to be the body section. From version 0.3.2 it is no
longer possible to include template script in the body of the
section directive. See the example below for the
correct usage (note the %><%).
See:
insert-section.
Example:
<% @section declare %><%
private void formatName( String pName ) {
%><b><%=pName%></b><%
}
%><% @section %>
<% formatName( "foo" ); %>
|
insert-section
required: no [ top ] | Section name: | | | name of section to insert
|
|
The contents of the named section are inserted by this directive.
The contents are inserted directly into the current section;
template script and text from the inserted section become template
script and text in the current section. The contents of the
specified section are inserted as they are at the time of the
insertion. If more content is added to the specified section later
in the template, this will not appear in the current section.
This directive can be used with the section directive to provide macros for the template.
See:
section.
Example:
<% @section item-list %><%
for( int itemI = 0; itemI < numItems; itemI++ ) {
%>
<%=item[ itemI ] %>
<% } %><% @section %>
<% int numItems = 10; // list 10 items %>
<% @insert-section item-list %>
<% numItems = 5; // only list 5 items %>
<% @insert-section item-list %>
|
include
required: no [ top ] | File: | | | file to include
| Control Switch: | | | controls external file loading process
|
|
This directive allows external files to be included into the
template. The contents of the external file are placed directly into
the template, so template script may also be used in the external
file. Any include directives in the external files are
also included in a recursive manner until all include
directives have been performed.
By default, the file name provided to the include
directive by the file parameter specifies the location of the
external file, relative to the current folder. To specify the
location of the external file relative to the template file
use the control switch parameter value
template-relative. Absolute file paths can also be
used.
The if-exists parameter can be used in cases where the
external file may not exist. In this case, it is not considered an
error if the external file does not exist, and template processing
and generation of output files is not halted.
Example:
<% @include some-file.txt %>
<% @include other-file.txt if-exists %>
<% @include another-file.txt template-relative %>
|
replace
required: no [ top ] | From String: | | | string to search for in the template
| To String: | | | string to insert in the template
|
|
This directive performs global search and replace operations on the
template. This is useful for defining user-friendly terms for
blocks of template script.
The property insertion sequence $<...> can be
used to access the values of property settings in the search and
replace texts. In particular the shortcut settings
$<o> and $<c> can be used to
insert the template script markers <% and
%>
Note: The list of replacements is sorted so that from strings that
do not contain other from strings are replaced first.
Example:
<% @replace Item $<o>=item[itemI]$<c> %>
<% @section item-list
for( int itemI = 0; itemI < numItems; itemI++ ) {
%>
<% @section %>
<% @replace "// start item list //" \
"$<o> @insert-section item-list $<c>" %>
<% @replace "// end //" "$<o> } $<c>" %>
// start item list //
Item
// end //
|
replace-regexp
required: no [ top ] | Match: | | | Regular expression to match in the template
| Repalcement: | | | Replacement to insert in the template
|
|
This directive performs global search and replace operations on the
template, using regular expressions. This is useful for defining
user-friendly replacements for parts of the template.
The property insertion sequence $<...> can be
used to access the values of property settings in the regular
expression and in the replacement text. In particular the shortcut
settings $<o> and $<c> can be
used to insert the template script markers <% and
%>
Regular expression replacements can be used to perform complex
transformations on the template text. In particular, they can be used
to create parameterized replacements, by using the submatch insertions
sequences $1, $2, ... in the replacement text.
Note: in this version of Jostraca, the GNU regexp package is used,
which provides Perl 5 syntax regular espressions.
Example:
<% @replace ${(.*?)} $<o>=$1$<c> %>
<% @replace #if(.*?)\n '$<o> if( $1 ) { $<c>' %>
<% @replace #else '$<o> } else { $<c>' %>
<% @replace #end '$<o> } $<c>' %>
|