template.bend checks
raw source on the hub · import bend-kit-template@0.2.0.0/template.bend as Template
Mustache templates: variables, sections, inverted sections, comments, partials, and set delimiters, with HTML escaping on by default.
1 import
import Base
Types
type Value source · line 5 · 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 13 · 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 19 · 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 31 · raw
Data
LEnd@text:String -> Lex
LTag@text:String -> @tag:Tok -> @rest:String -> Lex
LErr@msg:String -> Lex
type Frame source · line 36 · raw
Data
Frame@name:String -> @inv:Bool -> @acc:List<&2, Node> -> Frame
type St source · line 39 · raw
Data
SOk@top:Frame -> @stack:List<&2, Frame> -> St
SErr@msg:String -> St
Definitions
def escape.pick source · line 43 · raw
@amp:Bool -> @lt:Bool -> @gt:Bool -> @quot:Bool -> @apos:Bool -> @c:Char -> @rest:String -> String
def escape source · line 67 · raw
@s:String -> String
HTML text: & < > " ' become & < > " '.
def cut.go source · line 75 · raw
@+s:String -> @hit:Bool -> @+pat:String -> @acc:String -> Pair(String, Maybe<&2, String>)
def cut source · line 87 · 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 90 · raw
@ws:List<&2, String> -> Tok
def delim.of source · line 97 · raw
@ok:Bool -> @t:String -> Tok
def delim source · line 105 · raw
@+t:String -> Tok
The body of {{=<% %>=}} after its first '=': two delimiters and a closing '='.
def tag.sigil.set source · line 108 · raw
@set:Bool -> @+c:U32 -> @+t:String -> Tok
def tag.sigil source · line 122 · raw
@+c:U32 -> @+t:String -> Tok
def tag.plain source · line 125 · raw
@name:String -> Tok
def tag.of source · line 132 · raw
@triple:Bool -> @name:String -> Tok
def lex.close source · line 139 · raw
@text:String -> @triple:Bool -> @p:Pair(String, Maybe<&2, String>) -> Lex
def lex.open source · line 147 · raw
@triple:Bool -> @text:String -> @+a:String -> @+c:String -> Lex
def lex.after source · line 154 · raw
@p:Pair(String, Maybe<&2, String>) -> @+c:String -> Lex
def lex source · line 163 · 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 166 · raw
@d:Tok -> @+src:String -> Lex
def delims source · line 173 · raw
@t:Tok -> @d:Tok -> Tok
def toks.go source · line 181 · 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 195 · raw
@+c:U32 -> Bool
def blank13 source · line 198 · raw
@+c:U32 -> Bool
def head_ok source · line 202 · 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 210 · raw
@s:String -> String
def drop_chr source · line 218 · raw
@+k:U32 -> @s:String -> String
def trim_head source · line 226 · raw
@s:String -> String
def trim_tail source · line 229 · raw
@s:String -> String
def std.kind source · line 232 · raw
@t:Tok -> Bool
def last_line.go source · line 249 · raw
@s:String -> @+acc:String -> String
def last_line source · line 258 · raw
@s:String -> String
The text after the last LF of s.
def std.ind source · line 262 · raw
@t:Tok -> @+ind:String -> Tok
A partial tag takes ind as its indentation.
def std.go source · line 286 · 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 295 · 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 302 · raw
@+n:String -> List<&2, String>
def add source · line 305 · raw
@top:Frame -> @n:Node -> Frame
def close.pop source · line 310 · raw
@stack:List<&2, Frame> -> @+name:String -> @inv:Bool -> @acc:List<&2, Node> -> St
def close source · line 317 · raw
@same:Bool -> @+n:String -> @top:Frame -> @stack:List<&2, Frame> -> St
def close.of source · line 326 · raw
@+n:String -> @top:Frame -> @stack:List<&2, Frame> -> St
def step source · line 331 · raw
@st:St -> @t:Tok -> St
def tree.go source · line 358 · raw
@toks:List<&2, Tok> -> @st:St -> St
def tree.fin source · line 365 · raw
@st:St -> Result<&2, &2, String, List<&2, Node>>
def parse.tree source · line 376 · raw
@r:Result<&2, &2, String, List<&2, Tok>> -> Result<&2, &2, String, List<&2, Node>>
def parse source · line 384 · 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 387 · raw
@r:Pair(Map<&2, Value>, Value) -> Maybe<&2, Value>
def find.if source · line 391 · raw
@r:Pair(Map<&2, Value>, Bool) -> @+k:String -> Maybe<&2, Value>
def probe source · line 399 · raw
@v:Value -> @+k:String -> Maybe<&2, Value>
def first source · line 406 · raw
@a:Maybe<&2, Value> -> @b:Maybe<&2, Value> -> Maybe<&2, Value>
def resolve source · line 414 · 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 421 · raw
@mv:Maybe<&2, Value> -> @+k:String -> Maybe<&2, Value>
def dig source · line 428 · raw
@path:List<&2, String> -> @mv:Maybe<&2, Value> -> Maybe<&2, Value>
def top source · line 435 · raw
@stack:List<&2, Value> -> Maybe<&2, Value>
def lookup source · line 443 · 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 450 · raw
@raw:Bool -> @v:Maybe<&2, Value> -> String
def truthy source · line 459 · raw
@v:Maybe<&2, Value> -> Bool
def items.of source · line 470 · raw
@v:Maybe<&2, Value> -> List<&2, Value>
def sec.items source · line 484 · raw
@inv:Bool -> @+v:Maybe<&2, Value> -> List<&2, Value>
The values a section's body renders once each against.
def indent source · line 492 · raw
@ind:String -> @+s:String -> String
Each LF in partial text is followed by the partial's indentation.
def undent source · line 500 · raw
@+ind:String -> @+s:String -> String
Drops the indentation that indent left after the partial's last LF.
def part.got source · line 506 · raw
@r:Pair(Map<&2, List<&2, Node>>, List<&2, Node>) -> List<&2, Node>
def part source · line 511 · raw
@+ps:Map<&2, List<&2, Node>> -> @+n:String -> List<&2, Node>
A missing partial renders as nothing.
def go source · line 515 · 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 -> 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 536 · 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 540 · 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 543 · raw
@r:Result<&2, &2, String, List<&2, Node>> -> @ctx:Map<&2, Value> -> Result<&2, &2, String, String>
def render_text source · line 551 · raw
@+src:String -> @ctx:Map<&2, Value> -> Result<&2, &2, String, String>
parse, then render.