-
Notifications
You must be signed in to change notification settings - Fork 27
/
playground.html
79 lines (68 loc) · 2.27 KB
/
playground.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width,initial-scale=1'>
<meta name='format-detection' content='telephone=no'>
<title>Teddy Templating Engine playground</title>
</head>
<body>
<main>
<header>
<h1>Teddy Templating Engine playground</h1>
</header>
<p>Play around with client-side templating on this page.</p>
<noscript><p><strong>Javascript must be enabled for client-side templating to work.</strong></p></noscript>
<dl>
<dt>Template:</dt>
<dd><textarea rows='11' cols='43' id='src'><if hello>
<p>{hello}</p>
</if>
<if blah>
<p>blah is present</p>
</if>
<else>
<p>no blah!</p>
</else></textarea></dd>
<dt>JSON model:</dt>
<dd><textarea rows='11' cols='43' id='json'>{"hello":"hello world!"}</textarea></dd>
</dl>
<p><button id='render'>Render!</button></p>
<dl>
<dt>Rendered iframe:</dt>
<dd id='rendered'></dd>
</dl>
</main>
<!-- include teddy library -->
<script src='https://cdn.jsdelivr.net/npm/teddy@latest/dist/teddy.min.js'></script>
<!-- uncomment this to do local testing -->
<!-- <script src='dist/teddy.js'></script> -->
<script>
(function () {
const i = document.createElement('iframe')
i.id = 'renderedframe'
document.getElementById('rendered').appendChild(i)
document.getElementById('render').onclick = function () {
let json, rendered
try {
json = JSON.parse(document.getElementById('json').value)
} catch (e) {
console.log(e)
window.alert('Teddy could not parse your JSON! Check console log for the error.')
}
try {
teddy.setTemplate('playground.html', document.getElementById('src').value) // eslint-disable-line
rendered = teddy.render('playground.html', json) // eslint-disable-line
} catch (e) {
console.log(e)
window.alert('Teddy could not compile the template! Check console log for the error.')
}
const idoc = document.getElementById('renderedframe').contentWindow.document
idoc.open()
idoc.write(rendered)
idoc.close()
}
})()
</script>
</body>
</html>