template.bend checks
raw source on the hub · import bend-kit-template@0.4.0.1/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.2/encoding.bend as Encoding import bend-kit-bytes@0.3.3.2/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.
NLineNode
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 30 · raw
Data
TLineTok
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 43 · raw
Data
LEnd@text:String -> Lex
LTag@text:String -> @tag:Tok -> @rest:String -> Lex
LErr@msg:String -> Lex
type Frame source · line 48 · raw
Data
Frame@name:String -> @inv:Bool -> @acc:List<&2, Node> -> Frame
type St source · line 51 · 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 55 · raw
@amp:Bool -> @lt:Bool -> @gt:Bool -> @quot:Bool -> @apos:Bool -> @c:Char -> @rest:String -> String
def escape source · line 79 · raw
@s:String -> String
HTML text: & < > " ' become & < > " '.
def cut.go source · line 87 · raw
@+s:String -> @hit:Bool -> @+pat:String -> @acc:String -> Pair(String, Maybe<&2, String>)
def cut source · line 99 · 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 102 · raw
@ws:List<&2, String> -> Tok
def delim.of source · line 109 · raw
@ok:Bool -> @t:String -> Tok
def delim source · line 117 · raw
@+t:String -> Tok
The body of {{=<% %>=}} after its first '=': two delimiters and a closing '='.
def tag.sigil.set source · line 120 · raw
@set:Bool -> @+c:U32 -> @+t:String -> Tok
def tag.sigil source · line 134 · raw
@+c:U32 -> @+t:String -> Tok
def tag.plain source · line 137 · raw
@name:String -> Tok
def tag.of source · line 144 · raw
@triple:Bool -> @name:String -> Tok
def lex.close source · line 151 · raw
@text:String -> @triple:Bool -> @p:Pair(String, Maybe<&2, String>) -> Lex
def lex.open source · line 159 · raw
@triple:Bool -> @text:String -> @+a:String -> @+c:String -> Lex
def lex.after source · line 166 · raw
@p:Pair(String, Maybe<&2, String>) -> @+c:String -> Lex
def lex source · line 175 · 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 178 · raw
@d:Tok -> @+src:String -> Lex
def delims source · line 185 · raw
@t:Tok -> @d:Tok -> Tok
def toks.go source · line 193 · 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 207 · raw
@+c:U32 -> Bool
def blank13 source · line 210 · raw
@+c:U32 -> Bool
def head_ok source · line 214 · 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 222 · raw
@s:String -> String
def drop_chr source · line 230 · raw
@+k:U32 -> @s:String -> String
def trim_head source · line 238 · raw
@s:String -> String
def trim_tail source · line 241 · raw
@s:String -> String
def std.kind source · line 244 · raw
@t:Tok -> Bool
def last_line.go source · line 261 · raw
@s:String -> @+acc:String -> String
def last_line source · line 270 · raw
@s:String -> String
The text after the last LF of s.
def std.ind source · line 274 · raw
@t:Tok -> @+ind:String -> Tok
A partial tag takes ind as its indentation.
def line.text source · line 299 · raw
@+s:String -> @line:Bool -> @+out:List<&2, Tok> -> List<&2, Tok>
def line.mark source · line 303 · raw
@s:String -> @+line:Bool -> @+tag:Bool -> @+acc:String -> @+out:List<&2, Tok> -> List<&2, Tok>
def std.go source · line 314 · raw
@toks:List<&2, Tok> -> @+orig:String -> @first:Bool -> @+cur:String -> @line:Bool -> @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 323 · 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 330 · raw
@+n:String -> List<&2, String>
def add source · line 333 · raw
@top:Frame -> @n:Node -> Frame
def close.pop source · line 338 · raw
@stack:List<&2, Frame> -> @+name:String -> @inv:Bool -> @acc:List<&2, Node> -> St
def close source · line 345 · raw
@same:Bool -> @+n:String -> @top:Frame -> @stack:List<&2, Frame> -> St
def close.of source · line 354 · raw
@+n:String -> @top:Frame -> @stack:List<&2, Frame> -> St
def step source · line 359 · raw
@st:St -> @t:Tok -> St
def tree.go source · line 388 · raw
@toks:List<&2, Tok> -> @st:St -> St
def tree.fin source · line 395 · raw
@st:St -> Result<&2, &2, String, List<&2, Node>>
def parse.tree source · line 406 · raw
@r:Result<&2, &2, String, List<&2, Tok>> -> Result<&2, &2, String, List<&2, Node>>
def parse source · line 414 · 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 417 · raw
@r:Pair(Map<&2, Value>, Value) -> Maybe<&2, Value>
def find.if source · line 421 · raw
@r:Pair(Map<&2, Value>, Bool) -> @+k:String -> Maybe<&2, Value>
def probe source · line 429 · raw
@v:Value -> @+k:String -> Maybe<&2, Value>
def first source · line 436 · raw
@a:Maybe<&2, Value> -> @b:(@_:Unit -> Maybe<&2, Value>) -> Maybe<&2, Value>
def resolve source · line 444 · 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 451 · raw
@mv:Maybe<&2, Value> -> @+k:String -> Maybe<&2, Value>
def dig source · line 458 · raw
@path:List<&2, String> -> @mv:Maybe<&2, Value> -> Maybe<&2, Value>
def top source · line 465 · raw
@stack:List<&2, Value> -> Maybe<&2, Value>
def lookup source · line 473 · 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 480 · raw
@raw:Bool -> @v:Maybe<&2, Value> -> String
def truthy source · line 489 · raw
@v:Maybe<&2, Value> -> Bool
def items.of source · line 500 · raw
@v:Maybe<&2, Value> -> List<&2, Value>
def sec.items source · line 514 · raw
@inv:Bool -> @+v:Maybe<&2, Value> -> List<&2, Value>
The values a section's body renders once each against.
def part.got source · line 521 · raw
@r:Pair(Map<&2, List<&2, Node>>, List<&2, Node>) -> List<&2, Node>
def part source · line 526 · raw
@+ps:Map<&2, List<&2, Node>> -> @+n:String -> List<&2, Node>
A missing partial renders as nothing.
def go source · line 530 · 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 552 · 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 556 · 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 559 · raw
@r:Result<&2, &2, String, List<&2, Node>> -> @ctx:Map<&2, Value> -> Result<&2, &2, String, String>
def render_text source · line 567 · raw
@+src:String -> @ctx:Map<&2, Value> -> Result<&2, &2, String, String>
parse, then render.
def packed.reserve source · line 570 · raw
@+s:String -> @o:0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out -> @+factor:U32 -> 0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out
def packed.text source · line 574 · raw
@+s:String -> @o:0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out -> 0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out
def packed.escaped source · line 577 · raw
@s:String -> @o:0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out -> 0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out
def packed.string source · line 584 · raw
@raw:Bool -> @+s:String -> @o:0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out -> 0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out
def packed.value source · line 591 · raw
@raw:Bool -> @v:Maybe<&2, Value> -> @o:0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out -> 0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out
def packed.go source · line 600 · 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:0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out -> 0x09d3d9053ea07e5ef20d335e01928b1c/encoding.Out
def render_bytes_with source · line 622 · raw
@nodes:List<&2, Node> -> @ctx:Map<&2, Value> -> @partials:Map<&2, List<&2, Node>> -> 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes
Render UTF-8 directly into packed bytes, with the same partial rules as render_with.
def render_bytes source · line 626 · raw
@nodes:List<&2, Node> -> @ctx:Map<&2, Value> -> 0x166a26e38c43ec5f8fe3323f5850e3d8/bytes.Bytes
Render UTF-8 directly into packed bytes without partials.