UNPKG

docxtemplater

Version:

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

315 lines (314 loc) 9.21 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for es6/xml-templater.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> xml-templater.js </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Statements</span> <span class='fraction'>45/45</span> </div> <div class='fl pad1y space-right2'> <span class="strong">83.33% </span> <span class="quiet">Branches</span> <span class='fraction'>5/6</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Functions</span> <span class='fraction'>11/11</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Lines</span> <span class='fraction'>45/45</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 74 75 76 77 78 79 80 81 82 83 84</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">63×</span> <span class="cline-any cline-yes">63×</span> <span class="cline-any cline-yes">604×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">63×</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">164×</span> <span class="cline-any cline-yes">164×</span> <span class="cline-any cline-yes">164×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">164×</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">163×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">138×</span> <span class="cline-any cline-yes">138×</span> <span class="cline-any cline-yes">138×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">164×</span> <span class="cline-any cline-yes">164×</span> <span class="cline-any cline-yes">164×</span> <span class="cline-any cline-yes">164×</span> <span class="cline-any cline-yes">492×</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">63×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">837×</span> <span class="cline-any cline-yes">4160×</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">138×</span> <span class="cline-any cline-yes">138×</span> <span class="cline-any cline-yes">138×</span> <span class="cline-any cline-yes">136×</span> <span class="cline-any cline-yes">136×</span> <span class="cline-any cline-yes">136×</span> <span class="cline-any cline-yes">136×</span> <span class="cline-any cline-yes">132×</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">132×</span> <span class="cline-any cline-yes">132×</span> <span class="cline-any cline-yes">132×</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">131×</span> <span class="cline-any cline-yes">131×</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("./doc-utils"); const ScopeManager = require("./scope-manager"); const xmlMatcher = require("./xml-matcher"); 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); const result = matcher.matches.map(function (match) { return match.array[2]; }); return DocUtils.wordToUtf8(DocUtils.convertSpaces(result.join(""))); } &nbsp; module.exports = class XmlTemplater { constructor(content, options) { this.fromJson(options); this.setModules({inspect: {filePath: this.filePath}}); this.load(content); } load(content) { if (typeof content !== "string") { const err = new Errors.XTInternalError("Content must be a string"); err.properties.id = "xmltemplater_content_must_be_string"; throw err; } this.content = content; } setTags(tags) { this.tags = (tags != null) ? tags : {}; this.scopeManager = ScopeManager.createBaseScopeManager({tags: this.tags, parser: this.parser}); return this; } fromJson(options) { this.filePath = options.filePath; this.modules = options.modules; this.fileTypeConfig = options.fileTypeConfig; Object.keys(DocUtils.defaults).map(function (key) { this[key] = options[key] != null ? options[key] : <span class="branch-1 cbranch-no" title="branch not covered" >DocUtils.defaults[key];</span> }, this); } getFullText() { return getFullText(this.content, this.fileTypeConfig.tagsXmlTextArray); } setModules(obj) { this.modules.forEach((module) =&gt; { module.set(obj); }); } parse() { this.xmllexed = Lexer.xmlparse(this.content, {text: this.fileTypeConfig.tagsXmlTextArray, other: this.fileTypeConfig.tagsXmlLexedArray}); this.setModules({inspect: {xmllexed: this.xmllexed}}); this.lexed = Lexer.parse(this.xmllexed, this.delimiters); this.setModules({inspect: {lexed: this.lexed}}); this.parsed = Parser.parse(this.lexed, this.modules); this.setModules({inspect: {parsed: this.parsed}}); this.postparsed = Parser.postparse(this.parsed, this.modules); return this; } /* content is the whole content to be tagged scope is the current scope returns the new content of the tagged content */ render(to) { this.filePath = to; this.setModules({inspect: {postparsed: this.postparsed}}); this.content = render({ compiled: this.postparsed, tags: this.tags, modules: this.modules, parser: this.parser, nullGetter: this.nullGetter, filePath: this.filePath, }); this.setModules({inspect: {content: this.content}}); 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 Fri Mar 17 2017 11:22:16 GMT+0100 (CET) </div> </div> <script src="../prettify.js"></script> <script> window.onload = function () { if (typeof prettyPrint === 'function') { prettyPrint(); } }; </script> <script src="../sorter.js"></script> </body> </html>