WebAssembly.DSL

Basic DSL for assembling HTML elements from blocks.

Summary

element(name, attributes \\ [], content)

Create HTML element in the assembly scope, possibly nesting a new scope

value(val)

Create any value in the assembly scope

void_element(name, attributes \\ [])

Create HTML void element (ie. element without content) in the assembly scope

Macros

element(name, attributes \\ [], content)

Create HTML element in the assembly scope, possibly nesting a new scope.

New scope for inner elements is created when this macro is called with a do-block.

Should be called inside the WebAssembly.Builder context.

Expects attributes to be Elixir keywords. They will get converted into HTML format. Underscores in keys will be converted to dash signs.

This macro is to be used by WebAssembly.HTML module, unless you want to invent your own elements.

Examples

iex> build element :div, do: (element :span, "foo")
["\n<div>", ["\n<span>", "foo", "</span>"], "</div>"]

iex> build(element :a,
iex>    [href: "#foo", data_toggle: "modal"], "bar")
iex> |> WebAssembly.Tools.Output.flush
"\n<a href=\"#foo\" data-toggle=\"modal\">bar</a>"
value(val)

Create any value in the assembly scope.

Should be called inside the WebAssembly.Builder context.

Please note there's no typechecking here and the final result will be treated as an iolist. Means: if unsure, put only strings here.

Examples

iex> build value "what are your values?"
["what are your values?"]
iex> build(element :foo, do: value "bar")
iex> |> WebAssembly.Tools.Output.flush
"\n<foo>bar</foo>"
void_element(name, attributes \\ [])

Create HTML void element (ie. element without content) in the assembly scope.

Should be called inside the WebAssembly.Builder context.

See element/3 for explanation on the format of attributes.

This macro is to be used by WebAssembly.HTML module, unless you want to invent your own elements.

Examples

iex> build(void_element :meta,
iex>    http_equiv: "Content-Type", content: "text/html")
iex> |> WebAssembly.Tools.Output.flush
"\n<meta http-equiv=\"Content-Type\" content=\"text/html\" />"