Introduction StringTemplate

StringTemplate is not a "system" or "engine" or "server"; 

It is designed to be embedded inside other applications and is distributed as a small library with no external dependencies except ANTLR

The primary classes of interest are STSTGroupDir, and STGroupFile

You can directly create a template in code, you can load templates from a directory, and you can load a file containing a collection templates (a template group file). 

Group files behave like zips or jars of template directories.

If you would like to keep just the template text and not the formal template definition around the template text, you can use STRawGroupDir.


Group files are collections of templates and dictionaries and have .stg file suffixes. 

Group files can also import templates or groups. 

The basic format looks like:

delimiters 
imports 
dictionaries 
templates


Use delimiters keyword to set delimiters per group file:  <...> are the default.



import a single template file, a group file, or a directory of templates.

Template definitions

Template definitions look like function definitions with untyped arguments:

templateName(arg1, arg2, ..., argN) ::= "single-line template"

or

templateName(arg1, arg2, ..., argN) ::= <<
multi-line template
>>

or

templateName(arg1, arg2, ..., argN) ::= <%
multi-line template that ignores indentation and newlines
%>




参考文献:

[0]  StringTemplate 4 Documentation https://theantlrguy.atlassian.net/wiki/display/ST4/Introduction


你可能感兴趣的:(StringTemplate)