Thursday, April 4, 2013

String Templates


StringTemplate is a template engine library used for generating text from data structures. StringTemplate's distinguishing characteristic is that it strictly enforces model-view separation unlike other comparable template engines. It is particularly good at multi-targeted code generators, multiple site skins, and internationalization/localization. It is also developed for multiple languages, such as Java, C#, Python. Following code show the steps of a simple “Hello World” printing using StringTemplates.

import org.antlr.stringtemplate.*;

StringTemplate hello = new StringTemplate("Hello, $name$");
hello.setAttribute("name", "World");
System.out.println(hello.toString());

0 comments:

Post a Comment