Skip to content
This repository was archived by the owner on Apr 4, 2019. It is now read-only.

Commit 72a5663

Browse files
author
Godhuda
committed
Improve the ergonomics of the demo
1 parent 9bedd3c commit 72a5663

File tree

1 file changed

+46
-30
lines changed

1 file changed

+46
-30
lines changed

demos/compile-and-run.html

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,58 @@
11
<html>
22
<head>
33
<title>HTMLBars example</title>
4+
<style type="text/css">
5+
#inputs {
6+
overflow: hidden;
7+
}
8+
9+
#inputs label {
10+
float: left;
11+
}
12+
13+
#inputs textarea {
14+
display: block;
15+
width: 300px;
16+
height: 150px;
17+
margin: 5px 10px 5px 0px;
18+
font-family: monospace;
19+
}
20+
</style>
421
</head>
522
<body>
6-
<label>
7-
Data
8-
<textarea id="data">{"name": "Bob"}</textarea>
9-
</label>
10-
11-
<label>
12-
Template
13-
<textarea id="template">Howdy {{name}}</textarea>
14-
</label>
15-
16-
<label>
17-
Options
18-
<textarea id="options">{ "disableComponentGeneration": true }</textarea>
19-
</label>
20-
21-
<label>
22-
<input id="skip-render" type="checkbox">
23-
Skip render?
24-
</label>
25-
26-
<button id="run-template">Compile and Render</button>
23+
<div id="inputs">
24+
<label>
25+
Data
26+
<textarea id="data">{"name": "Bob"}</textarea>
27+
</label>
28+
29+
<label>
30+
Template
31+
<textarea id="template">Howdy {{name}}</textarea>
32+
</label>
33+
34+
<label>
35+
Options
36+
<textarea id="options">{ "disableComponentGeneration": true }</textarea>
37+
</label>
38+
</div>
39+
40+
<div id="actions">
41+
<button id="compile-template">Compile</button>
42+
<button id="run-template">Compile and Render</button>
43+
</div>
44+
2745
<hr>
46+
2847
<div id="output"></div>
2948

3049
<script src="../assets/loader.js"></script>
3150
<script src="../amd/dom-helper.amd.js"></script>
3251
<script src="../amd/htmlbars-compiler.amd.js"></script>
3352
<script src="../amd/htmlbars-runtime.amd.js"></script>
3453
<script>
35-
var button = document.getElementById('run-template'),
54+
var compileBtn = document.getElementById('compile-template'),
55+
runBtn = document.getElementById('run-template'),
3656
dataarea = document.getElementById('data'),
3757
textarea = document.getElementById('template'),
3858
output = document.getElementById('output'),
@@ -46,7 +66,6 @@
4666

4767
var templateSource = localStorage.getItem('templateSource');
4868
var data = localStorage.getItem('templateData');
49-
var shouldRender = localStorage.getItem('shouldRender');
5069

5170
if (templateSource) {
5271
textarea.value = templateSource;
@@ -56,19 +75,16 @@
5675
dataarea.value = data;
5776
}
5877

59-
if (shouldRender === "false") {
60-
skipRender.checked = true;
61-
}
78+
compileBtn.addEventListener('click', function() { compile(false); });
79+
runBtn.addEventListener('click', function() { compile(true); });
6280

63-
button.addEventListener('click', function() {
81+
function compile(shouldRender) {
6482
var source = textarea.value,
6583
data = dataarea.value,
66-
shouldRender = !skipRender.checked,
6784
compileOptions;
6885

6986
localStorage.setItem('templateSource', source);
7087
localStorage.setItem('templateData', data);
71-
localStorage.setItem('shouldRender', shouldRender);
7288

7389
try {
7490
data = JSON.parse(data);
@@ -104,7 +120,7 @@
104120
output.innerHTML += 'Failure to run template: '+e.message;
105121
throw(e);
106122
}
107-
});
123+
}
108124
</script>
109125
</body>
110126
</html>

0 commit comments

Comments
 (0)