Tweeg: a Twig to JS compiler
Tweeg is a compiler for the popular PHP template engine Twig. It converts templates to JavaScript. Not being a PHP fan, to say the least, I don't particularly like Twig. But it does the job. At eMAG we're using PHP + Symfony on the server, and Twig is pretty much non-negotiable at this point.
Sometimes we need to render the same template on the server (on initial page load) and also on the client (when we update stuff via AJAX requests). So far, such cases were rare, so we wrote separate templates for JS using a slightly modified version of John Resig's micro-templating. It sucks, but it did the job. However, we will soon face the situation that we'll have to duplicate dozen of templates, just because Twig was not supported in JavaScript. So I took upon myself the lovely task of writing a Twig parser and compiler.
Halfway through, a colleague pointed out a similar package (twig.js). Tweeg was already better in a number of ways, so I didn't give up:
- Tweeg is a compiler, which twig.js is not. (issue)
- Tweeg supports string interpolation, which twig.js doesn't
- Tweeg is much smaller.
eMAG kindly agreed to open-source this package under the MIT license, so here it is. Usage details in the README.
PS: I would welcome a Gulp plugin for it. ;-)