2150 |
mathias |
1 |
if(!dojo._hasResource["dojox.dtl.tests.text.tag"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
|
|
|
2 |
dojo._hasResource["dojox.dtl.tests.text.tag"] = true;
|
|
|
3 |
dojo.provide("dojox.dtl.tests.text.tag");
|
|
|
4 |
|
|
|
5 |
dojo.require("dojox.dtl");
|
|
|
6 |
|
|
|
7 |
doh.register("dojox.dtl.text.tag",
|
|
|
8 |
[
|
|
|
9 |
function test_tag_block_and_extends(t){
|
|
|
10 |
var dd = dojox.dtl;
|
|
|
11 |
|
|
|
12 |
// Simple (messy) string-based extension
|
|
|
13 |
var template = new dd.Template('{% extends "../../dojox/dtl/tests/text/templates/pocket.html" %}{% block pocket %}Simple{% endblock %}');
|
|
|
14 |
t.is("Simple Pocket", template.render());
|
|
|
15 |
|
|
|
16 |
// Variable replacement
|
|
|
17 |
var context = new dd.Context({
|
|
|
18 |
parent: "../../dojox/dtl/tests/text/templates/pocket.html"
|
|
|
19 |
})
|
|
|
20 |
template = new dd.Template('{% extends parent %}{% block pocket %}Variabled{% endblock %}');
|
|
|
21 |
t.is("Variabled Pocket", template.render(context));
|
|
|
22 |
|
|
|
23 |
// Nicer dojo.moduleUrl and variable based extension
|
|
|
24 |
context.parent = dojo.moduleUrl("dojox.dtl.tests.text.templates", "pocket.html");
|
|
|
25 |
template = new dd.Template('{% extends parent %}{% block pocket %}Slightly More Advanced{% endblock %}');
|
|
|
26 |
t.is("Slightly More Advanced Pocket", template.render(context));
|
|
|
27 |
|
|
|
28 |
// dojo.moduleUrl with support for more variables.
|
|
|
29 |
// This is important for HTML templates where the "shared" flag will be important.
|
|
|
30 |
context.parent = {
|
|
|
31 |
url: dojo.moduleUrl("dojox.dtl.tests.text.templates", "pocket.html")
|
|
|
32 |
}
|
|
|
33 |
template = new dd.Template('{% extends parent %}{% block pocket %}Super{% endblock %}');
|
|
|
34 |
t.is("Super Pocket", template.render(context));
|
|
|
35 |
},
|
|
|
36 |
function test_tag_comment(t){
|
|
|
37 |
var dd = dojox.dtl;
|
|
|
38 |
|
|
|
39 |
var template = new dd.Template('Hot{% comment %}<strong>Make me disappear</strong>{% endcomment %} Pocket');
|
|
|
40 |
t.is("Hot Pocket", template.render());
|
|
|
41 |
|
|
|
42 |
var found = false;
|
|
|
43 |
try {
|
|
|
44 |
template = new dd.Template('Hot{% comment %}<strong>Make me disappear</strong> Pocket');
|
|
|
45 |
}catch(e){
|
|
|
46 |
t.is("Unclosed tag found when looking for endcomment", e.message);
|
|
|
47 |
found = true;
|
|
|
48 |
}
|
|
|
49 |
t.t(found);
|
|
|
50 |
},
|
|
|
51 |
function test_tag_cycle(t){
|
|
|
52 |
var dd = dojox.dtl;
|
|
|
53 |
|
|
|
54 |
var context = new dd.Context({
|
|
|
55 |
items: ["apple", "banana", "lemon"],
|
|
|
56 |
unplugged: "Torrey"
|
|
|
57 |
});
|
|
|
58 |
var template = new dd.Template("{% for item in items %}{% cycle 'Hot' 'Diarrhea' unplugged 'Extra' %} Pocket. {% endfor %}");
|
|
|
59 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template.render(context));
|
|
|
60 |
// Make sure that it doesn't break on re-render
|
|
|
61 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template.render(context));
|
|
|
62 |
|
|
|
63 |
// Test repeating the loop
|
|
|
64 |
context.items.push("guava", "mango", "pineapple");
|
|
|
65 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. Extra Pocket. Hot Pocket. Diarrhea Pocket. ", template.render(context));
|
|
|
66 |
|
|
|
67 |
// Repeat the above tests for the old style
|
|
|
68 |
// ========================================
|
|
|
69 |
context.items = context.items.slice(0, 3);
|
|
|
70 |
template = new dd.Template("{% for item in items %}{% cycle Hot,Diarrhea,Torrey,Extra %} Pocket. {% endfor %}");
|
|
|
71 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template.render(context));
|
|
|
72 |
// Make sure that it doesn't break on re-render
|
|
|
73 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template.render(context));
|
|
|
74 |
|
|
|
75 |
// Test repeating the loop
|
|
|
76 |
context.items.push("guava", "mango", "pineapple");
|
|
|
77 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. Extra Pocket. Hot Pocket. Diarrhea Pocket. ", template.render(context));
|
|
|
78 |
|
|
|
79 |
// Now test outside of the for loop
|
|
|
80 |
// ================================
|
|
|
81 |
context = new dojox.dtl.Context({ unplugged: "Torrey" });
|
|
|
82 |
template = new dd.Template("{% cycle 'Hot' 'Diarrhea' unplugged 'Extra' as steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket.");
|
|
|
83 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket.", template.render(context));
|
|
|
84 |
|
|
|
85 |
template = new dd.Template("{% cycle 'Hot' 'Diarrhea' unplugged 'Extra' as steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket. {% cycle steakum %} Pocket.");
|
|
|
86 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. Extra Pocket. Hot Pocket. Diarrhea Pocket.", template.render(context));
|
|
|
87 |
|
|
|
88 |
// Test for nested objects
|
|
|
89 |
context.items = {
|
|
|
90 |
list: ["apple", "banana", "lemon"]
|
|
|
91 |
};
|
|
|
92 |
template = new dd.Template("{% for item in items.list %}{% cycle 'Hot' 'Diarrhea' unplugged 'Extra' %} Pocket. {% endfor %}");
|
|
|
93 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template.render(context));
|
|
|
94 |
// Make sure that it doesn't break on re-render
|
|
|
95 |
t.is("Hot Pocket. Diarrhea Pocket. Torrey Pocket. ", template.render(context));
|
|
|
96 |
},
|
|
|
97 |
function test_tag_debug(t){
|
|
|
98 |
var dd = dojox.dtl;
|
|
|
99 |
|
|
|
100 |
var context = new dd.Context({
|
|
|
101 |
items: ["apple", "banana", "lemon"],
|
|
|
102 |
unplugged: "Torrey"
|
|
|
103 |
});
|
|
|
104 |
var template = new dd.Template("{% debug %}");
|
|
|
105 |
t.is('items: ["apple", "banana", "lemon"]\n\nunplugged: "Torrey"\n\n', template.render(context));
|
|
|
106 |
},
|
|
|
107 |
function test_tag_filter(t){
|
|
|
108 |
var dd = dojox.dtl;
|
|
|
109 |
|
|
|
110 |
var template = new dd.Template('{% filter lower|center:"15" %}Hot Pocket{% endfilter %}');
|
|
|
111 |
t.is(" hot pocket ", template.render());
|
|
|
112 |
},
|
|
|
113 |
function test_tag_firstof(t){
|
|
|
114 |
t.t(false);
|
|
|
115 |
},
|
|
|
116 |
function test_tag_for(t){
|
|
|
117 |
t.t(false);
|
|
|
118 |
},
|
|
|
119 |
function test_tag_if(t){
|
|
|
120 |
t.t(false);
|
|
|
121 |
},
|
|
|
122 |
function test_tag_ifchanged(t){
|
|
|
123 |
t.t(false);
|
|
|
124 |
},
|
|
|
125 |
function test_tag_ifequal(t){
|
|
|
126 |
t.t(false);
|
|
|
127 |
},
|
|
|
128 |
function test_tag_ifnotequal(t){
|
|
|
129 |
t.t(false);
|
|
|
130 |
},
|
|
|
131 |
function test_tag_include(t){
|
|
|
132 |
t.t(false);
|
|
|
133 |
},
|
|
|
134 |
function test_tag_load(t){
|
|
|
135 |
t.t(false);
|
|
|
136 |
},
|
|
|
137 |
function test_tag_now(t){
|
|
|
138 |
t.t(false);
|
|
|
139 |
},
|
|
|
140 |
function test_tag_regroup(t){
|
|
|
141 |
t.t(false);
|
|
|
142 |
},
|
|
|
143 |
function test_tag_spaceless(t){
|
|
|
144 |
t.t(false);
|
|
|
145 |
},
|
|
|
146 |
function test_tag_ssi(t){
|
|
|
147 |
t.t(false);
|
|
|
148 |
},
|
|
|
149 |
function test_tag_templatetag(t){
|
|
|
150 |
t.t(false);
|
|
|
151 |
},
|
|
|
152 |
function test_tag_url(t){
|
|
|
153 |
t.t(false);
|
|
|
154 |
},
|
|
|
155 |
function test_tag_widthratio(t){
|
|
|
156 |
t.t(false);
|
|
|
157 |
},
|
|
|
158 |
function test_tag_with(t){
|
|
|
159 |
t.t(false);
|
|
|
160 |
}
|
|
|
161 |
]
|
|
|
162 |
);
|
|
|
163 |
|
|
|
164 |
}
|