yatla package

yatla.builtins module

Built-in functions accessible from a template.

yatla.builtins.Maximum(val1, val2)

Returns the greatest of val1 and val2.

yatla.builtins.Minimum(val1, val2)

Returns the smallest of val1 and val2.

yatla.builtins.RoundDown(val, base)

Returns the greatest multiple of base that is less than or equal to val. This is effectively rounding val down to the first factor of base.

yatla.builtins.RoundUp(val, base)

Returns the smallest multiple of base that is greater than or equal to val. This is effectively rounding val up to the first factor of base.

yatla.lexer module

This module provides the lexer which is used to parse templates. The members of this module are not required in most templating workflows.

class yatla.lexer.Scanner(source)

Scanner class for tokenising documents.

keep_whitespace()

Sets the scanner to parse all whitespace (except newlines) as a string.

scan()

Scans a document, yielding tokens.

trim_whitespace()

Sets the scanner to break on all whitespace.

class yatla.lexer.Token(type: TokenType, lexeme: str, literal: str | int | float | None, line_number: int)

A token generated by a scanner. Has an optional literal value depending on the token’s type for example, a token of TokenType.STRING will have the string’s literal value in the literal field.

class yatla.lexer.TokenType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

An enumeration of all the token types a scanner can emit.

yatla.template module

class yatla.template.Slot(name: str, type: SlotType)

Represents a slot in a template. Has a name which is derived from the placeholder in the template, and a type which is inferred from the use of the slot.

name: str
type: SlotType
class yatla.template.Template(_ast: DocumentASTNode, source: str, slots: List[Slot])

Represents a parsed template. Can be filled using a mapping of slot names to values.

fill(values: Mapping[str, int | float | str | Iterable[int] | Iterable[float] | Iterable[str]]) str

Fill the slots in the template using the provided values.

slots: List[Slot]
source: str

yatla.parser module

yatla.parser.parse(source: str) Template

Given a template source as a string, parse the template into a Template object. This method also verifies that a template is valid.

yatla.types module

class yatla.types.SlotType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)

An enumeration of all supported parameter types by the templating engine.

String = 1
Num = 2
Any = 3
StringArray = 4
NumArray = 5
AnyArray = 6