UNPKG

docxtemplater

Version:

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

366 lines (365 loc) 10.3 kB
<!doctype html> <html lang="en"> <head> <title>Code coverage report for es6/scopeManager.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> scopeManager.js </h1> <div class='clearfix'> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Statements</span> <span class='fraction'>52/52</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Branches</span> <span class='fraction'>22/22</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Functions</span> <span class='fraction'>8/8</span> </div> <div class='fl pad1y space-right2'> <span class="strong">100% </span> <span class="quiet">Lines</span> <span class='fraction'>51/51</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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101</td><td class="line-coverage quiet"><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-neutral">&nbsp;</span> <span class="cline-any cline-yes"></span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">732×</span> <span class="cline-any cline-yes">732×</span> <span class="cline-any cline-yes">732×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">159×</span> <span class="cline-any cline-yes">159×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">260×</span> <span class="cline-any cline-yes">153×</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">159×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">159×</span> <span class="cline-any cline-yes">159×</span> <span class="cline-any cline-yes">159×</span> <span class="cline-any cline-yes">105×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">54×</span> <span class="cline-any cline-yes">43×</span> <span class="cline-any cline-yes">145×</span> <span class="cline-any cline-yes">145×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">43×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">11×</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"></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">908×</span> <span class="cline-any cline-yes">908×</span> <span class="cline-any cline-yes">908×</span> <span class="cline-any cline-yes">908×</span> <span class="cline-any cline-yes">908×</span> <span class="cline-any cline-yes">908×</span> <span class="cline-any cline-yes">908×</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-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-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">907×</span> <span class="cline-any cline-yes">907×</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-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-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"></span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">906×</span> <span class="cline-any cline-yes">898×</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-neutral">&nbsp;</span> <span class="cline-any cline-yes">153×</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">153×</span> <span class="cline-any cline-yes">153×</span> <span class="cline-any cline-yes">153×</span> <span class="cline-any cline-yes">153×</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"></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-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></td><td class="text"><pre class="prettyprint lang-js">"use strict"; const Errors = require("./errors"); &nbsp; // This class responsibility is to manage the scope const ScopeManager = class ScopeManager { constructor(options) { this.scopePath = options.scopePath; this.scopeList = options.scopeList; this.parser = options.parser; } loopOver(tag, callback, inverted) { inverted = inverted || false; return this.loopOverValue(this.getValue(tag), callback, inverted); } functorIfInverted(inverted, functor, value) { if (inverted) { functor(value); } } isValueFalsy(value, type) { return (value == null || !value || (type === "[object Array]" &amp;&amp; value.length === 0)); } loopOverValue(value, functor, inverted) { const type = Object.prototype.toString.call(value); const currentValue = this.scopeList[this.num]; if (this.isValueFalsy(value, type)) { return this.functorIfInverted(inverted, functor, currentValue); } if (type === "[object Array]") { for (let i = 0, scope; i &lt; value.length; i++) { scope = value[i]; this.functorIfInverted(!inverted, functor, scope); } return; } if (type === "[object Object]") { return this.functorIfInverted(!inverted, functor, value); } if (value === true) { return this.functorIfInverted(!inverted, functor, currentValue); } } getValue(tag, num) { // search in the scopes (in reverse order) and keep the first defined value this.num = num == null ? (this.scopeList.length - 1) : num; let err; let parser; let result; const scope = this.scopeList[this.num]; try { parser = this.parser(tag); } catch (error) { err = new Errors.XTScopeParserError("Scope parser compilation failed"); err.properties = { id: "scopeparser_compilation_failed", tag: tag, explanation: `The scope parser for the tag ${tag} failed to compile`, rootError: error, }; throw err; } try { result = parser.get(scope, {num: this.num, scopeList: this.scopeList}); } catch (error) { err = new Errors.XTScopeParserError("Scope parser execution failed"); err.properties = { id: "scopeparser_execution_failed", explanation: `The scope parser for the tag ${tag} failed to execute`, scope: scope, tag: tag, rootError: error, }; throw err; } if (result == null &amp;&amp; this.num &gt; 0) { return this.getValue(tag, this.num - 1); } return result; } createSubScopeManager(scope, tag) { const options = { scopePath: this.scopePath.slice(0), scopeList: this.scopeList.slice(0), }; &nbsp; options.parser = this.parser; options.scopeList = this.scopeList.concat(scope); options.scopePath = this.scopePath.concat(tag); return new ScopeManager(options); } }; &nbsp; ScopeManager.createBaseScopeManager = function ({parser, tags}) { const options = {parser, tags}; options.scopePath = []; options.scopeList = [tags]; return new ScopeManager(options); }; &nbsp; module.exports = ScopeManager; &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>