StringTemplate
From Wikipedia, the free encyclopedia
StringTemplate is a java template engine (with ports for C# and Python) for generating source code, web pages, emails, or any other formatted text output. StringTemplate is particularly good at multi-targeted code generators, multiple site skins, and internationalization/localization. It evolved over years of effort developing jGuru.com and, most recently, during the development of the ANTLR v3 code generator. Its distinguishing characteristic is that it strictly enforces model-view separation unlike other engines. Separation is a key component of a generator because it makes generators easier to build, understand, modify, and retarget.
StringTemplate is technically A Functional Language For Generating Structured Text: StringTemplate's primary contribution is the clear identification and implementation of a tightly-bracketed solution to the problem of rendering data structures to text, as dictated by the nature of generation and the critical goal of strictly separating the generation logic from the output templates. First, the very nature of code generation suggests the use of a generational grammar. Next, enforcing separation of the generation logic from the output templates restricts the template language syntactically and semantically in such way that templates are easily shown to be equivalent to a grammar. Finally, the rules of separation, such as side-effect free expressions, coincide with the fundamentals of pure, functional programming.
ST embodies this solution and focuses on conceptual integrity, robustness, regularity, and efficiency (ST is fast and its binary is 165k). ST's feature set is driven by solving real problems encountered in complicated systems such as ANTLR version 3's retargetable code generator; features include group inheritance, polymorphism, lazy evaluation, recursion, auto-indentation, and the new notions of group interfaces and regions. Experience shows that ST is easy to learn and satisfying to use.
StringTemplate is available under the BSD license. Terence Parr, the creator of ANTLR, is the lead developer behind StringTemplate.