go-html/cmd/wasm/test.html

51 lines
1.6 KiB
HTML
Raw Normal View History

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>go-html WASM Test</title>
<style>
body { font-family: monospace; margin: 2em; }
pre { background: #f5f5f5; padding: 1em; overflow: auto; }
</style>
</head>
<body>
<h1>go-html WASM Test</h1>
<div>
<label>Variant: <input id="variant" value="HLCRF"></label>
</div>
<div>
<label>H: <input id="slot-H" value="Header"></label>
</div>
<div>
<label>C: <input id="slot-C" value="Main content"></label>
</div>
<div>
<label>F: <input id="slot-F" value="Footer"></label>
</div>
<button id="render-btn">Render</button>
<h2>Raw HTML Output</h2>
<pre id="raw"></pre>
<script src="wasm_exec.js"></script>
<script>
const go = new Go();
WebAssembly.instantiateStreaming(fetch("go-html.wasm"), go.importObject)
.then(result => {
go.run(result.instance);
document.title += " (loaded)";
});
document.getElementById("render-btn").addEventListener("click", function() {
const variant = document.getElementById("variant").value;
const slots = {
H: document.getElementById("slot-H").value,
C: document.getElementById("slot-C").value,
F: document.getElementById("slot-F").value,
};
const result = gohtml.renderToString(variant, "en", slots);
document.getElementById("raw").textContent = result;
});
</script>
</body>
</html>