test: add WASM browser test harness
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
456adce73b
commit
e34c5c96c3
1 changed files with 50 additions and 0 deletions
50
cmd/wasm/test.html
Normal file
50
cmd/wasm/test.html
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
<!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>
|
||||||
Loading…
Add table
Reference in a new issue