I've done (well, almost) it on my branch of NodeBB -- abstract out templates engine and add support of Jade in addition to templates.js
Actually now it's posible to add more template engines in a similar fasion.
There are glitches of course but in general everything looks good.
In my opinion templates.js is cute but a little too lightweight. And at the same time its syntax is quite verbose and looks like "broken html". But ofcourse I can't just frop it. It do its job good and all currently working code use it.
What I wanted is posibility to use another template engines that won't broke everything.
- I've replaced templates.js with general library (nodebb-templatist)
It delegates temlate compilation, loading and rendering to concrete function choosen by template type
- Concrete library like nodebb-templatist-tpl or nodebb-templatist-jade registers template compiler and loader with general library.
- Template compiler function asyncronously returns dictionary with relative file names and content
- Loader function asynchronously returns "render" function for given template name
- Luck of careful testing
- It would be cool if that concrete template engines be simply a kind of NodeBB plugins. But currently I can't do it because templates compilation runs before plugins are loaded and initialized.
- templates.js can render not only whole template but a specific template block. This ability isnt present in most of other engines. I have a couple of ideas how to implement that but I'm not sure.
- Cross-engine partial includes can be implemented but requires additional hacking on top of template parsing.
I can make pull request after some cleanups.
This post is an anounce and invitation to a discussion