Module

tuck/filter

src/tuck/filter.pooka

Small helpers that change a value on its way to the page.

A filter takes the value before the |, any arguments in parentheses, and returns a new value or a sentence about why it cannot. Tuck's own filters live here; a Library can add more with tuck.with_filter.

default, escape and safe are not here: they need to know whether a value exists at all, or whether it is already safe to print, so the renderer handles them itself.

API reference

class

Filter

src/tuck/filter.pooka:25
class Filter(run: fn(Json, List(Json)) -> Result(Json, String))

A filter: the value, its arguments, and the new value or a reason.

field

run

src/tuck/filter.pooka:25
run: fn(Json, List(Json)) -> Result(Json, String)
INFERREDfn($package/pooka_json/pooka/json.Json, List($package/pooka_json/pooka/json.Json)) -> Result($package/pooka_json/pooka/json.Json, String)
constructor

new

src/tuck/filter.pooka:25
INFERREDfn(fn($package/pooka_json/pooka/json.Json, List($package/pooka_json/pooka/json.Json)) -> Result($package/pooka_json/pooka/json.Json, String)) -> tuck/filter.Filter
function

built_in

src/tuck/filter.pooka:35
built_in() -> List(#(String, Filter))
INFERREDfn() -> List(#(String, tuck/filter.Filter))

Every built-in filter, by name.

Pooka
import tuck/filter

let assert Some(upper) = list.key_find(filter.built_in(), "upper")
assert upper.run(json.JString("owl"), []) == Ok(json.JString("OWL"))
function

special

src/tuck/filter.pooka:54
special() -> List(String)
INFERREDfn() -> List(String)

The names the renderer handles itself, for suggestions.

function

text

src/tuck/filter.pooka:67
text(value: Json) -> Result(String, String)
INFERREDfn($package/pooka_json/pooka/json.Json) -> Result(String, String)

A value as text, the way {{ }} prints it. Lists and objects have no single obvious spelling, so they are refused with a hint.

Pooka
import tuck/filter

assert filter.text(json.JInt(3)) == Ok("3")
assert filter.text(json.JNull()) == Ok("")
function

kind

src/tuck/filter.pooka:85
kind(value: Json) -> String
INFERREDfn($package/pooka_json/pooka/json.Json) -> String

What kind of value this is, for messages.

function

truthy

src/tuck/filter.pooka:98
truthy(value: Json) -> Bool
INFERREDfn($package/pooka_json/pooka/json.Json) -> Bool

Is the value true enough for {% if %}? Everything is, except false, nil, zero, and empty strings, lists and objects.

function

compare

src/tuck/filter.pooka:297
compare(left: Json, right: Json) -> Result(Order, String)
INFERREDfn($package/pooka_json/pooka/json.Json, $package/pooka_json/pooka/json.Json) -> Result($package/pooka_stdlib/pooka/order.Order, String)

Order two numbers, or two strings; anything else cannot be ordered.

function

same

src/tuck/filter.pooka:309
same(left: Json, right: Json) -> Bool
INFERREDfn($package/pooka_json/pooka/json.Json, $package/pooka_json/pooka/json.Json) -> Bool

Equal values, with 1 and 1.0 counting as equal.

function

escape_html

src/tuck/filter.pooka:323
escape_html(value: String) -> String
INFERREDfn(String) -> String

Text safe to place in HTML: &, <, >, " and ' become entities.

Pooka
import tuck/filter

assert filter.escape_html("<b>Tom & Jerry</b>") == "&lt;b&gt;Tom &amp; Jerry&lt;/b&gt;"