Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/flyx/askew

code generator & framework for single-page GopherJS/WASM apps
https://github.com/flyx/askew

declarative-ui gopherjs wasm

Last synced: 10 days ago
JSON representation

code generator & framework for single-page GopherJS/WASM apps

Awesome Lists containing this project

README

        

Askew

A minimal framework for writing dynamic websites in pure Go

Askew defines a small meta-language based on HTML to define UI components you can use to build client-side web applications.
Its two purposes are to enable you to declaratively define your UI, and to provide glue between the DOM API and your Go code.

Askew provides a JavaScript backend, where the Go code is compiled to JavaScript via GopherJS, and a WASM backend, where the Go code is compiled to WebAssembly.
The WebAssembly depends on `wasm_exec.js`, the runtime for the WASM generated by the Go compiler.
Other than that, no JavaScript libraries are used.

Askew's user documentation is available [here](https://flyx.github.io/askew).
This readme contains developer information.

## How it works

### HTML Processing

Askew depends on a [forked version](https://github.com/flyx/net) of Go's [HTML5 parser](https://pkg.go.dev/golang.org/x/net/html).
This version has been modified to be able to properly process Askew's meta-elements.

The generated code will, on initialization, programmatically create a `` element for each component type, and base component instantiations on copies of that template.
Hooks on certain element, e.g. for binding or event capturing, are stored as paths into the DOM content of the template.
These paths are used on instantiation to identify the elements that need to get hooked.

This was considered a quick and robust way to implement the HTML meta processing, though it might not be the most elegant or performant one.
The biggest problem with using the HTML5 parser is that you can't get line or column numbers to do error reporting because the parser [does not track those](https://github.com/golang/go/issues/34302).

### Custom Syntax Processing

The custom syntax used in Askew's meta-elements and -attributes is parsed via a PEG grammar.
This grammar is defined in `parsers/grammar.peg`.
It uses [pointlander/peg](https://github.com/pointlander/peg) to generate Go code; you can invoke it with `go generate` in the `parsers` directory.

### Go Code Generation

Go code is generated via `text/template`.
`goimports` is used on the generated code to format it properly and remove unused imports.

## Documentation

The documentation pages are generated via [piranha/gostatic](github.com/piranha/gostatic).
The `site` directory contains the sources, from which the pages can be generated with `make`.
The resulting HTML files are moved into the `gh-pages` branch.

## License

MIT