Skip to main content

Module interpolate

Module interpolate 

Source
Expand description

Resolving the {...} placeholders a template carries.

A <for> body and a fragment body are written with placeholders standing in for what the iteration or the instantiation brings: {row.name}, {$index}, {$theme}. Turning a template into an instance means walking the subtree and replacing each of them with the value its scope holds.

This lives here, below both consumers, because the desktop reconciler and the web emitter write the same text into the same node a tick apart. Two resolvers would drift, and a drift shows up as a page the browser rebuilds on load rather than adopts.

A placeholder whose scope is absent is left in the string verbatim, so the walk that owns that scope resolves it later: a fragment walk resolves its arguments and leaves {row.name} standing for the <for> walk inside it.

Structs§

Row
One iteration of a <for> body: the record its placeholders read and the index they count from.
Scope
The scopes a placeholder can resolve against.

Traits§

Globals
Where a global placeholder reads its value.

Functions§

carries_placeholder
Whether any string substitute_attrs resolves carries a {.
element_carries_placeholder
Whether anything a substitution resolves on element carries a {: its own strings, and the arguments a use site passes.
resolve
Replace every {...} token in text with what its scope holds.
substitute_attrs
The attributes to build an element with, once the placeholders in its own strings are resolved against scope.
substitute_element
Walk a template subtree, resolving every placeholder in its string-valued attributes and its text against scope.