%wasm
!echo $GONB_JUPYTER_ROOT
!echo $GONB_WASM_DIR
!echo $GONB_WASM_URL
%goflags --cover --covermode=set
/home/janpf /home/janpf/jupyter_files/eb626c95 /files/jupyter_files/eb626c95
!echo $GONB_WASM_DIR
/home/janpf/jupyter_files/eb626c95
github.com/janpfeifer/gonb/gonbui/wasm
and that the Gonb
variables are created.¶We want to first make sure we are using the gonbui/wasm
that we want to test (and not downloading
the latest release from the web).
!if [[ "${GONB_GIT_ROOT}" == "" ]] ; then \
echo "Please set GONB_GIT_ROOT before runnig this notebook!" 1>&2 ; \
else \
echo "ok" ; \
fi
ok
!*rm -f go.work && go work init && go work use . "${GONB_GIT_ROOT}"
%goworkfix
- Added replace rule for module "github.com/janpfeifer/gonb" to local directory "/home/janpf/Projects/gonb".
Now we are testing that:
GonbWasmArgs
is properly set and ParseFlags
works.DIV
is created, and that GonbWasmDivId
correctly points to it.%wasm
import (
"flag"
"github.com/janpfeifer/gonb/gonbui/wasm"
)
var flagX = flag.String("x", "", "the meaning of life, the universe, and everything")
%% --x=42
flag.Parse()
div := wasm.ById(GonbWasmDivId) // Div created for the wasm program.
var parts []string
parts = append(parts, fmt.Sprintf("Wasm File Directory: %s\n", GonbWasmDir))
parts = append(parts, fmt.Sprintf("Wasm URL: %s\n", GonbWasmUrl))
parts = append(parts, fmt.Sprintf("Wasm DIV tag id: %s\n", GonbWasmDivId))
parts = append(parts, fmt.Sprintf("The meaning of life, the universe, and everything: %s", *flagX))
div.SetInnerText(strings.Join(parts, ""))
%reset
* State reset: all memorized declarations discarded.
import (
"github.com/janpfeifer/gonb/gonbui"
)
%%
gonbui.DisplayHTML(`<div id="xxx"></div>`)
gonbui.ScriptJavascript(`
var x = document.getElementById("xxx");
x.innerText = "Hello world!";
`)