~/bend-docscommunity

template.bend checks

raw source on the hub · import bend-kit-template@0.1.0.0/template.bend as Template

Mustache templates: variables, sections, inverted sections, and comments, 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.

type Node source · line 12 · raw

Data

A parsed template. A path is a dotted name split at its dots; the name "." is the empty path.

type Tok source · line 17 · raw

Data

type Lex source · line 27 · raw

Data

type Frame source · line 32 · raw

Data

type St source · line 35 · raw

Data

Definitions

def escape.pick source · line 39 · raw

@amp:Bool -> @lt:Bool -> @gt:Bool -> @quot:Bool -> @apos:Bool -> @c:Char -> @rest:String -> String

def escape source · line 63 · raw

@s:String -> String

HTML text: & < > " ' become &amp; &lt; &gt; &quot; &#39;.

def cut.go source · line 71 · raw

@+s:String -> @hit:Bool -> @+pat:String -> @acc:String -> Pair(String, Maybe<&2, String>)

def cut source · line 83 · 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 tag.sigil source · line 86 · raw

@+c:U32 -> @+t:String -> Tok

def tag.plain source · line 97 · raw

@name:String -> Tok

def tag.of source · line 104 · raw

@triple:Bool -> @name:String -> Tok

def lex.close source · line 111 · raw

@text:String -> @triple:Bool -> @p:Pair(String, Maybe<&2, String>) -> Lex

def lex.open source · line 119 · raw

@triple:Bool -> @text:String -> @+a:String -> Lex

def lex.after source · line 126 · raw

@p:Pair(String, Maybe<&2, String>) -> Lex

def lex source · line 135 · raw

@+src:String -> Lex

The text up to the next tag, the tag, and the rest.

def toks.go source · line 139 · raw

@f:Nat -> @l:Lex -> @acc:List<&2, Tok> -> Result<&2, &2, String, List<&2, Tok>>

Every lex step eats a char, so length + 1 steps are enough. Texts and tags alternate.

def blank source · line 152 · raw

@+c:U32 -> Bool

def blank13 source · line 155 · raw

@+c:U32 -> Bool

def head_ok source · line 159 · 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 167 · raw

@s:String -> String

def drop_chr source · line 175 · raw

@+k:U32 -> @s:String -> String

def trim_head source · line 183 · raw

@s:String -> String

def trim_tail source · line 186 · raw

@s:String -> String

def std.kind source · line 189 · raw

@t:Tok -> Bool

def std.go source · line 203 · 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 212 · raw

@toks:List<&2, Tok> -> List<&2, Tok>

A section, inverted, close, or comment tag alone on its line takes the line with it.

def path.of source · line 219 · raw

@+n:String -> List<&2, String>

def add source · line 222 · raw

@top:Frame -> @n:Node -> Frame

def close.pop source · line 227 · raw

@stack:List<&2, Frame> -> @+name:String -> @inv:Bool -> @acc:List<&2, Node> -> St

def close source · line 234 · raw

@same:Bool -> @+n:String -> @top:Frame -> @stack:List<&2, Frame> -> St

def close.of source · line 243 · raw

@+n:String -> @top:Frame -> @stack:List<&2, Frame> -> St

def step source · line 248 · raw

@st:St -> @t:Tok -> St

def tree.go source · line 271 · raw

@toks:List<&2, Tok> -> @st:St -> St

def tree.fin source · line 278 · raw

@st:St -> Result<&2, &2, String, List<&2, Node>>

def parse.tree source · line 289 · raw

@r:Result<&2, &2, String, List<&2, Tok>> -> Result<&2, &2, String, List<&2, Node>>

def parse source · line 297 · raw

@+src:String -> Result<&2, &2, String, List<&2, Node>>

The template as nodes, or Fail with why it is malformed. Partials and set delimiters fail.

def find.got source · line 300 · raw

@r:Pair(Map<&2, Value>, Value) -> Maybe<&2, Value>

def find.if source · line 304 · raw

@r:Pair(Map<&2, Value>, Bool) -> @+k:String -> Maybe<&2, Value>

def probe source · line 312 · raw

@v:Value -> @+k:String -> Maybe<&2, Value>

def first source · line 319 · raw

@a:Maybe<&2, Value> -> @b:Maybe<&2, Value> -> Maybe<&2, Value>

def resolve source · line 327 · 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 334 · raw

@mv:Maybe<&2, Value> -> @+k:String -> Maybe<&2, Value>

def dig source · line 341 · raw

@path:List<&2, String> -> @mv:Maybe<&2, Value> -> Maybe<&2, Value>

def top source · line 348 · raw

@stack:List<&2, Value> -> Maybe<&2, Value>

def lookup source · line 356 · 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 363 · raw

@raw:Bool -> @v:Maybe<&2, Value> -> String

def truthy source · line 372 · raw

@v:Maybe<&2, Value> -> Bool

def items.of source · line 383 · raw

@v:Maybe<&2, Value> -> List<&2, Value>

def sec.items source · line 397 · raw

@inv:Bool -> @+v:Maybe<&2, Value> -> List<&2, Value>

The values a section's body renders once each against.

def go source · line 405 · raw

@nodes:List<&2, Node> -> @items:List<&2, Value> -> @iter:Bool -> @+stack:List<&2, Value> -> String

iter renders nodes once per item, each pushed on the stack; otherwise it renders nodes once.

def render source · line 421 · raw

@nodes:List<&2, Node> -> @ctx:Map<&2, Value> -> String

The nodes rendered against ctx.

def render_text.of source · line 424 · raw

@r:Result<&2, &2, String, List<&2, Node>> -> @ctx:Map<&2, Value> -> Result<&2, &2, String, String>

def render_text source · line 432 · raw

@+src:String -> @ctx:Map<&2, Value> -> Result<&2, &2, String, String>

parse, then render.