The control of whitespaces in a template is a problem that to some extent haunts every template engine. MDWorkbench provides a simple and powerful solution to this problem.
TGL automatically ignores (i.e. does not print to the output) indentation whitespace and trailing whitespace at the end of each line (includes the line break) that contains only directives (e.g. [#if option]) and/or comments (e.g. [#-- a comment --]).
This lets you write well formated templates without impact on the generated output.
Notation used in the following example:
·
is used to display automatically stripped space characters¶
is used to display automatically stripped line breaksHere is a small example of a text template:
[#template WhitespaceExample(model : uml21.Model)]¶ [#file]test.txt[/#file]·[#-- the file where to write generated contents --]¶ An example of whitespace stripping: [#-- check if the class is abstract --]¶ [#foreach class in model.getInstances("Class")]¶ class name: ${class.name} ····[#if class.isAbstract()]¶ this class is abstract [#-- there is static text on this line, no whitespace stripping --] ····[/#if]¶ [/#foreach]¶ [/#template]¶
The above template would produce an output similar to the following:
An example of whitespace stripping: class name: Account class name: Customer this class is abstract class name: Bank
White-space stripping can be disabled for a single line with the notrim directive.
In addition to automatic whitespace stripping, TGL offers some directives to have a fine control over the generated text: