-
Notifications
You must be signed in to change notification settings - Fork 285
Home
To ask questions or join in the discussion, there is a Google group.
Mustache.java is a Java 6 implementation of the mustache language. It supports all the base functionality and ignores some of the things like pragmas. Here are some interesting properties of this implementation:
- very simple to implement the backing code
- concurrent execution
- reloadable at runtime during development
Here is the code required to compile and execute hello, world:
public class HelloWorld {
String hello = "Hello";
String world() {return "world";}
public static void main(String[] args) throws MustacheException, IOException {
Writer writer = new OutputStreamWriter(System.out);
MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile(new StringReader("{{hello}}, {{world}}!"), "helloworld");
mustache.execute(writer, new HelloWorld());
writer.flush();
}
}
The simplicity of implementation of the backing code is that mustache.java cares very little about things like access modifiers, you can make it whatever you want (except explicitly private) and it will be able to access your fields and methods. The names need to match up with the names in the mustache templates though you can do things like 'object.subobject' and mustache.java will evaluate them by going through the hierarchy.