Xml expressions
Xml expressions are function calls in the form of xml tags, optimized for generating HTML5 views.
Tagnames matching an existing identifier are mapped to that identifier. The tag <greet />
becomes a function call greet()
.
Lowercase tagnames in the form xxx
are not defined, they are converted to function calls pkg.Xxx()
, where pkg
is the package where the function's first output type is defined in.
So if a function's output type is live.View
, the tag <div></div>
becomes the call live.Div()
.
Tagnames containing a dot in the form A.B
are converted to function calls A.B()
.
So the tag <person.Greet />
becomes a function call person.Greet()
.
To pass named arguments in the call, the function must be defined with the inputs wrapped in braces.
To allow using adhoc xml attributes, define the last input argument to be of type ...map[string]any
.
This functions as a catcha-all, similar to variadic arguments, but for named arguments. The xml attribute names are stored unchanged.
The subtree, if provided, will be passed as the attribute main
. Its type will be inferred from the function definition, with the following constraint. Inputs must be inout variables, with the name and type passed through identically from the call site. This improves readability, ensures that there will be no variables appearing in the source without a definition.
Pass named subtrees using the form <subtree:>...</subtree:>
.
Alternatively, subtrees can also be passed as attributes.
Embed expressions within tagnames using the form {expression}
.
Embed statements within tagnames using the form {{expression}}
.
Embed raw HTML by converting to string to live.HtmlString type.