-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathftl_preview.html
59 lines (50 loc) · 2.73 KB
/
ftl_preview.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
<html>
<head>
<title>FM</title>
<style>
.red {background:red;}
.green {background:green;}
</style>
</head>
<body>
<div id="node1"> </div>
<div id="node2"> </div>
<div id="node3"> </div>
<div id="node4"> </div>
<div id="node5"> </div>
<div id="node6"> </div>
<script src="freemarker.js" type="text/javascript" id="Any_0"></script>
<script type="text/javascript">
function doTemplate(template, context, node, expected) {
var text = freemarker.render(template, context);
//console.debug(text, expected);
node = document.getElementById(node);
node.innerHTML = text;
if (expected) {
node.className = expected==text ? 'green' : 'red';
}
}
var template1 = "<#list envelopes as envelope><div id=\"${envelope.id}\" class=\"amptpl_Block \">${envelope.title}"
+"</div><#if tipLink??><br/><a href=\"${tipLink}\">If you like this, tip this!</a> </#if><#if "
+"copyLink??><#if copyLinkOnClick??><a href=\"${copyLink}\" onclick=\"${copyLinkOnClick}\">copy"
+" this!</a><#else><a href=\"${copyLink}\">copy this!</a></#if></#if><hr/></#list>";
var expected1 = "<div id=\"1\" class=\"amptpl_Block \">Help</div><br/><a href=\"http://amplafi.net\">"
+"If you like this, tip this!</a> <a href=\"opa\" onclick=\"1\">copy this!</a><hr/>"
+"<div id=\"2\" class=\"amptpl_Block \">Hello</div><br/><a href=\"http://amplafi.net\">"
+"If you like this, tip this!</a> <a href=\"opa\" onclick=\"1\">copy this!</a><hr/>";
doTemplate(template1, { copyLink:'opa', copyLinkOnClick:'1', tipLink:'http://amplafi.net',
envelopes:[{id:1, title:'Help'}, {id:2, title:'Hello'}] }, 'node1', expected1);
var template2 = "Teams:<br /><#list teams as team>${team.name}<ul>"
+"<#list team.players as player><li>${player.name}</li></#list></ul></#list>";
var expected2 = "Teams:<br />PAO<ul><li>Ninis</li><li>Karagounis</li><li>Galinovich</li></ul>"
+ "AEK<ul><li>Blanco</li></ul>";
doTemplate(template2, { teams:[ {name:'PAO', players:[{name:'Ninis'}, {name:'Karagounis'}, {name:'Galinovich'}]},
{name:'AEK', players:[{name:'Blanco'}] } ]}, 'node2', expected2);
var template3 = "<#if s?size!=0>Data:<hr /><#list s as n>${n}.</#list><#else>No data.</#if>";
doTemplate(template3, {s:[]}, 'node3', "No data.");
doTemplate(template3, {s:['emi', 'andy']}, 'node4', "Data:<hr />emi.andy.");
doTemplate(template3, {s:[["12/07/2008 02:00",{"timeInMillis":1228608040000,"timeZoneID":"Europe/Athens"},null,null]]}, 'node5', "Data:<hr />12/07/2008 02:00.");
doTemplate(template3, {s:[{_render:function(){return this.data[0] + ' at ' + this.data[1].timeZoneID;},data:["12/07/2008 02:00",{"timeInMillis":1228608040000,"timeZoneID":"Europe/Athens"},null,null]}]}, 'node6', "Data:<hr />12/07/2008 02:00 at Europe/Athens.");
</script>
</body>
</html>