inheritance.js
1.98 KB
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
var Hogan = Hogan || require('./lib/hogan');
function doIt() {
var child = Hogan.compile('{{< intermediate }} {{$childcontent}} child content {{/childcontent}} {{/intermediate}}');
var intermediate = Hogan.compile('{{< parent}} {{$content}} intermediate content {{$childcontent}} ERROR {{/childcontent}} {{/content}} {{/parent}}');
var parent = Hogan.compile('Content:{{$content}} parent content{{/content}}');
var result = child.render({}, {intermediate: intermediate, parent: parent});
console.log("got: ", result);
console.log("expected:", "Content: intermediate content child content")
}
function doIt2() {
var child = Hogan.compile('{{< intermediate }}{{$childcontent}}child content{{/childcontent}}{{/intermediate}}');
var intermediate = Hogan.compile('{{< parent}} {{$content}} intermediate content {{/content}}{{$childcontent}} ERROR2 {{/childcontent}} {{/parent}}');
var parent = Hogan.compile('Content:{{$content}} parent content {{/content}}{{$childcontent}} ERROR1 {{/childcontent}}');
var result = child.render({}, {intermediate: intermediate, parent: parent});
console.log("got: ", result);
console.log("expected:", "Content: intermediate content child content")
}
function doIt3() {
Hogan.cache = {};
var child1 = Hogan.compile("{{<intermediate}}{{$content}}CHILD1{{/content}}{{/intermediate}}");
var child2 = Hogan.compile("{{<intermediate}}{{$content}}CHILD2{{/content}}{{/intermediate}}");
var intermediate = Hogan.compile("{{<parent}}{{$content}}INTERMEDIATE{{/content}}{{/parent}}");
var parent = Hogan.compile("Content: {{$content}}PARENT{{/content}}");
var s;
s = parent.render({}, {});
s = intermediate.render({}, {parent: parent});
s = child1.render({}, {intermediate: intermediate, parent: parent});
s = child2.render({}, {intermediate: intermediate, parent: parent});
console.log("got: ", s);
console.log("expected: ", "Content: CHILD2");
}
doIt3();