const wrapper = require("../module-wrapper");
const Errors = require("../errors");
class Render {
constructor() {
this.name = "Render";
}
set(obj) {
if (obj.compiled) {
this.compiled = obj.compiled;
}
if (obj.data != null) {
this.data = obj.data;
}
}
getRenderedMap(mapper) {
return Object.keys(this.compiled).reduce((mapper, from) => {
mapper[from] = {from, data: this.data};
return mapper;
}, mapper);
}
optionsTransformer(options, docxtemplater) {
this.parser = docxtemplater.parser;
return options;
}
postparse(parsed) {
const errors = [];
parsed.map((p) => {
if (p.type === "placeholder") {
const tag = p.value;
try {
this.parser(tag);
}
catch (rootError) {
const err = new Errors.XTScopeParserError("Scope parser compilation failed");
err.properties = {
id: "scopeparser_compilation_failed",
tag,
explanation: `The scope parser for the tag ${tag} failed to compile`,
rootError,
};
errors.push(err);
}
}
});
if (errors.length > 0) {
Errors.throwMultiError(errors);
}
return parsed;
}
}
module.exports = () => wrapper(new Render());
|