Nunjucks

A rich and powerful templating language for JavaScript.

https://mozilla.github.io/nunjucks/

Пример

var nunjucks = require('nunjucks'); var MyLoader = nunjucks.Loader.extend({ async: true, getSource: function(name, callback) { var res = '...'; callback(err, res); } }); var env = new nunjucks.Environment(new MyLoader(), {autoescape: true}); // ! function CustomExtension(cb) { this.tags = ['docs']; this.parse = function(parser, nodes, lexer) { var tok = parser.nextToken(); var args = parser.parseSignature(null, true); parser.nextToken(); var body = parser.parseUntilBlocks('enddocs'); parser.advanceAfterBlockEnd(); return new nodes.CallExtensionAsync(this, 'run', args, [body], cb); }; this.run = function(context, args, body, cb) { var res = env.filters.safe(args + ':' + body()); // prevent escape cb(null, res); }; } env.addExtension('CustomExtension', new CustomExtension()); env.renderString('{% docs "<TEST>" %}"OK"{% enddocs %}', console.log);