3 ms·
I've written a Jinja-to-JavaScript compiler: https://bitbucket.org/djc/jasinja https://bitbucket.org/djc/jasinja It reuses the Jinja front-end, it really only
by dochtman 14y ago
I've written a Jinja-to-JavaScript compiler:
https://bitbucket.org/djc/jasinja https://bitbucket.org/djc/jasinja
It reuses the Jinja front-end, it really only replaces Jinja's code generator and supports a pretty large subset of Jinja. I think this is particularly great because it allows you to switch from server-side template rendering to client-side rendering of templates piecemeal, or use both with the same templating language.
- masklinn 14y agoThat's kinda neat. I assume it only supports built-in filters and control structures?
- dochtman 14y agoThe compiler output looks roughly like this: var Jasinja = { "filters": { "attr": function(obj, name) { return obj[name]; } }, "tests": { "lower": function(val) { return val.toLowerCase() == val; } }, "templates": { "test": { "macros": {}, "blocks": {}, "render": function(ctx, tmpl) { return "a"; } } } }; So you can easily add some filters by setting Jasinja.filters['myfilter'] to a function.