all files / es6/modules/ render.js

100% Statements 26/26
100% Branches 8/8
100% Functions 5/5
100% Lines 25/25
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54       90×     896× 31×   896× 30×       31× 80× 80×       90× 90×     197× 197× 5157× 402× 402× 402×                     197×   196×       90×  
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());