Add haste build (only partially working b/c of dependency on IO.)
Chris Pressey
5 years ago
10 | 10 | |
11 | 11 | # For this to work, you need hastec installed. |
12 | 12 | |
13 | #if command -v hastec >/dev/null 2>&1; then | |
14 | # echo "building $PROG.js with hastec" | |
15 | # (cd src && hastec --make HasteMain.hs -o ../demo/$PROG.js) | |
16 | #else | |
17 | # echo "hastec not found, not building $PROG.js" | |
18 | #fi | |
13 | if command -v hastec >/dev/null 2>&1; then | |
14 | echo "building $PROG.js with hastec" | |
15 | (cd src && hastec --make HasteMain.hs -o ../demo/$PROG.js) | |
16 | else | |
17 | echo "hastec not found, not building $PROG.js" | |
18 | fi |
0 | <!DOCTYPE html> | |
1 | <head> | |
2 | <meta charset="utf-8"> | |
3 | <title>Emmental</title> | |
4 | </head> | |
5 | <body> | |
6 | ||
7 | <h1>Emmental</h1> | |
8 | ||
9 | <p>(emmental.hs compiled to .js by <code>hastec</code>, running in HTML5 document)</p> | |
10 | ||
11 | <div id="installation"></div> | |
12 | ||
13 | <script src="../eg/examplePrograms.jsonp.js"></script> | |
14 | <script src="hastec-launcher.js"></script> | |
15 | <script src="emmental.js"></script> | |
16 | <script> | |
17 | launch({ | |
18 | container: document.getElementById('installation'), | |
19 | initialOption: "testprog10.emmental" | |
20 | }); | |
21 | </script> | |
22 | </body> |
0 | function launch(config) { | |
1 | config.container.innerHTML = ` | |
2 | <textarea id="prog" rows="10" cols="80"></textarea> | |
3 | <div id="control-panel"></div> | |
4 | <div><button id="run-button">Run</button></div> | |
5 | <pre id="result"></pre> | |
6 | `; | |
7 | ||
8 | function makeSelect(container, labelText, optionsArray, fun) { | |
9 | var label = document.createElement('label'); | |
10 | label.innerHTML = labelText; | |
11 | container.appendChild(label); | |
12 | var select = document.createElement("select"); | |
13 | for (var i = 0; i < optionsArray.length; i++) { | |
14 | var op = document.createElement("option"); | |
15 | op.text = optionsArray[i].filename; | |
16 | op.value = optionsArray[i].contents; | |
17 | select.options.add(op); | |
18 | } | |
19 | select.onchange = function(e) { | |
20 | fun(optionsArray[select.selectedIndex]); | |
21 | }; | |
22 | select.selectedIndex = 0; | |
23 | label.appendChild(select); | |
24 | return select; | |
25 | }; | |
26 | ||
27 | function selectOptionByText(selectElem, text) { | |
28 | var optElem; | |
29 | for (var i = 0; optElem = selectElem.options[i]; i++) { | |
30 | if (optElem.text === text) { | |
31 | selectElem.selectedIndex = i; | |
32 | selectElem.dispatchEvent(new Event('change')); | |
33 | return; | |
34 | } | |
35 | } | |
36 | } | |
37 | ||
38 | var controlPanel = document.getElementById('control-panel'); | |
39 | var select = makeSelect(controlPanel, "example program:", examplePrograms, function(option) { | |
40 | document.getElementById('prog').value = option.contents; | |
41 | }); | |
42 | selectOptionByText(select, config.initialOption); | |
43 | } |
0 | module Main where | |
1 | ||
2 | import Haste.DOM (withElems, getValue, setProp) | |
3 | import Haste.Events (onEvent, MouseEvent(Click)) | |
4 | ||
5 | import Emmental | |
6 | ||
7 | ||
8 | main = withElems ["prog", "result", "run-button"] driver | |
9 | ||
10 | driver [progElem, resultElem, runButtonElem] = | |
11 | onEvent runButtonElem Click $ \_ -> do | |
12 | Just prog <- getValue progElem | |
13 | r <- emmental prog | |
14 | setProp resultElem "textContent" $ show $ r |