UNPKG

@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.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.PugEngine = void 0; const template_types_1 = require("../../interfaces/template.types"); const template_engine_1 = require("../template-engine"); const load_peer_1 = require("../load-peer"); class PugEngine extends template_engine_1.TemplateEngine { options; customOptions; static engineName = template_types_1.TemplateEngineEnum.PUG; static displayName = 'Pug'; static peerPackage = 'pug'; constructor(options = {}, customOptions = {}) { super(); this.options = options; this.customOptions = customOptions; } async render(content, data) { const pug = await (0, load_peer_1.loadPeer)('pug', 'pug', 'template'); const template = pug.compile(content, this.options); return template({ ...this.customOptions.globals, ...this.customOptions.filters, ...data }); } async validate(content) { try { const pug = await (0, load_peer_1.loadPeer)('pug', 'pug', 'template'); pug.compile(content, this.options); return true; } catch { return false; } } } exports.PugEngine = PugEngine; //# sourceMappingURL=pug.engine.js.map