zents
Version:
ZenTS is a Node.js & TypeScript MVC-Framework for building rich web applications, released as free and open-source software under the MIT License. It is designed for building web applications with modern tools and design patterns.
40 lines • 1.39 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Environment = void 0;
const nunjucks_1 = require("nunjucks");
const config_1 = require("../config/config");
class Environment extends nunjucks_1.Environment {
constructor(loader, templateData) {
super(loader, config_1.config.template);
this.loadFilters(templateData.filters);
}
loadFilters(filters) {
for (const [name, filter] of filters) {
const instance = new filter.module();
if (!filter.async) {
this.addFilter(name, (...args) => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
return instance.run(...args);
}, false);
}
else {
this.addFilter(name, async (...args) => {
const next = args.pop();
let err = null;
let result;
try {
result = (await instance.run(...args));
}
catch (e) {
err = e;
}
finally {
next(err, result);
}
}, true);
}
}
}
}
exports.Environment = Environment;
//# sourceMappingURL=Environment.js.map