Packages
WebAssembly is a web DSL for Elixir. You create html structure straight using do blocks. Means, you can intermix html-building blocks with full Elixir syntax. DSL output is an iolist, which you can flatten to string, but better use is to just feed it to the socket (via Plug & Cowboy). WebAssem...
Current section
Files
Jump to
Current section
Files
lib/webassembly.ex
defmodule WebAssembly do
@moduledoc ~S"""
Wrapper module for assembling html elements from blocks into iolist.
The moving parts are: elements DSL (`WebAssembly.DSL`),
HTML macros (`WebAssembly.HTML`) and a context in which
they should be used, provided by Builder (`WebAssembly.Builder`).
These modules are automatically imported, so you just use:
use WebAssembly
builder do
div class: "container" do
n = get_the_size
if n > 1 do
ul do
for index <- 1..n, do:
li "item #{index}"
end
else
span "got only one item"
end
end
end
"""
# ^todo: mode docs on nesting, loops, partials ..etc
defmacro __using__(_opts) do
quote do
import WebAssembly.DSL
import WebAssembly.Builder
use WebAssembly.HTML
:ok
end
end
end