template.bend checks
raw source on the hub · import bend-kit-template@0.3.1.0/template.bend as Template
Mustache templates: variables, sections, inverted sections, comments, partials, and set delimiters, with HTML escaping on by default.
3 imports
import Base import bend-kit-encoding@0.5.0.1/encoding.bend as Encoding import bend-kit-bytes@0.3.3.1/bytes.bend as Bytes
Types
type Value source · line 15 · raw
Data
A context value. A section repeats over a VList, hides on VBool{False{}} or an empty VList, and pushes any other value.
VStr@s:String -> Value
VBool@b:Bool -> Value
VList@xs:List<&2, Value> -> Value
VMap@m:Map<&2, Value> -> Value
type Node source · line 23 · raw
Data
A parsed template. A path is a dotted name split at its dots; the name "." is the empty path. NPart's ind is the whitespace before a standalone partial tag; it indents each line of the partial.
NText@s:String -> Node
NVar@path:List<&2, String> -> @raw:Bool -> Node
NSec@path:List<&2, String> -> @inv:Bool -> @body:List<&2, Node> -> Node
NPart@name:String -> @ind:String -> Node
type Tok source · line 29 · raw
Data
TText@s:String -> Tok
TVar@name:String -> Tok
TRaw@name:String -> Tok
TOpen@name:String -> Tok
TInv@name:String -> Tok
TClose@name:String -> Tok
TSkipTok
TDelim@open:String -> @close:String -> Tok
TPart@name:String -> @ind:String -> Tok
TBad@msg:String -> Tok
type Lex source · line 41 · raw
Data
LEnd@text:String -> Lex
LTag@text:String -> @tag:Tok -> @rest:String -> Lex
LErr@msg:String -> Lex
type Frame source · line 46 · raw
Data
Frame@name:String -> @inv:Bool -> @acc:List<&2, Node> -> Frame
type St source · line 49 · raw
Data
SOk@top:Frame -> @stack:List<&2, Frame> -> St
SErr@msg:String -> St
Definitions
def when source · line 7 · raw
@-A:Type -> @c:Bool -> @t:(@_:Unit -> A) -> @e:(@_:Unit -> A) -> A
Bool.pick evaluates both branches; when evaluates only the chosen one.
def escape.pick source · line 53 · raw
@amp:Bool -> @lt:Bool -> @gt:Bool -> @quot:Bool -> @apos:Bool -> @c:Char -> @rest:String -> String
def escape source · line 77 · raw
@s:String -> String
HTML text: & < > " ' become & < > " '.
def cut.go source · line 85 · raw
@+s:String -> @hit:Bool -> @+pat:String -> @acc:String -> Pair(String, Maybe<&2, String>)
def cut source · line 97 · raw
@+s:String -> @+pat:String -> Pair(String, Maybe<&2, String>)
s before the first pat, and Some of s after it; s and None when pat is absent.
def delim.pair source · line 100 · raw
@ws:List<&2, String> -> Tok
def delim.of source · line 107 · raw
@ok:Bool -> @t:String -> Tok
def delim source · line 115 · raw
@+t:String -> Tok
The body of {{=<% %>=}} after its first '=': two delimiters and a closing '='.
def tag.sigil.set source · line 118 · raw
@set:Bool -> @+c:U32 -> @+t:String -> Tok
def tag.sigil source · line 132 · raw
@+c:U32 -> @+t:String -> Tok
def tag.plain source · line 135 · raw
@name:String -> Tok
def tag.of source · line 142 · raw
@triple:Bool -> @name:String -> Tok
def lex.close source · line 149 · raw
@text:String -> @triple:Bool -> @p:Pair(String, Maybe<&2, String>) -> Lex
def lex.open source · line 157 · raw
@triple:Bool -> @text:String -> @+a:String -> @+c:String -> Lex
def lex.after source · line 164 · raw
@p:Pair(String, Maybe<&2, String>) -> @+c:String -> Lex
def lex source · line 173 · raw
@+o:String -> @+c:String -> @+src:String -> Lex
The text up to the next tag between delimiters o and c, the tag, and the rest.
def lex.with source · line 176 · raw
@d:Tok -> @+src:String -> Lex
def delims source · line 183 · raw
@t:Tok -> @d:Tok -> Tok
def toks.go source · line 191 · raw
@f:Nat -> @l:Lex -> @acc:List<&2, Tok> -> @d:Tok -> Result<&2, &2, String, List<&2, Tok>>
Every lex step eats a char, so length + 1 steps are enough. Texts and tags alternate. d is the TDelim in force.
def blank source · line 205 · raw
@+c:U32 -> Bool
def blank13 source · line 208 · raw
@+c:U32 -> Bool
def head_ok source · line 212 · raw
@s:String -> @last:Bool -> Bool
Is s blank up to its first LF? At the end of s, last decides.
def drop_blank source · line 220 · raw
@s:String -> String
def drop_chr source · line 228 · raw
@+k:U32 -> @s:String -> String
def trim_head source · line 236 · raw
@s:String -> String
def trim_tail source · line 239 · raw
@s:String -> String
def std.kind source · line 242 · raw
@t:Tok -> Bool
def last_line.go source · line 259 · raw
@s:String -> @+acc:String -> String
def last_line source · line 268 · raw
@s:String -> String
The text after the last LF of s.
def std.ind source · line 272 · raw
@t:Tok -> @+ind:String -> Tok
A partial tag takes ind as its indentation.
def std.go source · line 296 · raw
@toks:List<&2, Tok> -> @+orig:String -> @first:Bool -> @+cur:String -> @out:List<&2, Tok> -> List<&2, Tok>
orig is the text before the tag as lexed; cur is that text after its own head trim.
def std source · line 305 · raw
@toks:List<&2, Tok> -> List<&2, Tok>
A section, inverted, close, comment, set-delimiter, or partial tag alone on its line takes the line with it.
def path.of source · line 312 · raw
@+n:String -> List<&2, String>
def add source · line 315 · raw
@top:Frame -> @n:Node -> Frame
def close.pop source · line 320 · raw
@stack:List<&2, Frame> -> @+name:String -> @inv:Bool -> @acc:List<&2, Node> -> St
def close source · line 327 · raw
@same:Bool -> @+n:String -> @top:Frame -> @stack:List<&2, Frame> -> St
def close.of source · line 336 · raw
@+n:String -> @top:Frame -> @stack:List<&2, Frame> -> St
def step source · line 341 · raw
@st:St -> @t:Tok -> St
def tree.go source · line 368 · raw
@toks:List<&2, Tok> -> @st:St -> St
def tree.fin source · line 375 · raw
@st:St -> Result<&2, &2, String, List<&2, Node>>
def parse.tree source · line 386 · raw
@r:Result<&2, &2, String, List<&2, Tok>> -> Result<&2, &2, String, List<&2, Node>>
def parse source · line 394 · raw
@+src:String -> Result<&2, &2, String, List<&2, Node>>
The template as nodes, or Fail with why it is malformed.
def find.got source · line 397 · raw
@r:Pair(Map<&2, Value>, Value) -> Maybe<&2, Value>
def find.if source · line 401 · raw
@r:Pair(Map<&2, Value>, Bool) -> @+k:String -> Maybe<&2, Value>
def probe source · line 409 · raw
@v:Value -> @+k:String -> Maybe<&2, Value>
def first source · line 416 · raw
@a:Maybe<&2, Value> -> @b:(@_:Unit -> Maybe<&2, Value>) -> Maybe<&2, Value>
def resolve source · line 424 · raw
@stack:List<&2, Value> -> @+k:String -> Maybe<&2, Value>
The first value on the stack, innermost first, that is a map with key k.
def sub source · line 431 · raw
@mv:Maybe<&2, Value> -> @+k:String -> Maybe<&2, Value>
def dig source · line 438 · raw
@path:List<&2, String> -> @mv:Maybe<&2, Value> -> Maybe<&2, Value>
def top source · line 445 · raw
@stack:List<&2, Value> -> Maybe<&2, Value>
def lookup source · line 453 · raw
@path:List<&2, String> -> @+stack:List<&2, Value> -> Maybe<&2, Value>
Only the first part of a dotted name searches the stack.
def show source · line 460 · raw
@raw:Bool -> @v:Maybe<&2, Value> -> String
def truthy source · line 469 · raw
@v:Maybe<&2, Value> -> Bool
def items.of source · line 480 · raw
@v:Maybe<&2, Value> -> List<&2, Value>
def sec.items source · line 494 · raw
@inv:Bool -> @+v:Maybe<&2, Value> -> List<&2, Value>
The values a section's body renders once each against.
def indent source · line 502 · raw
@ind:String -> @+s:String -> String
Each LF in partial text is followed by the partial's indentation.
def undent source · line 510 · raw
@+ind:String -> @+s:String -> String
Drops the indentation that indent left after the partial's last LF.
def part.got source · line 516 · raw
@r:Pair(Map<&2, List<&2, Node>>, List<&2, Node>) -> List<&2, Node>
def part source · line 521 · raw
@+ps:Map<&2, List<&2, Node>> -> @+n:String -> List<&2, Node>
A missing partial renders as nothing.
def go source · line 525 · raw
@f:Nat -> @nodes:List<&2, Node> -> @items:List<&2, Value> -> @iter:Bool -> @+ps:Map<&2, List<&2, Node>> -> @+stack:List<&2, Value> -> @+ind:String -> @tail:String -> String
f bounds partial nesting. iter renders nodes once per item, each pushed on the stack; otherwise it renders nodes once.
def render_with source · line 546 · raw
@nodes:List<&2, Node> -> @ctx:Map<&2, Value> -> @partials:Map<&2, List<&2, Node>> -> String
The nodes rendered against ctx, with {{> name}} taken from partials. Partials nest at most 64 deep; a deeper one renders as nothing.
def render source · line 550 · raw
@nodes:List<&2, Node> -> @ctx:Map<&2, Value> -> String
The nodes rendered against ctx. A partial renders as nothing.
def render_text.of source · line 553 · raw
@r:Result<&2, &2, String, List<&2, Node>> -> @ctx:Map<&2, Value> -> Result<&2, &2, String, String>
def render_text source · line 561 · raw
@+src:String -> @ctx:Map<&2, Value> -> Result<&2, &2, String, String>
parse, then render.
def packed.reserve source · line 564 · raw
@+s:String -> @o:0xe0126415561194eca594bb57287bdd1d/encoding.Out -> @+factor:U32 -> 0xe0126415561194eca594bb57287bdd1d/encoding.Out
def packed.text source · line 568 · raw
@+s:String -> @o:0xe0126415561194eca594bb57287bdd1d/encoding.Out -> 0xe0126415561194eca594bb57287bdd1d/encoding.Out
def packed.escaped source · line 571 · raw
@s:String -> @o:0xe0126415561194eca594bb57287bdd1d/encoding.Out -> 0xe0126415561194eca594bb57287bdd1d/encoding.Out
def packed.string source · line 578 · raw
@raw:Bool -> @+s:String -> @o:0xe0126415561194eca594bb57287bdd1d/encoding.Out -> 0xe0126415561194eca594bb57287bdd1d/encoding.Out
def packed.value source · line 585 · raw
@raw:Bool -> @v:Maybe<&2, Value> -> @o:0xe0126415561194eca594bb57287bdd1d/encoding.Out -> 0xe0126415561194eca594bb57287bdd1d/encoding.Out
def packed.resume.at source · line 594 · raw
@+n:U32 -> @+r:U32 -> @p:Pair(Array<U32>, U32) -> 0xe0126415561194eca594bb57287bdd1d/encoding.Out
def packed.resume.if source · line 598 · raw
@full:Bool -> @+n:U32 -> @buf:Array<U32> -> 0xe0126415561194eca594bb57287bdd1d/encoding.Out
def packed.resume source · line 605 · raw
@b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> 0xe0126415561194eca594bb57287bdd1d/encoding.Out
def packed.trim.got source · line 609 · raw
@r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes) -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes
def packed.trim.pick source · line 613 · raw
@cut:Bool -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> @+n:U32 -> @+i:U32 -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes
def packed.trim.suffix source · line 620 · raw
@+ind:String -> @+n:U32 -> @r:Pair(0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes, Bool) -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes
def packed.trim source · line 624 · raw
@+ind:String -> @b:0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes
def packed.go source · line 628 · raw
@f:Nat -> @nodes:List<&2, Node> -> @items:List<&2, Value> -> @iter:Bool -> @+ps:Map<&2, List<&2, Node>> -> @+stack:List<&2, Value> -> @+ind:String -> @out:0xe0126415561194eca594bb57287bdd1d/encoding.Out -> 0xe0126415561194eca594bb57287bdd1d/encoding.Out
def render_bytes_with source · line 649 · raw
@nodes:List<&2, Node> -> @ctx:Map<&2, Value> -> @partials:Map<&2, List<&2, Node>> -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes
Render UTF-8 directly into packed bytes, with the same partial rules as render_with.
def render_bytes source · line 653 · raw
@nodes:List<&2, Node> -> @ctx:Map<&2, Value> -> 0xec25e4adfb02e59e4b817801115988ee/bytes.Bytes
Render UTF-8 directly into packed bytes without partials.