| author | ymh <ymh.work@gmail.com> |
| Wed, 11 Dec 2019 11:02:15 +0100 | |
| changeset 1512 | 487ca37bb0c7 |
| parent 1304 | 10974bff4dae |
| child 1514 | 5869151a1f2f |
| permissions | -rw-r--r-- |
| 940 | 1 |
/*! |
2 |
* mustache.js - Logic-less {{mustache}} templates with JavaScript |
|
3 |
* http://github.com/janl/mustache.js |
|
4 |
*/ |
|
| 598 | 5 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
6 |
/*global define: false Mustache: true*/ |
| 598 | 7 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
8 |
(function defineMustache (global, factory) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
9 |
if (typeof exports === 'object' && exports && typeof exports.nodeName !== 'string') { |
| 940 | 10 |
factory(exports); // CommonJS |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
11 |
} else if (typeof define === 'function' && define.amd) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
12 |
define(['exports'], factory); // AMD |
| 940 | 13 |
} else { |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
14 |
global.Mustache = {}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
15 |
factory(Mustache); // script, wsh, asp |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
16 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
17 |
}(this, function mustacheFactory (mustache) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
18 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
19 |
var objectToString = Object.prototype.toString; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
20 |
var isArray = Array.isArray || function isArrayPolyfill (object) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
21 |
return objectToString.call(object) === '[object Array]'; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
22 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
23 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
24 |
function isFunction (object) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
25 |
return typeof object === 'function'; |
| 940 | 26 |
} |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
27 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
28 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
29 |
* More correct typeof string handling array |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
30 |
* which normally returns typeof 'object' |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
31 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
32 |
function typeStr (obj) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
33 |
return isArray(obj) ? 'array' : typeof obj; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
34 |
} |
| 598 | 35 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
36 |
function escapeRegExp (string) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
37 |
return string.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&'); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
38 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
39 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
40 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
41 |
* Null safe way of checking whether or not an object, |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
42 |
* including its prototype, has a given property |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
43 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
44 |
function hasProperty (obj, propName) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
45 |
return obj != null && typeof obj === 'object' && (propName in obj); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
46 |
} |
| 940 | 47 |
|
48 |
// Workaround for https://issues.apache.org/jira/browse/COUCHDB-577 |
|
49 |
// See https://github.com/janl/mustache.js/issues/189 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
50 |
var regExpTest = RegExp.prototype.test; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
51 |
function testRegExp (re, string) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
52 |
return regExpTest.call(re, string); |
| 598 | 53 |
} |
54 |
||
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
55 |
var nonSpaceRe = /\S/; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
56 |
function isWhitespace (string) { |
| 940 | 57 |
return !testRegExp(nonSpaceRe, string); |
| 598 | 58 |
} |
59 |
||
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
60 |
var entityMap = { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
61 |
'&': '&', |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
62 |
'<': '<', |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
63 |
'>': '>', |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
64 |
'"': '"', |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
65 |
"'": ''', |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
66 |
'/': '/' |
| 940 | 67 |
}; |
68 |
||
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
69 |
function escapeHtml (string) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
70 |
return String(string).replace(/[&<>"'\/]/g, function fromEntityMap (s) { |
| 940 | 71 |
return entityMap[s]; |
| 598 | 72 |
}); |
73 |
} |
|
74 |
||
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
75 |
var whiteRe = /\s*/; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
76 |
var spaceRe = /\s+/; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
77 |
var equalsRe = /\s*=/; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
78 |
var curlyRe = /\s*\}/; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
79 |
var tagRe = /#|\^|\/|>|\{|&|=|!/; |
| 940 | 80 |
|
81 |
/** |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
82 |
* Breaks up the given `template` string into a tree of tokens. If the `tags` |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
83 |
* argument is given here it must be an array with two string values: the |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
84 |
* opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
85 |
* course, the default is to use mustaches (i.e. mustache.tags). |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
86 |
* |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
87 |
* A token is an array with at least 4 elements. The first element is the |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
88 |
* mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
89 |
* did not contain a symbol (i.e. {{myValue}}) this element is "name". For |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
90 |
* all text that appears outside a symbol this element is "text". |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
91 |
* |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
92 |
* The second element of a token is its "value". For mustache tags this is |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
93 |
* whatever else was inside the tag besides the opening symbol. For text tokens |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
94 |
* this is the text itself. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
95 |
* |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
96 |
* The third and fourth elements of the token are the start and end indices, |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
97 |
* respectively, of the token in the original template. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
98 |
* |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
99 |
* Tokens that are the root node of a subtree contain two more elements: 1) an |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
100 |
* array of tokens in the subtree and 2) the index in the original template at |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
101 |
* which the closing tag for that section begins. |
| 940 | 102 |
*/ |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
103 |
function parseTemplate (template, tags) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
104 |
if (!template) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
105 |
return []; |
| 940 | 106 |
|
107 |
var sections = []; // Stack to hold section tokens |
|
108 |
var tokens = []; // Buffer to hold the tokens |
|
109 |
var spaces = []; // Indices of whitespace tokens on the current line |
|
110 |
var hasTag = false; // Is there a {{tag}} on the current line? |
|
111 |
var nonSpace = false; // Is there a non-space char on the current line? |
|
112 |
||
113 |
// Strips all whitespace tokens array for the current line |
|
114 |
// if there was a {{#tag}} on it and otherwise only space. |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
115 |
function stripSpace () { |
| 940 | 116 |
if (hasTag && !nonSpace) { |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
117 |
while (spaces.length) |
| 940 | 118 |
delete tokens[spaces.pop()]; |
119 |
} else { |
|
120 |
spaces = []; |
|
| 598 | 121 |
} |
122 |
||
| 940 | 123 |
hasTag = false; |
124 |
nonSpace = false; |
|
125 |
} |
|
| 598 | 126 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
127 |
var openingTagRe, closingTagRe, closingCurlyRe; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
128 |
function compileTags (tagsToCompile) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
129 |
if (typeof tagsToCompile === 'string') |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
130 |
tagsToCompile = tagsToCompile.split(spaceRe, 2); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
131 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
132 |
if (!isArray(tagsToCompile) || tagsToCompile.length !== 2) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
133 |
throw new Error('Invalid tags: ' + tagsToCompile); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
134 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
135 |
openingTagRe = new RegExp(escapeRegExp(tagsToCompile[0]) + '\\s*'); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
136 |
closingTagRe = new RegExp('\\s*' + escapeRegExp(tagsToCompile[1])); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
137 |
closingCurlyRe = new RegExp('\\s*' + escapeRegExp('}' + tagsToCompile[1])); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
138 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
139 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
140 |
compileTags(tags || mustache.tags); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
141 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
142 |
var scanner = new Scanner(template); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
143 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
144 |
var start, type, value, chr, token, openSection; |
| 940 | 145 |
while (!scanner.eos()) { |
146 |
start = scanner.pos; |
|
| 598 | 147 |
|
| 940 | 148 |
// Match any text between tags. |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
149 |
value = scanner.scanUntil(openingTagRe); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
150 |
|
| 940 | 151 |
if (value) { |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
152 |
for (var i = 0, valueLength = value.length; i < valueLength; ++i) { |
| 940 | 153 |
chr = value.charAt(i); |
| 598 | 154 |
|
| 940 | 155 |
if (isWhitespace(chr)) { |
156 |
spaces.push(tokens.length); |
|
| 598 | 157 |
} else { |
| 940 | 158 |
nonSpace = true; |
| 598 | 159 |
} |
160 |
||
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
161 |
tokens.push([ 'text', chr, start, start + 1 ]); |
| 940 | 162 |
start += 1; |
| 598 | 163 |
|
| 940 | 164 |
// Check for whitespace on the current line. |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
165 |
if (chr === '\n') |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
166 |
stripSpace(); |
| 598 | 167 |
} |
168 |
} |
|
169 |
||
| 940 | 170 |
// Match the opening tag. |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
171 |
if (!scanner.scan(openingTagRe)) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
172 |
break; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
173 |
|
| 940 | 174 |
hasTag = true; |
| 598 | 175 |
|
| 940 | 176 |
// Get the tag type. |
177 |
type = scanner.scan(tagRe) || 'name'; |
|
178 |
scanner.scan(whiteRe); |
|
| 598 | 179 |
|
| 940 | 180 |
// Get the tag value. |
181 |
if (type === '=') { |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
182 |
value = scanner.scanUntil(equalsRe); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
183 |
scanner.scan(equalsRe); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
184 |
scanner.scanUntil(closingTagRe); |
| 940 | 185 |
} else if (type === '{') { |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
186 |
value = scanner.scanUntil(closingCurlyRe); |
| 940 | 187 |
scanner.scan(curlyRe); |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
188 |
scanner.scanUntil(closingTagRe); |
| 940 | 189 |
type = '&'; |
| 598 | 190 |
} else { |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
191 |
value = scanner.scanUntil(closingTagRe); |
| 598 | 192 |
} |
193 |
||
| 940 | 194 |
// Match the closing tag. |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
195 |
if (!scanner.scan(closingTagRe)) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
196 |
throw new Error('Unclosed tag at ' + scanner.pos); |
| 940 | 197 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
198 |
token = [ type, value, start, scanner.pos ]; |
| 940 | 199 |
tokens.push(token); |
200 |
||
201 |
if (type === '#' || type === '^') { |
|
202 |
sections.push(token); |
|
203 |
} else if (type === '/') { |
|
204 |
// Check section nesting. |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
205 |
openSection = sections.pop(); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
206 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
207 |
if (!openSection) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
208 |
throw new Error('Unopened section "' + value + '" at ' + start); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
209 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
210 |
if (openSection[1] !== value) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
211 |
throw new Error('Unclosed section "' + openSection[1] + '" at ' + start); |
| 940 | 212 |
} else if (type === 'name' || type === '{' || type === '&') { |
213 |
nonSpace = true; |
|
214 |
} else if (type === '=') { |
|
215 |
// Set the tags for the next time around. |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
216 |
compileTags(value); |
| 598 | 217 |
} |
| 940 | 218 |
} |
| 598 | 219 |
|
| 940 | 220 |
// Make sure there are no open sections when we're done. |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
221 |
openSection = sections.pop(); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
222 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
223 |
if (openSection) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
224 |
throw new Error('Unclosed section "' + openSection[1] + '" at ' + scanner.pos); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
225 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
226 |
return nestTokens(squashTokens(tokens)); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
227 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
228 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
229 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
230 |
* Combines the values of consecutive text tokens in the given `tokens` array |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
231 |
* to a single token. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
232 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
233 |
function squashTokens (tokens) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
234 |
var squashedTokens = []; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
235 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
236 |
var token, lastToken; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
237 |
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
238 |
token = tokens[i]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
239 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
240 |
if (token) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
241 |
if (token[0] === 'text' && lastToken && lastToken[0] === 'text') { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
242 |
lastToken[1] += token[1]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
243 |
lastToken[3] = token[3]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
244 |
} else { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
245 |
squashedTokens.push(token); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
246 |
lastToken = token; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
247 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
248 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
249 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
250 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
251 |
return squashedTokens; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
252 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
253 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
254 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
255 |
* Forms the given array of `tokens` into a nested tree structure where |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
256 |
* tokens that represent a section have two additional items: 1) an array of |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
257 |
* all tokens that appear in that section and 2) the index in the original |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
258 |
* template that represents the end of that section. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
259 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
260 |
function nestTokens (tokens) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
261 |
var nestedTokens = []; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
262 |
var collector = nestedTokens; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
263 |
var sections = []; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
264 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
265 |
var token, section; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
266 |
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
267 |
token = tokens[i]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
268 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
269 |
switch (token[0]) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
270 |
case '#': |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
271 |
case '^': |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
272 |
collector.push(token); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
273 |
sections.push(token); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
274 |
collector = token[4] = []; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
275 |
break; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
276 |
case '/': |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
277 |
section = sections.pop(); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
278 |
section[5] = token[2]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
279 |
collector = sections.length > 0 ? sections[sections.length - 1][4] : nestedTokens; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
280 |
break; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
281 |
default: |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
282 |
collector.push(token); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
283 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
284 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
285 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
286 |
return nestedTokens; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
287 |
} |
| 940 | 288 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
289 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
290 |
* A simple string scanner that is used by the template parser to find |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
291 |
* tokens in template strings. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
292 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
293 |
function Scanner (string) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
294 |
this.string = string; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
295 |
this.tail = string; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
296 |
this.pos = 0; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
297 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
298 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
299 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
300 |
* Returns `true` if the tail is empty (end of string). |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
301 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
302 |
Scanner.prototype.eos = function eos () { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
303 |
return this.tail === ''; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
304 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
305 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
306 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
307 |
* Tries to match the given regular expression at the current position. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
308 |
* Returns the matched text if it can match, the empty string otherwise. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
309 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
310 |
Scanner.prototype.scan = function scan (re) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
311 |
var match = this.tail.match(re); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
312 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
313 |
if (!match || match.index !== 0) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
314 |
return ''; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
315 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
316 |
var string = match[0]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
317 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
318 |
this.tail = this.tail.substring(string.length); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
319 |
this.pos += string.length; |
| 940 | 320 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
321 |
return string; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
322 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
323 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
324 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
325 |
* Skips all text until the given regular expression can be matched. Returns |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
326 |
* the skipped string, which is the entire tail if no match can be made. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
327 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
328 |
Scanner.prototype.scanUntil = function scanUntil (re) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
329 |
var index = this.tail.search(re), match; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
330 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
331 |
switch (index) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
332 |
case -1: |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
333 |
match = this.tail; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
334 |
this.tail = ''; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
335 |
break; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
336 |
case 0: |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
337 |
match = ''; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
338 |
break; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
339 |
default: |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
340 |
match = this.tail.substring(0, index); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
341 |
this.tail = this.tail.substring(index); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
342 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
343 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
344 |
this.pos += match.length; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
345 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
346 |
return match; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
347 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
348 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
349 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
350 |
* Represents a rendering context by wrapping a view object and |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
351 |
* maintaining a reference to the parent context. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
352 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
353 |
function Context (view, parentContext) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
354 |
this.view = view; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
355 |
this.cache = { '.': this.view }; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
356 |
this.parent = parentContext; |
| 940 | 357 |
} |
| 598 | 358 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
359 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
360 |
* Creates a new context using the given view with this context |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
361 |
* as the parent. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
362 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
363 |
Context.prototype.push = function push (view) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
364 |
return new Context(view, this); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
365 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
366 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
367 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
368 |
* Returns the value of the given name in this context, traversing |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
369 |
* up the context hierarchy if the value is absent in this context's view. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
370 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
371 |
Context.prototype.lookup = function lookup (name) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
372 |
var cache = this.cache; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
373 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
374 |
var value; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
375 |
if (cache.hasOwnProperty(name)) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
376 |
value = cache[name]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
377 |
} else { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
378 |
var context = this, names, index, lookupHit = false; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
379 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
380 |
while (context) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
381 |
if (name.indexOf('.') > 0) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
382 |
value = context.view; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
383 |
names = name.split('.'); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
384 |
index = 0; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
385 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
386 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
387 |
* Using the dot notion path in `name`, we descend through the |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
388 |
* nested objects. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
389 |
* |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
390 |
* To be certain that the lookup has been successful, we have to |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
391 |
* check if the last object in the path actually has the property |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
392 |
* we are looking for. We store the result in `lookupHit`. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
393 |
* |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
394 |
* This is specially necessary for when the value has been set to |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
395 |
* `undefined` and we want to avoid looking up parent contexts. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
396 |
**/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
397 |
while (value != null && index < names.length) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
398 |
if (index === names.length - 1) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
399 |
lookupHit = hasProperty(value, names[index]); |
| 598 | 400 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
401 |
value = value[names[index++]]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
402 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
403 |
} else { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
404 |
value = context.view[name]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
405 |
lookupHit = hasProperty(context.view, name); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
406 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
407 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
408 |
if (lookupHit) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
409 |
break; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
410 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
411 |
context = context.parent; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
412 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
413 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
414 |
cache[name] = value; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
415 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
416 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
417 |
if (isFunction(value)) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
418 |
value = value.call(this.view); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
419 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
420 |
return value; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
421 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
422 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
423 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
424 |
* A Writer knows how to take a stream of tokens and render them to a |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
425 |
* string, given a context. It also maintains a cache of templates to |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
426 |
* avoid the need to parse the same template twice. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
427 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
428 |
function Writer () { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
429 |
this.cache = {}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
430 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
431 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
432 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
433 |
* Clears all cached templates in this writer. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
434 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
435 |
Writer.prototype.clearCache = function clearCache () { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
436 |
this.cache = {}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
437 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
438 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
439 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
440 |
* Parses and caches the given `template` and returns the array of tokens |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
441 |
* that is generated from the parse. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
442 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
443 |
Writer.prototype.parse = function parse (template, tags) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
444 |
var cache = this.cache; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
445 |
var tokens = cache[template]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
446 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
447 |
if (tokens == null) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
448 |
tokens = cache[template] = parseTemplate(template, tags); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
449 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
450 |
return tokens; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
451 |
}; |
| 940 | 452 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
453 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
454 |
* High-level method that is used to render the given `template` with |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
455 |
* the given `view`. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
456 |
* |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
457 |
* The optional `partials` argument may be an object that contains the |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
458 |
* names and templates of partials that are used in the template. It may |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
459 |
* also be a function that is used to load partial templates on the fly |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
460 |
* that takes a single argument: the name of the partial. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
461 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
462 |
Writer.prototype.render = function render (template, view, partials) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
463 |
var tokens = this.parse(template); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
464 |
var context = (view instanceof Context) ? view : new Context(view); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
465 |
return this.renderTokens(tokens, context, partials, template); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
466 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
467 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
468 |
/** |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
469 |
* Low-level method that renders the given array of `tokens` using |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
470 |
* the given `context` and `partials`. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
471 |
* |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
472 |
* Note: The `originalTemplate` is only ever used to extract the portion |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
473 |
* of the original template that was contained in a higher-order section. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
474 |
* If the template doesn't use higher-order sections, this argument may |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
475 |
* be omitted. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
476 |
*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
477 |
Writer.prototype.renderTokens = function renderTokens (tokens, context, partials, originalTemplate) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
478 |
var buffer = ''; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
479 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
480 |
var token, symbol, value; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
481 |
for (var i = 0, numTokens = tokens.length; i < numTokens; ++i) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
482 |
value = undefined; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
483 |
token = tokens[i]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
484 |
symbol = token[0]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
485 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
486 |
if (symbol === '#') value = this.renderSection(token, context, partials, originalTemplate); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
487 |
else if (symbol === '^') value = this.renderInverted(token, context, partials, originalTemplate); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
488 |
else if (symbol === '>') value = this.renderPartial(token, context, partials, originalTemplate); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
489 |
else if (symbol === '&') value = this.unescapedValue(token, context); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
490 |
else if (symbol === 'name') value = this.escapedValue(token, context); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
491 |
else if (symbol === 'text') value = this.rawValue(token); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
492 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
493 |
if (value !== undefined) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
494 |
buffer += value; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
495 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
496 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
497 |
return buffer; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
498 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
499 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
500 |
Writer.prototype.renderSection = function renderSection (token, context, partials, originalTemplate) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
501 |
var self = this; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
502 |
var buffer = ''; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
503 |
var value = context.lookup(token[1]); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
504 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
505 |
// This function is used to render an arbitrary template |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
506 |
// in the current context by higher-order sections. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
507 |
function subRender (template) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
508 |
return self.render(template, context, partials); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
509 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
510 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
511 |
if (!value) return; |
| 940 | 512 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
513 |
if (isArray(value)) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
514 |
for (var j = 0, valueLength = value.length; j < valueLength; ++j) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
515 |
buffer += this.renderTokens(token[4], context.push(value[j]), partials, originalTemplate); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
516 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
517 |
} else if (typeof value === 'object' || typeof value === 'string' || typeof value === 'number') { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
518 |
buffer += this.renderTokens(token[4], context.push(value), partials, originalTemplate); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
519 |
} else if (isFunction(value)) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
520 |
if (typeof originalTemplate !== 'string') |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
521 |
throw new Error('Cannot use higher-order sections without the original template'); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
522 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
523 |
// Extract the portion of the original template that the section contains. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
524 |
value = value.call(context.view, originalTemplate.slice(token[3], token[5]), subRender); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
525 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
526 |
if (value != null) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
527 |
buffer += value; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
528 |
} else { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
529 |
buffer += this.renderTokens(token[4], context, partials, originalTemplate); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
530 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
531 |
return buffer; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
532 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
533 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
534 |
Writer.prototype.renderInverted = function renderInverted (token, context, partials, originalTemplate) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
535 |
var value = context.lookup(token[1]); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
536 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
537 |
// Use JavaScript's definition of falsy. Include empty arrays. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
538 |
// See https://github.com/janl/mustache.js/issues/186 |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
539 |
if (!value || (isArray(value) && value.length === 0)) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
540 |
return this.renderTokens(token[4], context, partials, originalTemplate); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
541 |
}; |
| 598 | 542 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
543 |
Writer.prototype.renderPartial = function renderPartial (token, context, partials) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
544 |
if (!partials) return; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
545 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
546 |
var value = isFunction(partials) ? partials(token[1]) : partials[token[1]]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
547 |
if (value != null) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
548 |
return this.renderTokens(this.parse(value), context, partials, value); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
549 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
550 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
551 |
Writer.prototype.unescapedValue = function unescapedValue (token, context) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
552 |
var value = context.lookup(token[1]); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
553 |
if (value != null) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
554 |
return value; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
555 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
556 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
557 |
Writer.prototype.escapedValue = function escapedValue (token, context) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
558 |
var value = context.lookup(token[1]); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
559 |
if (value != null) |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
560 |
return mustache.escape(value); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
561 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
562 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
563 |
Writer.prototype.rawValue = function rawValue (token) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
564 |
return token[1]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
565 |
}; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
566 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
567 |
mustache.name = 'mustache.js'; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
568 |
mustache.version = '2.1.3'; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
569 |
mustache.tags = [ '{{', '}}' ]; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
570 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
571 |
// All high-level mustache.* functions use this writer. |
| 940 | 572 |
var defaultWriter = new Writer(); |
| 598 | 573 |
|
| 940 | 574 |
/** |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
575 |
* Clears all cached templates in the default writer. |
| 940 | 576 |
*/ |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
577 |
mustache.clearCache = function clearCache () { |
| 940 | 578 |
return defaultWriter.clearCache(); |
579 |
}; |
|
580 |
||
581 |
/** |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
582 |
* Parses and caches the given template in the default writer and returns the |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
583 |
* array of tokens it contains. Doing this ahead of time avoids the need to |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
584 |
* parse templates on the fly as they are rendered. |
| 940 | 585 |
*/ |
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
586 |
mustache.parse = function parse (template, tags) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
587 |
return defaultWriter.parse(template, tags); |
| 940 | 588 |
}; |
| 598 | 589 |
|
| 940 | 590 |
/** |
591 |
* Renders the `template` with the given `view` and `partials` using the |
|
592 |
* default writer. |
|
593 |
*/ |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
594 |
mustache.render = function render (template, view, partials) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
595 |
if (typeof template !== 'string') { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
596 |
throw new TypeError('Invalid template! Template should be a "string" ' + |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
597 |
'but "' + typeStr(template) + '" was given as the first ' + |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
598 |
'argument for mustache#render(template, view, partials)'); |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
599 |
} |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
600 |
|
| 940 | 601 |
return defaultWriter.render(template, view, partials); |
602 |
}; |
|
| 598 | 603 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
604 |
// This is here for backwards compatibility with 0.4.x., |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
605 |
/*eslint-disable */ // eslint wants camel cased function name |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
606 |
mustache.to_html = function to_html (template, view, partials, send) { |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
607 |
/*eslint-enable*/ |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
608 |
|
| 940 | 609 |
var result = mustache.render(template, view, partials); |
| 598 | 610 |
|
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
611 |
if (isFunction(send)) { |
| 940 | 612 |
send(result); |
613 |
} else { |
|
614 |
return result; |
|
| 598 | 615 |
} |
616 |
}; |
|
617 |
||
|
1304
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
618 |
// Export the escaping function so that the user may override it. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
619 |
// See https://github.com/janl/mustache.js/issues/244 |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
620 |
mustache.escape = escapeHtml; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
621 |
|
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
622 |
// Export these mainly for testing, but also for advanced usage. |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
623 |
mustache.Scanner = Scanner; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
624 |
mustache.Context = Context; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
625 |
mustache.Writer = Writer; |
|
10974bff4dae
upgrade metadataplayer + publish enmi 14and 15
Yves-Marie Haussonne <1218002+ymph@users.noreply.github.com>
parents:
940
diff
changeset
|
626 |
|
| 940 | 627 |
})); |