API Reference otera v#0.1.0

Copy Markdown View Source

Modules

Otera (お寺, "temple") renders Jinja templates in pure Elixir, with the semantics of Python Jinja2.

A Python bytes value, which str.encode() gives. It prints like Python, such as b'caf\xc3\xa9', has a length in bytes, iterates as integers, and decode() gives the string back.

Renders the chat template of a Hugging Face model like apply_chat_template in Python transformers.

The cycler(*items) object of Jinja2. next() gives the current item and moves to the next one, reset() goes back to the first item, and current is the item that next() gives next. The position lives in Otera.State.

A dictionary that keeps the insertion order of its keys, like a Python dict.

An error that a template raises while it renders.

Renders the syntax tree of Otera.Parser with the semantics of Python Jinja2.

The builtin filters of Jinja2, with their Python behavior.

Python string formatting: the % operator, which the format filter of Jinja2 uses, and str.format().

An Elixir function with a Python signature, for a global, filter or test that takes keyword arguments.

An item of the result of the groupby filter: a Python named tuple (grouper, list) with the attributes grouper and list. It prints and compares like a tuple.

HTML text like Python: escape/1 of markupsafe, unescape/1 of html.unescape, and striptags/1 of Markup.striptags.

A Python iterable that is not a list or a tuple, with the behavior of its Python type.

JSON with the rules of Python json: dumps/2 for the tojson filter, and decode!/1 to keep the key order of objects.

The joiner(sep=", ") object of Jinja2. A call gives an empty string the first time and sep after that. Whether it was called lives in Otera.State.

Splits a template source into tokens, with the rules of the Python Jinja2 lexer.

The lipsum(n=5, html=True, min=20, max=100) function of Jinja2: n paragraphs of random lorem ipsum, with the algorithm and the words of Jinja2. The text is random, as in Python.

The loop variable inside a {% for %} block, like the LoopContext of Jinja2.

A macro that a template defines with {% macro %}, or the caller of a {% call %} block, which has no name.

A Python method bound to a value, such as message.content.strip or loop.cycle. Otera.Methods runs it when the template calls it.

The Python methods that templates call on values, such as content.strip(), name.startswith("get_") or message.get("tool_calls").

A namespace() object of Jinja2, which a template can change.

Parses the tokens of Otera.Lexer into an abstract syntax tree, with the grammar of the Python Jinja2 parser.

Python pprint.pformat, for the pprint filter, with its defaults: a width of 80, an indent of 1, and dicts sorted by key.

The mutable state of a render, for the Python objects that templates change: namespace() objects and the last value of loop.changed().

An error in the syntax of a template, with the line where Otera found it.

A parsed template. Otera.parse/2 makes it, and Otera.render/3 renders it many times without parsing it again.

The builtin tests of Jinja2, such as x is defined or x is divisibleby 3, with their Python behavior.

Python textwrap.wrap, for the wordwrap filter, with the options that the filter uses: no tab expansion, no whitespace replacement, and whitespace dropped at the start and end of the lines.

The value of a missing variable, attribute or item, like the default Undefined of Jinja2.

The character properties of Python str methods, such as isprintable(), isdigit() and the cased letters of title().

The Python semantics of template values.