Today I released my first open source project, Hogan.groovy. It’s a simple port of Twitter’s Hogan.js to Groovy, my favorite JVM language, allowing you to render Mustache templates.
This isn’t major (there are several Mustache template engines on the JVM) and it wasn’t a lot of my own code (since it’s a port), but I have been wanting to do this for awhile. When they first released Hogan.js and I took a look at the modular code, I knew it was something I could kick out in a few days (which of course was a few months ago, I got distracted).
Here’s an example of how you’d use it:
One thing that I had liked about Hogan over other Mustache implementations when it came out was the fact that it could traverse up the context stack to find things. It could also use dot-notation to get at deeper items.
Handlebars.js offers some of these improvements as well as a general helper function concept which I liked, but it’s parser was generated and for awhile I contemplated trying to generate the parser using something like parboiled, however once I saw Hogan.js’ really small and simple hand-rolled scanner/parser, I knew I’d rather just port it instead.
Now that I’ve gotten my hands dirty with the scanner/parser (I even submitted a Pull Request on a bug) I might try to add some features to bring it to parity with the other implementations.
But the long term plan is to build a Grails plugin so you’ll be able to render Mustache templates in their views or easily include compiled JavaScript templates that use Hogan.js to render on the client-side.