Module

tuck/render

src/tuck/render.pooka

Walking a template with the data in hand, and writing as it goes.

Values are looked up in the loop variables first, then in the data. A name that is not there is not an error straight away: {% if %} reads it as false and | default replaces it. Only printing it, looping over it or filtering it is an error, and then the message says what was missing and what was there instead.

API reference

class

Val

src/tuck/render.pooka:28
class Val

A value while it is being worked out.

class

Found

src/tuck/render.pooka:31
class Found(value: Json) is Val

A value from the template or the data.

field

value

src/tuck/render.pooka:31
value: Json
INFERRED$package/pooka_json/pooka/json.Json
constructor

new

src/tuck/render.pooka:31
INFERREDfn($package/pooka_json/pooka/json.Json) -> tuck/render.Found
class

Safe

src/tuck/render.pooka:34
class Safe(text: String) is Val

Text that is already safe to print without escaping.

field

text

src/tuck/render.pooka:34
text: String
INFERREDString
constructor

new

src/tuck/render.pooka:34
INFERREDfn(String) -> tuck/render.Safe
class

Missing

src/tuck/render.pooka:38
class Missing(message: String, at: Pos) is Val

Something that is not there: the sentence to say if it matters, and where in the template it was asked for.

field

message

src/tuck/render.pooka:38
message: String
INFERREDString
field

at

src/tuck/render.pooka:38
at: Pos
constructor

new

src/tuck/render.pooka:38
INFERREDfn(String, tuck/error.Pos) -> tuck/render.Missing
class

Version

src/tuck/render.pooka:41
class Version(owner: String, body: List(Node))

Everything rendering needs to know besides the nodes themselves.

field

owner

src/tuck/render.pooka:41
owner: String
INFERREDString
field

body

src/tuck/render.pooka:41
body: List(Node)
INFERREDList(tuck/ast.Node)
constructor

new

src/tuck/render.pooka:41
INFERREDfn(String, List(tuck/ast.Node)) -> tuck/render.Version
class

Scope

src/tuck/render.pooka:43
class Scope(
  template: String,
  load: fn(String) -> Result(Document, TuckError),
  filters: List(#(String, Filter)),
  functions: List(#(String, Function)),
  escape: Bool,
  frames: List(List(#(String, Val))),
  data: List(#(String, Json)),
  blocks: List(#(String, List(Version))),
  stack: List(String),
  parents: List(Version)
)
field

template

src/tuck/render.pooka:44
template: String
INFERREDString
field

load

src/tuck/render.pooka:45
load: fn(String) -> Result(Document, TuckError)
INFERREDfn(String) -> Result(tuck/ast.Document, tuck/error.TuckError)
field

filters

src/tuck/render.pooka:46
filters: List(#(String, Filter))
INFERREDList(#(String, tuck/filter.Filter))
field

functions

src/tuck/render.pooka:47
functions: List(#(String, Function))
INFERREDList(#(String, tuck/function.Function))
field

escape

src/tuck/render.pooka:48
escape: Bool
INFERREDBool
field

frames

src/tuck/render.pooka:49
frames: List(List(#(String, Val)))
INFERREDList(List(#(String, tuck/render.Val)))
field

data

src/tuck/render.pooka:50
data: List(#(String, Json))
INFERREDList(#(String, $package/pooka_json/pooka/json.Json))
field

blocks

src/tuck/render.pooka:51
blocks: List(#(String, List(Version)))
INFERREDList(#(String, List(tuck/render.Version)))
field

stack

src/tuck/render.pooka:52
stack: List(String)
INFERREDList(String)
field

parents

src/tuck/render.pooka:53
parents: List(Version)
INFERREDList(tuck/render.Version)
constructor

new

src/tuck/render.pooka:44
INFERREDfn(String, fn(String) -> Result(tuck/ast.Document, tuck/error.TuckError), List(#(String, tuck/filter.Filter)), List(#(String, tuck/function.Function)), Bool, List(List(#(String, tuck/render.Val))), List(#(String, $package/pooka_json/pooka/json.Json)), List(#(String, List(tuck/render.Version))), List(String), List(tuck/render.Version)) -> tuck/render.Scope
function

document

src/tuck/render.pooka:61
document(
  name: String,
  load: fn(String) -> Result(Document, TuckError),
  filters: List(#(String, Filter)),
  functions: List(#(String, Function)),
  escape: Bool,
  data: List(#(String, Json))
) -> Result(String, TuckError)
INFERREDfn(String, fn(String) -> Result(tuck/ast.Document, tuck/error.TuckError), List(#(String, tuck/filter.Filter)), List(#(String, tuck/function.Function)), Bool, List(#(String, $package/pooka_json/pooka/json.Json))) -> Result(String, tuck/error.TuckError)

Render the template called name, with data as its values.

load finds a template's document by name, for this template and for anything it includes or extends. escape makes every printed value safe for HTML.