StringTemplate 2.0 Release Notes
StringTemplate 2.0 Release Notes
Brought to you by that maniac that brings you
ANTLR!
Terence Parr
University of San Francisco
parrt@cs.usfca.edu
Copyright 2003-2004
http://www.stringtemplate.org
(StringTemplate released under BSD License)
Version 2.0, July 16, 2004
2.0 is a major bug fix and feature enhancement release, which is much better suited to code generation than the previously web-centric 1.x version. 2.0 should be a drop-in replacement for those using StringTemplate for websites, however.
Enhancements
- Template group file format with formal arguments. Looks like an output grammar.
- Rather than a handbuilt template parser, StringTemplate uses an ANTLR grammar. You can pass in lexer that breaks up a template into chunks, which is how I implement the $...$ and <...> delimiters.
- Added $else$ clause to the IF notation
- IF expressions now do the conventional boolean testing for true/false if the attribute is a boolean. Previously, IF expressions only tested presence/absence of attributes.
- Output is auto-indented by default; added general notion of StringTemplateWriter so you can do your own filtering.
- Added convenient notation for implicit aggregate attribute, which automatically creates an object with properties set to the arguments that follow. E.g., setAttribute("a.{x,y", xvalue, yvalue)}
- Added reference to template in super group: super.templateName().
- The default iterated attribute is now it rather than attr, but attr continues to work.
- a.b yields a's b attribute if a is StringTemplate.
- Added infinite recursion detection in lint mode.
- Added helper method setAttribute(String,int).
- Added escape delimiter \$ and \<.
Bug Fixes
- made lots of public methods protected to indicate which people should
be using on a regular basis.
- Supports nested anonymous templates.
- Added Collection and Iterator stuff in ASTExpr writeAttribute. Can
dump or apply template to either Map, Collection, or Iterator now.
- applying a template to a list of attributes reused the same
template, but you need a new one to get a new attribute set etc...
- apply a template to a list of attributes did a toString() rather
than build up a list of templates to apply later. Need lazy evaluation.
- removed ability to pass hashtable in as initial args...security
hole.
- included templates like <font()> computed the text right away rather
than lazily evaluating when the outer template evaluated. Was missing some parameters that way.
- when embedding a template inside another via setAttribute, it must
set the enclosingInstance so that it can inherit attributes. This was not
working
when you setAttribute("foo"...) multiple times for attribute foo.
It was just adding stuff to the internal array without checking to see if
it was a ST.
- Nested IF had some problems.
- properties that return arrays are converted to iterators. Factored
out this normalization code into static ASTExpr methods. Did not handle
properties that return collections as multi-valued values.