summaryrefslogtreecommitdiff
path: root/specs/inheritance.json
blob: 809b69326ba8afcf75018c762a2bd331c9c1a0eb (plain)
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
{
  "__ATTN__": "Do not edit this file; changes belong in the appropriate YAML file.",
  "overview": "Parent tags are used to expand an external template into the current template,\nwith optional parameters delimited by block tags.\n\nThese tags' content MUST be a non-whitespace character sequence NOT containing\nthe current closing delimiter; each Parent tag MUST be followed by an End\nSection tag with the same content within the matching parent tag.\n\nBlock tags are used inside of parent tags to assign data onto the context\nstack prior to rendering the parent template. Outside of parent tags, block\ntags are used to indicate where value set in the parent tag should be placed.\nIf no value is set then the content in between the block tags, if any, is\nrendered.\n",
  "tests": [
    {
      "name": "Default",
      "desc": "Default content should be rendered if the block isn't overridden",
      "data": {
      },
      "template": "{{$title}}Default title{{/title}}\n",
      "expected": "Default title\n"
    },
    {
      "name": "Variable",
      "desc": "Default content renders variables",
      "data": {
        "bar": "baz"
      },
      "template": "{{$foo}}default {{bar}} content{{/foo}}\n",
      "expected": "default baz content\n"
    },
    {
      "name": "Triple Mustache",
      "desc": "Default content renders triple mustache variables",
      "data": {
        "bar": "<baz>"
      },
      "template": "{{$foo}}default {{{bar}}} content{{/foo}}\n",
      "expected": "default <baz> content\n"
    },
    {
      "name": "Sections",
      "desc": "Default content renders sections",
      "data": {
        "bar": {
          "baz": "qux"
        }
      },
      "template": "{{$foo}}default {{#bar}}{{baz}}{{/bar}} content{{/foo}}\n",
      "expected": "default qux content\n"
    },
    {
      "name": "Negative Sections",
      "desc": "Default content renders negative sections",
      "data": {
        "baz": "three"
      },
      "template": "{{$foo}}default {{^bar}}{{baz}}{{/bar}} content{{/foo}}\n",
      "expected": "default three content\n"
    },
    {
      "name": "Mustache Injection",
      "desc": "Mustache injection in default content",
      "data": {
        "bar": {
          "baz": "{{qux}}"
        }
      },
      "template": "{{$foo}}default {{#bar}}{{baz}}{{/bar}} content{{/foo}}\n",
      "expected": "default {{qux}} content\n"
    },
    {
      "name": "Inherit",
      "desc": "Default content rendered inside included templates",
      "data": {
      },
      "template": "{{<include}}{{/include}}\n",
      "partials": {
        "include": "{{$foo}}default content{{/foo}}"
      },
      "expected": "default content"
    },
    {
      "name": "Overridden content",
      "desc": "Overridden content",
      "data": {
      },
      "template": "{{<super}}{{$title}}sub template title{{/title}}{{/super}}",
      "partials": {
        "super": "...{{$title}}Default title{{/title}}..."
      },
      "expected": "...sub template title..."
    },
    {
      "name": "Data does not override block",
      "desc": "Provided data does not override data passed into parent",
      "data": {
        "var": "var in data"
      },
      "template": "{{<include}}{{$var}}var in template{{/var}}{{/include}}",
      "partials": {
        "include": "{{$var}}var in include{{/var}}"
      },
      "expected": "var in template"
    },
    {
      "name": "Data does not override block default",
      "desc": "Provided data does not override default value of block",
      "data": {
        "var": "var in data"
      },
      "template": "{{<include}}{{/include}}",
      "partials": {
        "include": "{{$var}}var in include{{/var}}"
      },
      "expected": "var in include"
    },
    {
      "name": "Overridden partial",
      "desc": "Overridden partial",
      "data": {
      },
      "template": "test {{<partial}}{{$stuff}}override{{/stuff}}{{/partial}}",
      "partials": {
        "partial": "{{$stuff}}...{{/stuff}}"
      },
      "expected": "test override"
    },
    {
      "name": "Two overridden partials",
      "desc": "Two overridden partials with different content",
      "data": {
      },
      "template": "test {{<partial}}{{$stuff}}override1{{/stuff}}{{/partial}} {{<partial}}{{$stuff}}override2{{/stuff}}{{/partial}}\n",
      "partials": {
        "partial": "|{{$stuff}}...{{/stuff}}{{$default}} default{{/default}}|"
      },
      "expected": "test |override1 default| |override2 default|\n"
    },
    {
      "name": "Override partial with newlines",
      "desc": "Override partial with newlines",
      "data": {
      },
      "template": "{{<partial}}{{$ballmer}}\npeaked\n\n:(\n{{/ballmer}}{{/partial}}",
      "partials": {
        "partial": "{{$ballmer}}peaking{{/ballmer}}"
      },
      "expected": "peaked\n\n:(\n"
    },
    {
      "name": "Inherit indentation",
      "desc": "Inherit indentation when overriding a partial",
      "data": {
      },
      "template": "{{<partial}}{{$nineties}}hammer time{{/nineties}}{{/partial}}",
      "partials": {
        "partial": "stop:\n  {{$nineties}}collaborate and listen{{/nineties}}\n"
      },
      "expected": "stop:\n  hammer time\n"
    },
    {
      "name": "Only one override",
      "desc": "Override one substitution but not the other",
      "data": {
      },
      "template": "{{<partial}}{{$stuff2}}override two{{/stuff2}}{{/partial}}",
      "partials": {
        "partial": "{{$stuff}}new default one{{/stuff}}, {{$stuff2}}new default two{{/stuff2}}"
      },
      "expected": "new default one, override two"
    },
    {
      "name": "Super template",
      "desc": "Super templates behave identically to partials when called with no parameters",
      "data": {
      },
      "template": "{{>include}}|{{<include}}{{/include}}",
      "partials": {
        "include": "{{$foo}}default content{{/foo}}"
      },
      "expected": "default content|default content"
    },
    {
      "name": "Recursion",
      "desc": "Recursion in inherited templates",
      "data": {
      },
      "template": "{{<include}}{{$foo}}override{{/foo}}{{/include}}",
      "partials": {
        "include": "{{$foo}}default content{{/foo}} {{$bar}}{{<include2}}{{/include2}}{{/bar}}",
        "include2": "{{$foo}}include2 default content{{/foo}} {{<include}}{{$bar}}don't recurse{{/bar}}{{/include}}"
      },
      "expected": "override override override don't recurse"
    },
    {
      "name": "Multi-level inheritance",
      "desc": "Top-level substitutions take precedence in multi-level inheritance",
      "data": {
      },
      "template": "{{<parent}}{{$a}}c{{/a}}{{/parent}}",
      "partials": {
        "parent": "{{<older}}{{$a}}p{{/a}}{{/older}}",
        "older": "{{<grandParent}}{{$a}}o{{/a}}{{/grandParent}}",
        "grandParent": "{{$a}}g{{/a}}"
      },
      "expected": "c"
    },
    {
      "name": "Multi-level inheritance, no sub child",
      "desc": "Top-level substitutions take precedence in multi-level inheritance",
      "data": {
      },
      "template": "{{<parent}}{{/parent}}",
      "partials": {
        "parent": "{{<older}}{{$a}}p{{/a}}{{/older}}",
        "older": "{{<grandParent}}{{$a}}o{{/a}}{{/grandParent}}",
        "grandParent": "{{$a}}g{{/a}}"
      },
      "expected": "p"
    },
    {
      "name": "Text inside super",
      "desc": "Ignores text inside super templates, but does parse $ tags",
      "data": {
      },
      "template": "{{<include}} asdfasd {{$foo}}hmm{{/foo}} asdfasdfasdf {{/include}}",
      "partials": {
        "include": "{{$foo}}default content{{/foo}}"
      },
      "expected": "hmm"
    },
    {
      "name": "Text inside super",
      "desc": "Allows text inside a super tag, but ignores it",
      "data": {
      },
      "template": "{{<include}} asdfasd asdfasdfasdf {{/include}}",
      "partials": {
        "include": "{{$foo}}default content{{/foo}}"
      },
      "expected": "default content"
    }
  ]
}