robin/maivi

a tiny cute lua web framework

git clone https://git.robinwobin.dev/robin/maivi

robinlua: clean element functions and typesa31ba2f

push-srxvuswpkqxx
780 B33 linesraw
1---@class H
2---@overload fun(tag: string, children: Displayable|Children): Element
3---@overload fun(children: Displayable|Children): Element
4local h = {}
5
6h.document = maivi.elem("!DOCTYPE html", { close = false })
7h.raw = maivi.elem(nil, { raw = true })
8h.comment = function(str)
9  str = maivi.str.escape(str)
10  return h.raw(string.format("<!-- %s -->", str))
11end
12
13-- svg
14h.path = maivi.elem("path", { empty = true })
15
16h.stylesheet = function(args)
17  args.rel = "stylesheet"
18  args.type = "text/css"
19  return h.link(args)
20end
21
22return maivi.defaulttable(h, maivi.elem, {
23  __call = function(_, tagorchildren, children)
24    local tag
25    if not children then
26      children = tagorchildren
27    else
28      tag = tagorchildren
29    end
30
31    return maivi.elem(tag)(children)
32  end,
33})