-
Notifications
You must be signed in to change notification settings - Fork 188
/
Copy pathmustache_sections.json
282 lines (282 loc) · 11.4 KB
/
mustache_sections.json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
{
"__ATTN__": "Do not edit this file; changes belong in the appropriate YAML file.",
"overview": "Section tags and End Section tags are used in combination to wrap a section\nof the template for iteration\n\nThese tags' content MUST be a non-whitespace character sequence NOT\ncontaining the current closing delimiter; each Section tag MUST be followed\nby an End Section tag with the same content within the same section.\n\nThis tag's content names the data to replace the tag. Name resolution is as\nfollows:\n 1) Split the name on periods; the first part is the name to resolve, any\n remaining parts should be retained.\n 2) Walk the context stack from top to bottom, finding the first context\n that is a) a hash containing the name as a key OR b) an object responding\n to a method with the given name.\n 3) If the context is a hash, the data is the value associated with the\n name.\n 4) If the context is an object and the method with the given name has an\n arity of 1, the method SHOULD be called with a String containing the\n unprocessed contents of the sections; the data is the value returned.\n 5) Otherwise, the data is the value returned by calling the method with\n the given name.\n 6) If any name parts were retained in step 1, each should be resolved\n against a context stack containing only the result from the former\n resolution. If any part fails resolution, the result should be considered\n falsey, and should interpolate as the empty string.\nIf the data is not of a list type, it is coerced into a list as follows: if\nthe data is truthy (e.g. `!!data == true`), use a single-element list\ncontaining the data, otherwise use an empty list.\n\nFor each element in the data list, the element MUST be pushed onto the\ncontext stack, the section MUST be rendered, and the element MUST be popped\noff the context stack.\n\nSection and End Section tags SHOULD be treated as standalone when\nappropriate.\n",
"tests": [
{
"name": "Truthy",
"data": {
"boolean": true
},
"expected": "\"This should be rendered.\"",
"template": "\"{{#boolean}}This should be rendered.{{/boolean}}\"",
"desc": "Truthy sections should have their contents rendered."
},
{
"name": "Falsey",
"data": {
"boolean": false
},
"expected": "\"\"",
"template": "\"{{#boolean}}This should not be rendered.{{/boolean}}\"",
"desc": "Falsey sections should have their contents omitted."
},
{
"name": "Context",
"data": {
"context": {
"name": "Joe"
}
},
"expected": "\"Hi Joe.\"",
"template": "\"{{#context}}Hi {{name}}.{{/context}}\"",
"desc": "Objects and hashes should be pushed onto the context stack."
},
{
"name": "Deeply Nested Contexts",
"data": {
"a": {
"one": 1
},
"b": {
"two": 2
},
"c": {
"three": 3
},
"d": {
"four": 4
},
"e": {
"five": 5
}
},
"expected": "1\n121\n12321\n1234321\n123454321\n1234321\n12321\n121\n1\n",
"template": "{{#a}}\n{{one}}\n{{#b}}\n{{one}}{{two}}{{one}}\n{{#c}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{#d}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{#e}}\n{{one}}{{two}}{{three}}{{four}}{{five}}{{four}}{{three}}{{two}}{{one}}\n{{/e}}\n{{one}}{{two}}{{three}}{{four}}{{three}}{{two}}{{one}}\n{{/d}}\n{{one}}{{two}}{{three}}{{two}}{{one}}\n{{/c}}\n{{one}}{{two}}{{one}}\n{{/b}}\n{{one}}\n{{/a}}\n",
"desc": "All elements on the context stack should be accessible."
},
{
"name": "List",
"data": {
"list": [
{
"item": 1
},
{
"item": 2
},
{
"item": 3
}
]
},
"expected": "\"123\"",
"template": "\"{{#list}}{{item}}{{/list}}\"",
"desc": "Lists should be iterated; list items should visit the context stack."
},
{
"name": "Empty List",
"data": {
"list": []
},
"expected": "\"\"",
"template": "\"{{#list}}Yay lists!{{/list}}\"",
"desc": "Empty lists should behave like falsey values."
},
{
"name": "Doubled",
"data": {
"two": "second",
"bool": true
},
"expected": "* first\n* second\n* third\n",
"template": "{{#bool}}\n* first\n{{/bool}}\n* {{two}}\n{{#bool}}\n* third\n{{/bool}}\n",
"desc": "Multiple sections per template should be permitted."
},
{
"name": "Nested (Truthy)",
"data": {
"bool": true
},
"expected": "| A B C D E |",
"template": "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |",
"desc": "Nested truthy sections should have their contents rendered."
},
{
"name": "Nested (Falsey)",
"data": {
"bool": false
},
"expected": "| A E |",
"template": "| A {{#bool}}B {{#bool}}C{{/bool}} D{{/bool}} E |",
"desc": "Nested falsey sections should be omitted."
},
{
"name": "Context Misses",
"data": {},
"expected": "[]",
"template": "[{{#missing}}Found key 'missing'!{{/missing}}]",
"desc": "Failed context lookups should be considered falsey."
},
{
"name": "Implicit Iterator - String",
"data": {
"list": [
"a",
"b",
"c",
"d",
"e"
]
},
"expected": "\"(a)(b)(c)(d)(e)\"",
"template": "\"{{#list}}({{.}}){{/list}}\"",
"desc": "Implicit iterators should directly interpolate strings."
},
{
"name": "Implicit Iterator - Integer",
"data": {
"list": [
1,
2,
3,
4,
5
]
},
"expected": "\"(1)(2)(3)(4)(5)\"",
"template": "\"{{#list}}({{.}}){{/list}}\"",
"desc": "Implicit iterators should cast integers to strings and interpolate."
},
{
"name": "Implicit Iterator - Decimal",
"data": {
"list": [
1.1,
2.2,
3.3,
4.4,
5.5
]
},
"expected": "\"(1.10)(2.20)(3.30)(4.40)(5.50)\"",
"template": "\"{{#list}}({{.}}){{/list}}\"",
"desc": "Implicit iterators should cast decimals to strings and interpolate."
},
{
"name": "Dotted Names - Truthy",
"data": {
"a": {
"b": {
"c": true
}
}
},
"expected": "\"Here\" == \"Here\"",
"template": "\"{{#a.b.c}}Here{{/a.b.c}}\" == \"Here\"",
"desc": "Dotted names should be valid for Section tags."
},
{
"name": "Dotted Names - Falsey",
"data": {
"a": {
"b": {
"c": false
}
}
},
"expected": "\"\" == \"\"",
"template": "\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"",
"desc": "Dotted names should be valid for Section tags."
},
{
"name": "Dotted Names - Broken Chains",
"data": {
"a": {}
},
"expected": "\"\" == \"\"",
"template": "\"{{#a.b.c}}Here{{/a.b.c}}\" == \"\"",
"desc": "Dotted names that cannot be resolved should be considered falsey."
},
{
"name": "Surrounding Whitespace",
"data": {
"boolean": true
},
"expected": " | \t|\t | \n",
"template": " | {{#boolean}}\t|\t{{/boolean}} | \n",
"desc": "Sections should not alter surrounding whitespace."
},
{
"name": "Internal Whitespace",
"data": {
"boolean": true
},
"expected": " | \n | \n",
"template": " | {{#boolean}} {{! Important Whitespace }}\n {{/boolean}} | \n",
"desc": "Sections should not alter internal whitespace."
},
{
"name": "Indented Inline Sections",
"data": {
"boolean": true
},
"expected": " YES\n GOOD\n",
"template": " {{#boolean}}YES{{/boolean}}\n {{#boolean}}GOOD{{/boolean}}\n",
"desc": "Single-line sections should not alter surrounding whitespace."
},
{
"name": "Standalone Lines",
"data": {
"boolean": true
},
"expected": "| This Is\n|\n| A Line\n",
"template": "| This Is\n{{#boolean}}\n|\n{{/boolean}}\n| A Line\n",
"desc": "Standalone lines should be removed from the template."
},
{
"name": "Indented Standalone Lines",
"data": {
"boolean": true
},
"expected": "| This Is\n|\n| A Line\n",
"template": "| This Is\n {{#boolean}}\n|\n {{/boolean}}\n| A Line\n",
"desc": "Indented standalone lines should be removed from the template."
},
{
"name": "Standalone Line Endings",
"data": {
"boolean": true
},
"expected": "|\r\n|",
"template": "|\r\n{{#boolean}}\r\n{{/boolean}}\r\n|",
"desc": "\"\\r\\n\" should be considered a newline for standalone tags."
},
{
"name": "Standalone Without Previous Line",
"data": {
"boolean": true
},
"expected": "#\n/",
"template": " {{#boolean}}\n#{{/boolean}}\n/",
"desc": "Standalone tags should not require a newline to precede them."
},
{
"name": "Standalone Without Newline",
"data": {
"boolean": true
},
"expected": "#\n/\n",
"template": "#{{#boolean}}\n/\n {{/boolean}}",
"desc": "Standalone tags should not require a newline to follow them."
},
{
"name": "Padding",
"data": {
"boolean": true
},
"expected": "|=|",
"template": "|{{# boolean }}={{/ boolean }}|",
"desc": "Superfluous in-tag whitespace should be ignored."
}
]
}