The Python semantics of template values.
Templates see Elixir values as these Python values:
| Elixir | Python |
|---|---|
nil, true, false | None, True, False |
| integer, float | int, float |
| binary | str |
| list, tuple | list, tuple |
map, Otera.Dict | dict |
| other atom | str |
| function | a callable |
from_elixir/1 converts the variables of a render to these values. A map becomes an Otera.Dict with its keys in sorted order, and atom keys become strings.
This module gives the rules that Jinja2 takes from Python: truthiness, str() and repr(), equality and ordering, arithmetic, iteration, and attribute and item lookup in the immutable sandbox of transformers.
Summary
Functions
Applies a Python binary operator: :add, :sub, :mul, :div, :floordiv, :mod or :pow.
Compares two values with a Python ordering operator: :lt, :lteq, :gt or :gteq.
Returns true if item in container in Python.
Returns the decimal exponent of the first significant digit of a positive float, like floor(log10(value)).
Returns true if left == right in Python.
Formats a float like Python repr(): the shortest digits that give the same float, in fixed notation from 1e-4 to below 1e16, else in scientific notation.
Converts an Elixir value to a template value. See the module documentation.
Looks up x.name, like the immutable sandbox of Jinja2: a Python attribute first, then an item.
Looks up x[key], like the immutable sandbox of Jinja2: an item first, then a Python attribute.
Raises the Python TypeError for a dict key or a set item that is a list or a dict.
Returns true if Python can iterate over value.
Returns the length of value, like Python len().
Describes the type of value as Jinja2 does in undefined messages, for example dict object.
Returns the Python repr() of value.
Returns sequence[start:stop:step] with the Python rules for missing and negative bounds.
Returns the number of code points in string, the length of a Python str.
Strips chars from one or both ends of string, like Python str.strip(). With nil, strips whitespace.
Returns the items of value as a list, like Python iter(). A dict gives its keys, and a string its characters.
Converts value to a string, like Python str().
Returns the truth value of value, like Python bool().
Returns the name of the Python type of value, as in Python error messages.
Applies unary minus or plus.
Functions
Applies a Python binary operator: :add, :sub, :mul, :div, :floordiv, :mod or :pow.
Compares two values with a Python ordering operator: :lt, :lteq, :gt or :gteq.
Returns true if item in container in Python.
Returns the decimal exponent of the first significant digit of a positive float, like floor(log10(value)).
Returns true if left == right in Python.
Formats a float like Python repr(): the shortest digits that give the same float, in fixed notation from 1e-4 to below 1e16, else in scientific notation.
Converts an Elixir value to a template value. See the module documentation.
Looks up x.name, like the immutable sandbox of Jinja2: a Python attribute first, then an item.
Looks up x[key], like the immutable sandbox of Jinja2: an item first, then a Python attribute.
@spec hashable!(term()) :: :ok
Raises the Python TypeError for a dict key or a set item that is a list or a dict.
Returns true if Python can iterate over value.
@spec length(term()) :: non_neg_integer()
Returns the length of value, like Python len().
Describes the type of value as Jinja2 does in undefined messages, for example dict object.
Returns the Python repr() of value.
Returns sequence[start:stop:step] with the Python rules for missing and negative bounds.
@spec str_length(String.t()) :: non_neg_integer()
Returns the number of code points in string, the length of a Python str.
Strips chars from one or both ends of string, like Python str.strip(). With nil, strips whitespace.
Returns the items of value as a list, like Python iter(). A dict gives its keys, and a string its characters.
Converts value to a string, like Python str().
Returns the truth value of value, like Python bool().
Returns the name of the Python type of value, as in Python error messages.
Applies unary minus or plus.