Modules
A module is an object that collects a number of constants, functions and
types under a common name. Also a module always has the attributes __name__
and __doc__.
operator
The operator module contains the type attrgetter. The object
attrgetter(n) is callable and when called with an object a returns
as attribute named n. This can be used for sorting objects by their
attributes without having to create local templates.
For example
<?print operator.attrgetter('year')(now())()?>
prints 2021.
math
This module contains constants and functions related to mathematical operations:
math.eis the base of the natural logarithm (2.718281828…).math.piis the ratio of a circle’s circumference to its diameter (3.14159265…).math.tauis2 * math.pi.The trigonometric function
math.cos()return the cosine of it argument (which must be in radians).The trigonometric function
math.sin()return the sine of it argument (which must be in radians).The trigonometric function
math.tan()return the tangent of it argument (which must be in radians).math.sqrt()which returns the square root of its argument.math.isclose(a, b)returnsTrueif the valuesaandbare close to each other andFalseotherwise. Whether or not two values are considered close is determined according to given absolute and relative tolerances (via the keyword argumentsrel_tolandabs_tol).
ul4on
This module contains functions and types for working with ll.ul4on:
ul4on.dumps(foo)returns the UL4ON representation of the objectfoo.ul4on.loads(foo)decodes the UL4ON stringfooand returns the resulting object.ul4on.Encoder(indent)creates an encoder object that can be used to create multiple UL4ON dump using the same context. Anul4on.Encoderobject has a methoddumpsthat creates an UL4ON dump for the passed in object.ul4on.Decoder()creates a decoder object that can be used to recreate objects from multiple UL4ON dumps using the same context. Anul4on.Decoderobject has a methodloadsthat recreates an object from the passed in UL4ON dump.
ul4
This module contains all the types of the nodes in the abstract syntax tree that
comprises an UL4 template. The available types are: TextAST, IndentAST,
LineEndAST, CodeAST, ConstAST, SeqItemAST, UnpackSeqItemAST,
DictItemAST, UnpackDictItemAST, PositionalArgumentAST,
KeywordArgumentAST, UnpackListArgumentAST, UnpackDictArgumentAST,
ListAST, ListComprehensionAST, SetAST, SetComprehensionAST,
DictAST, DictComprehensionAST, GeneratorExpressionAST, VarAST,
BlockAST, ConditionalBlocksAST, IfBlockAST, ElIfBlockAST,
ElseBlockAST, ForBlockAST, WhileBlockAST, BreakAST,
ContinueAST, AttrAST, SliceAST, UnaryAST, NotAST,
NegAST, BitNotAST, PrintAST, PrintXAST, ReturnAST,
BinaryAST, ItemAST, IsAST, IsNotAST, EQAST, NEAST,
LTAST, LEAST, GTAST, GEAST, ContainsAST, NotContainsAST,
AddAST, SubAST, MulAST, FloorDivAST, TrueDivAST, ModAST,
ShiftLeftAST, ShiftRightAST, BitAndAST, BitXOrAST, BitOrAST,
AndAST, OrAST, IfAST, ChangeVarAST, SetVarAST, AddVarAST,
SubVarAST, MulVarAST, FloorDivVarAST, TrueDivVarAST,
ModVarAST, ShiftLeftVarAST, ShiftRightVarAST, BitAndVarAST,
BitXOrVarAST, BitOrVarAST, CallAST, RenderAST, RenderXAST,
RenderBlockAST, RenderBlocksAST, SignatureAST, Template and
TemplateClosure.
The only callable type in this list is Template which can be used to
create an UL4 template from source. Its signature is
(
source=None,
name=None,
*,
whitespace="keep",
signature=None
)
Note
ul4.Template is not callable in the Javascript version of UL4.
color
This module contains the following types and functions:
color.Color(r=0, g=0, b=0, a=255)Return a color object with the red component
r, the green componentg, the blue componentband the alpha (opacity) componenta. All values must be integers in the range 0 to 255. Float values will be rounded to integers and values out of range will be clipped to the allowed range.color.css(value, default)Return a color object for the CSS color specification
value. Ifvaluecan’t be interpreted as a CSS color,defaultwill be returned if given, otherwise an exception will be raised.color.mix(*values)Calculates a weighted mix of the colors from
values. Items invaluesare either colors or weights. The following example mixes two parts black with one part white:<?print color.mix(2, #000, 1, #fff)?>
which will print:
#555