Sign in

    moonbitstack/moonpug/spec does not have a README file

    Filter

    type Filter = (Call, Value, Array[Value], Map[String, Value]) -> Value raise Refused

    A filter: the value left of |, the arguments in parentheses.

    Func

    type Func = (Call, Array[Value], Map[String, Value]) -> Value raise Refused

    What a function receives: what the engine knows about the render in flight, positional arguments, named arguments.

    Test

    type Test = (Call, Value, Array[Value]) -> Bool raise Refused

    A test: the value left of is, the arguments after the name.

    Object

    pub(open) trait Object {
    fn kind(Self) -> String
    fn attr(Self, String) -> Value? = _
    fn call(Self, Call, Array[Value], Map[String, Value]) -> Value raise Refused = _
    fn callable(Self) -> Bool = _
    fn assign(Self, String, Value) -> Unit raise Refused = _
    fn show(Self) -> String = _
    fn items(Self) -> Array[Value]? = _
    }

    A host value a template can use. Each method is optional: an object that only has attributes implements attr, a function only call. Cyclers, macros, namespaces and the loop variable are objects too.

    Refused

    pub(all) suberror Refused {
    Syntax(template~ : String, line~ : Int, column~ : Int, reason~ : String)
    Unknown(template~ : String, line~ : Int, kind~ : String, name~ : String)
    Invalid(template~ : String, line~ : Int, reason~ : String)
    Exceeded(template~ : String, line~ : Int, limit~ : Int, got~ : Int)
    } derive(Eq,
    Debug
    )

    Why a template could not be read or rendered. Every variant names the template and the one-based line it stopped at; a fault raised by an extension carries an empty name and line 0 until the engine fills in where it was called from.
    impl Show for Refused

    Refused::at

    fn Refused::at(self : Refused, template : String, line : Int) -> Refused

    The same fault, placed at template and line if it has no place yet.

    Refused::equal

    fn Refused::equal(Refused, Refused) -> Bool

    Refused::not_equal

    fn Refused::not_equal(x : Refused, y : Refused) -> Bool

    Refused::output

    fn Refused::output(self : Refused, logger : &Logger) -> Unit

    Refused::place

    fn Refused::place(self : Refused) -> (String, Int)

    The template and line a fault names.

    Refused::to_repr

    Refused::to_string

    fn Refused::to_string(self : Refused) -> String

    Call

    pub struct Call {
    autoescape : Bool
    undefined : Undefined
    range : Int
    // private fields
    }

    What an extension can reach of the render in flight: whether output is being escaped, the undefined policy, the other filters and tests, the translation seam, and the bound on range.

    Call::check

    fn Call::check(self : Call, name : String, value : Value, args : Array[Value]) -> Bool raise Refused

    Apply the test registered under name; test itself is a keyword.

    Call::draw

    fn Call::draw(self : Call) -> Int

    A number that differs from call to call within a render and repeats on the next render, for filters such as random that must give the same page twice.

    Call::escaping

    fn Call::escaping(self : Call, autoescape : Bool) -> Call

    The same render with escaping turned on or off.

    Call::filter

    fn Call::filter(self : Call, name : String, value : Value, args : Array[Value], named : Map[String, Value]) -> Value raise Refused

    Apply the filter registered under name.

    Call::has_filter

    fn Call::has_filter(self : Call, name : String) -> Bool

    Whether a filter is registered under name.

    Call::has_test

    fn Call::has_test(self : Call, name : String) -> Bool

    Whether a test is registered under name.

    Call::items

    fn Call::items(self : Call, value : Value) -> Array[Value] raise Refused

    The items a loop over the value walks; an undefined value is empty, or refused under the strict policy.

    Call::new

    fn Call::new(autoescape? : Bool, undefined? : Undefined, range? : Int, filters? : Map[String, (Call, Value, Array[Value], Map[String, Value]) -> Value raise Refused], tests? : Map[String, (Call, Value, Array[Value]) -> Bool raise Refused], translate? : (String, String?, Int?) -> String?) -> Call

    The engine builds one per render; a test of an extension builds its own.

    Call::refuses

    fn Call::refuses(self : Call, name : String) -> Bool

    Whether using an undefined value of this name is refused. The strict policy refuses a name that was looked up and missing; the implicit else of an inline if has no name and is never refused.

    Call::text

    fn Call::text(self : Call, value : Value) -> String raise Refused

    A value as text, Python's str: an undefined value is empty, or refused under the strict policy.

    Call::translate

    fn Call::translate(self : Call, msgid : String, context? : String, count? : Int) -> String?

    Ask the translation seam for msgid in context, plural form for count. None when there is no seam or it has no translation.

    Call::truthy

    fn Call::truthy(self : Call, value : Value) -> Bool raise Refused

    Whether the value counts as true; an undefined value is false, or refused under the strict policy.

    Undefined

    pub(all) enum Undefined {
    Lenient
    Chainable
    Strict
    } derive(Eq)

    What happens when an undefined value is used, Jinja's three answers: Lenient prints nothing and iterates as empty but refuses attribute access; Chainable also lets attributes of it be undefined in turn; Strict refuses every use except asking whether it is defined.

    Undefined::equal

    fn Undefined::equal(Undefined, Undefined) -> Bool

    Undefined::not_equal

    fn Undefined::not_equal(x : Undefined, y : Undefined) -> Bool

    Value

    pub(all) enum Value {
    Null
    Bool(Bool)
    Int(Int64)
    Double(Double)
    Text(String)
    Markup(String)
    Seq(Array[Value])
    Tuple(Array[Value])
    Dict(Map[String, Value])
    Undefined(String)
    Object(&Object)
    }

    A value in a template. The context arrives as data; functions and host objects enter as Object. Markup is text already safe to write as it stands. Undefined is a name that resolved to nothing, carrying the name for the message a later use may need.
    impl Eq for Value
    impl Show for Value
    impl ToJson for Value

    Value::compare

    fn Value::compare(self : Value, other : Value) -> Int raise Refused

    Python's ordering: numbers with numbers, text with text, sequences element by element. Anything else has no order and is refused.

    Value::contains

    fn Value::contains(self : Value, item : Value) -> Bool raise Refused

    Python's item in self: a substring of a string, an element of a list or tuple, a key of a mapping, what an object yields.

    Value::equal

    fn Value::equal(self : Value, other : Value) -> Bool

    Value::field

    fn Value::field(self : Value, name : String) -> Value?

    value.name: an object's attribute, else the item of that name.

    Value::func

    fn Value::func(name : String, run : (Call, Array[Value], Map[String, Value]) -> Value raise Refused) -> Value

    A function as a template value: env.global("now", Value::func("now", …)).

    Value::index

    fn Value::index(self : Value) -> Int?

    A whole number usable as an index.

    Value::item

    fn Value::item(self : Value, key : Value) -> Value?

    value[key]: a mapping by key, a list or string by index (negative counts from the end), an object by attribute. None when there is nothing there.

    Value::iter

    fn Value::iter(self : Value) -> Array[Value] raise Refused

    The items a loop walks: a list's elements, a mapping's keys in insertion order, a string's characters, or what an object yields.

    Value::kind

    fn Value::kind(self : Value) -> String

    The word a message uses for a value's type.

    Value::markup

    fn Value::markup(self : Value) -> String

    A value as markup: safe text as it stands, anything else printed and escaped.

    Value::not_equal

    fn Value::not_equal(x : Value, y : Value) -> Bool

    Value::number

    fn Value::number(self : Value) -> Double?

    A number as Python sees one: Bool counts, being an int.

    Value::of_json

    fn Value::of_json(json : Json) -> Value

    Data read from JSON. A number written without a fraction or exponent is an Int when it fits, as Python reads it.

    Value::output

    fn Value::output(self : Value, logger : &Logger) -> Unit

    Value::path

    fn Value::path(self : Value, path : String) -> Value?

    A dotted path such as user.address.0, each step a lookup by item; a step written in digits indexes a list.

    Value::repr

    fn Value::repr(self : Value) -> String

    Python's repr: text quoted, lists and mappings with their elements in repr form. pprint and the printing of containers use it.

    Value::to_json

    fn Value::to_json(self : Value) -> Json

    Value::to_string

    fn Value::to_string(self : Value) -> String

    Value::truthy

    fn Value::truthy(self : Value) -> Bool

    What a condition sees: empty, zero, None and undefined are false.

    code_point_compare

    fn code_point_compare(a : String, b : String) -> Int

    Strings ordered by code point, as Python orders them.

    escape

    fn escape(text : String) -> String

    Text made safe for HTML and XML, element bodies and quoted attributes alike: the five characters markupsafe replaces, written the way it does.

    invalid

    fn invalid(reason : String) -> Refused

    A fault an extension raises; the engine adds the template and line.

    python_float

    fn python_float(d : Double) -> String

    A float the way Python writes it: the shortest digits that read back the same, fixed between 1e-4 and 1e16, scientific outside.

    repr_text

    fn repr_text(s : String) -> String

    Python's repr of a string: single quotes unless the text holds one and no double quote, with the escapes Python writes.

    unknown

    fn unknown(kind : String, name : String) -> Refused

    A name that resolves to nothing, raised from an extension.