-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathtest.html
95 lines (82 loc) · 1.59 KB
/
test.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<script src="mustache.js"></script>
<script>
var template = `
var is {{var}}
zero value is {{zerovar}}
undefined var is {{undefinedvar}}
nested object is
{{#obj}}
{{#goes}}
{{deep}}
{{/goes}}
{{/obj}}
dot syntax is {{obj.goes.deep}}
dot syntax in section is {{#obj.goes}}{{deep}}{{/obj.goes}}
list is
{{#list}}
{{item}}
{{/list}}
inverted is
{{^inverted}}
okay
{{/inverted}}
dot is
{{#dot}}
{{.}}
{{/dot}}
lambda is
{{#lambda}}
{{{raw}}}
{{/lambda}}
raw is {{{raw}}}
raw2 is {{&raw}}
comment is {{!not}} okay
partial is {{>partial}}
`
var expected = `
var is <okay>
zero value is 0
undefined var is
nested object is
okay
dot syntax is okay
dot syntax in section is okay
list is
okay
okay2
inverted is
okay
dot is
okay
lambda is
<b>
<okay>
okay</b>
raw is <okay>
raw2 is <okay>
comment is okay
partial is <okay>
`
var ctx = {
var: "<okay>",
obj: {goes: {deep: "okay"}},
list:[{item:"okay"},{item:"okay2"}],
dot: ["okay"],
raw: "<okay>",
inverted: false,
lambda: function (text, render) {
return "<b>" + render(text + this.dot[0]) + "</b>"
},
partial: "{{{var}}}",
zerovar: 0
}
var output = mustache(template, ctx)
var start = Date.now()
var n = 100
while (n--) {
mustache(template, ctx)
}
document.write("<pre>Rendered in " + (Date.now() - start) / 100 + "ms\n")
document.write("Test " + (output === expected ? "successful :)" : "FAILED :("))
console.log(output)
</script>