Module
tuck/filter
src/tuck/filter.pookaSmall 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(run: fn(Json, List(Json)) -> Result(Json, String))
A filter: the value, its arguments, and the new value or a reason.
run: fn(Json, List(Json)) -> Result(Json, String)
fn($package/pooka_json/pooka/json.Json, List($package/pooka_json/pooka/json.Json)) -> Result($package/pooka_json/pooka/json.Json, String)
fn(fn($package/pooka_json/pooka/json.Json, List($package/pooka_json/pooka/json.Json)) -> Result($package/pooka_json/pooka/json.Json, String)) -> tuck/filter.Filterbuilt_in() -> List(#(String, Filter))
fn() -> List(#(String, tuck/filter.Filter))Every built-in filter, by name.
import tuck/filter
let assert Some(upper) = list.key_find(filter.built_in(), "upper")
assert upper.run(json.JString("owl"), []) == Ok(json.JString("OWL"))
special() -> List(String)
fn() -> List(String)The names the renderer handles itself, for suggestions.
text(value: Json) -> Result(String, String)
fn($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.
import tuck/filter
assert filter.text(json.JInt(3)) == Ok("3")
assert filter.text(json.JNull()) == Ok("")
kind(value: Json) -> String
fn($package/pooka_json/pooka/json.Json) -> StringWhat kind of value this is, for messages.
truthy(value: Json) -> Bool
fn($package/pooka_json/pooka/json.Json) -> BoolIs the value true enough for {% if %}? Everything is, except false,
nil, zero, and empty strings, lists and objects.
compare(left: Json, right: Json) -> Result(Order, String)
fn($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.
same(left: Json, right: Json) -> Bool
fn($package/pooka_json/pooka/json.Json, $package/pooka_json/pooka/json.Json) -> BoolEqual values, with 1 and 1.0 counting as equal.
escape_html(value: String) -> String
fn(String) -> StringText safe to place in HTML: &, <, >, " and ' become entities.
import tuck/filter
assert filter.escape_html("<b>Tom & Jerry</b>") == "<b>Tom & Jerry</b>"