twing
Version:
First-class Twig engine for Node.js
43 lines (42 loc) • 1.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.sourceSynchronously = exports.source = void 0;
const loader_1 = require("../../../error/loader");
/**
* Returns a template content without rendering it.
*
* @param executionContext
* @param name The template name
* @param ignoreMissing Whether to ignore missing templates or not
*
* @return The template source
*/
const source = (executionContext, name, ignoreMissing) => {
const { template } = executionContext;
return template.loadTemplate(executionContext, name)
.catch(() => {
return null;
})
.then((template) => {
if (!ignoreMissing && (template === null)) {
throw (0, loader_1.createTemplateLoadingError)([name]);
}
return (template === null || template === void 0 ? void 0 : template.source.code) || null;
});
};
exports.source = source;
const sourceSynchronously = (executionContext, name, ignoreMissing) => {
const { template } = executionContext;
let loadedTemplate;
try {
loadedTemplate = template.loadTemplate(executionContext, name);
}
catch (error) {
loadedTemplate = null;
}
if (!ignoreMissing && (loadedTemplate === null)) {
throw (0, loader_1.createTemplateLoadingError)([name]);
}
return (loadedTemplate === null || loadedTemplate === void 0 ? void 0 : loadedTemplate.source.code) || null;
};
exports.sourceSynchronously = sourceSynchronously;