UNPKG

docxtemplater

Version:

.docx generator working with templates and data (like Mustache)

282 lines (281 loc) 8.26 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for es6/xmlTemplater.js</title> <meta charset="utf-8" /> <link rel="stylesheet" href="../prettify.css" /> <link rel="stylesheet" href="../base.css" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <style type='text/css'> .coverage-summary .sorter { background-image: url(../sort-arrow-sprite.png); } </style> </head> <body> <div class='wrapper'> <div class='pad1'> <h1> <a href="../index.html">all files</a> / <a href="index.html">es6/</a> xmlTemplater.js </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Statements</span> <span class='fraction'>39/39</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Branches</span> <span class='fraction'>6/6</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Functions</span> <span class='fraction'>7/7</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Lines</span> <span class='fraction'>39/39</span> </div> </div> </div> <div class='status-line high'></div> <pre><table class="coverage"> <tr><td class="line-count quiet">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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes">57×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">57×</span> <span class="cline-any cline-yes">57×</span> <span class="cline-any cline-yes">57×</span> <span class="cline-any cline-yes">668×</span> <span class="cline-any cline-yes">668×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">57×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">57×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-yes">299×</span> <span class="cline-any cline-yes">1794×</span> <span class="cline-any cline-yes">1794×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">57×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">277×</span> <span class="cline-any cline-yes">277×</span> <span class="cline-any cline-yes">274×</span> <span class="cline-any cline-yes">274×</span> <span class="cline-any cline-yes">269×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">267×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span></td><td class="text"><pre class="prettyprint lang-js">"use strict"; &nbsp; const DocUtils = require("./docUtils"); const ScopeManager = require("./scopeManager"); const xmlMatcher = require("./xmlMatcher"); const Errors = require("./errors"); const Lexer = require("./lexer"); const Parser = require("./parser.js"); const render = require("./render.js"); &nbsp; function getFullText(content, tagsXmlArray) { const matcher = xmlMatcher(content, tagsXmlArray); // get only the text const output = ((() =&gt; { const result = []; for (let i = 0, match; i &lt; matcher.matches.length; i++) { match = matcher.matches[i]; result.push(match.array[2]); } return result; })()); return DocUtils.wordToUtf8(DocUtils.convertSpaces(output.join(""))); } &nbsp; module.exports = class XmlTemplater { constructor(content, options) { this.fromJson(options); this.load(content); } load(content) { this.content = content; if (typeof this.content !== "string") { const err = new Errors.XTInternalError("Content must be a string"); err.properties.id = "xmltemplater_content_must_be_string"; throw err; } } fromJson(options) { this.tags = (options.tags != null) ? options.tags : {}; this.filePath = options.filePath; this.modules = options.modules; this.fileTypeConfig = options.fileTypeConfig; this.scopeManager = ScopeManager.createBaseScopeManager({tags: this.tags, parser: this.parser}); Object.keys(DocUtils.defaults).map(function (key) { const defaultValue = DocUtils.defaults[key]; this[key] = (options[key] != null) ? options[key] : defaultValue; }, this); } getFullText() { return getFullText(this.content, this.fileTypeConfig.tagsXmlTextArray); } /* content is the whole content to be tagged scope is the current scope returns the new content of the tagged content */ render() { this.xmllexed = Lexer.xmlparse(this.content, {text: this.fileTypeConfig.tagsXmlTextArray, other: this.fileTypeConfig.tagsXmlLexedArray}); this.lexed = Lexer.parse(this.xmllexed, this.delimiters); this.parsed = Parser.parse(this.lexed, this.modules); this.moduleparsed = Parser.postmoduleparse(this.parsed, this.modules); this.content = render({ compiled: this.moduleparsed, tags: this.tags, modules: this.modules, parser: this.parser, nullGetter: this.nullGetter, filePath: this.filePath, }); return this; } }; &nbsp;</pre></td></tr> </table></pre> <div class='push'></div><!-- for sticky footer --> </div><!-- /wrapper --> <div class='footer quiet pad2 space-top1 center small'> Code coverage generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Sat Jun 18 2016 12:59:17 GMT+0200 (CEST) </div> </div> <script src="../prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="../sorter.js"></script> </body> </html>