@ackplus/nest-dynamic-templates
Version:
A powerful and flexible dynamic template rendering library for NestJS applications with support for Nunjucks, Handlebars, EJS, Pug, MJML, Markdown, and more.
35 lines • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EjsEngine = void 0;
const template_engine_1 = require("../template-engine");
const template_types_1 = require("../../interfaces/template.types");
const load_peer_1 = require("../load-peer");
class EjsEngine extends template_engine_1.TemplateEngine {
options;
customOptions;
static engineName = template_types_1.TemplateEngineEnum.EJS;
static displayName = 'EJS';
static peerPackage = 'ejs';
constructor(options = {}, customOptions = {}) {
super();
this.options = options;
this.customOptions = customOptions;
}
async render(content, data) {
const ejs = await (0, load_peer_1.loadPeer)('ejs', 'ejs', 'template');
const locals = { ...this.customOptions.globals, ...this.customOptions.filters, ...data };
return ejs.render(content, locals, this.options);
}
async validate(content) {
try {
const ejs = await (0, load_peer_1.loadPeer)('ejs', 'ejs', 'template');
ejs.compile(content, this.options);
return true;
}
catch {
return false;
}
}
}
exports.EjsEngine = EjsEngine;
//# sourceMappingURL=ejs.engine.js.map