40 lines
1.5 KiB
Text
40 lines
1.5 KiB
Text
# build_more.ludic - <let name="{value}"/> names a value for the siblings after it, and
|
|
# <provide name="{value}"> gives it to everything inside, components included (React's context)
|
|
function bd_let(ui_st: mut UiState, k: UiTpl, e: UiEnv) -> UiEnv {
|
|
let le = env_new(ui_st, e)
|
|
for i in 0 .. len(k.keys) { env_bind(le, k.keys[i], ui_eval(ui_st, k.vals[i], e)) }
|
|
return le
|
|
}
|
|
function bd_provide(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []UiNode) -> void {
|
|
let cx = env_new(ui_st, e.ctx)
|
|
for i in 0 .. len(k.keys) { env_bind(cx, k.keys[i], ui_eval(ui_st, k.vals[i], e)) }
|
|
let pe = env_new(ui_st, e)
|
|
pe.ctx = cx
|
|
bd_kids(ui_st, k.kids, pe, key, out)
|
|
}
|
|
# a fragment's (or a template's) content: its elements, or its words as a text of their own
|
|
function bd_group(ui_st: mut UiState, k: UiTpl, e: UiEnv, key: string, out: []UiNode) -> void {
|
|
if k.text == null {
|
|
bd_kids(ui_st, k.kids, e, key, out)
|
|
return
|
|
}
|
|
let t = nd_take(ui_st)
|
|
t.kind = UI_TEXT
|
|
t.key = key
|
|
t.text = ui_tr(ui_st, ui_eval_text(ui_st, k.text, e))
|
|
t.env = e
|
|
push(out, t)
|
|
}
|
|
# text inside text - <p>Hi <b>there</b></p>, <h3><slot/></h3> - reads as one line of it
|
|
function el_inline(n: UiNode) -> void {
|
|
if n.kind != UI_TEXT or len(n.children) == 0 { return }
|
|
var s = n.text
|
|
for i in 0 .. len(n.children) {
|
|
let c = n.children[i]
|
|
el_inline(c)
|
|
if len(s) > 0 and len(c.text) > 0 { s = s + " " }
|
|
s = s + c.text
|
|
}
|
|
n.text = s
|
|
List.clear(n.children)
|
|
}
|