1
0
Fork 0
mirror of https://git.sr.ht/~adnano/kiln synced 2024-06-01 09:36:06 +02:00

docs: Document built-in functions

This commit is contained in:
Adnan Maolood 2021-05-17 12:41:37 -04:00
parent 73acb06c43
commit 2b5f585ce2

View File

@ -266,6 +266,68 @@ Templates have certain data and functions available to them.
All templates have the following functions available to them:
*and* _args..._
Returns the boolean AND of its arguments by returning the
first empty argument or the last argument, that is,
"and x y" behaves as "if x then y else x". All the
arguments are evaluated.
*call* _function_, _args..._
Returns the result of calling the first argument, which
must be a function, with the remaining arguments as parameters.
Thus "call .X.Y 1 2" is, in Go notation, dot.X.Y(1, 2) where
Y is a func-valued field, map entry, or the like.
The first argument must be the result of an evaluation
that yields a value of function type (as distinct from
a predefined function such as print). The function must
return either one or two result values, the second of which
is of type error. If the arguments don't match the function
or the returned error value is non-nil, execution stops.
*eq* _arg1_, _arg2_
Returns the boolean truth of _arg1_ == _arg2_.
*ge* _arg1_, _arg2_
Returns the boolean truth of _arg1_ >= _arg2_.
*gt* _arg1_, _arg2_
Returns the boolean truth of _arg1_ > _arg2_.
*html* _args..._
Returns the escaped HTML equivalent of the textual
representation of its arguments. This function is unavailable
in HTML templates, with a few exceptions.
*index* _collection_, _args..._
Returns the result of indexing its first argument by the
following arguments. Thus "index x 1 2 3" is, in Go syntax,
x[1][2][3]. Each indexed item must be a map, slice, or array.
*js* _args..._
Returns the escaped JavaScript equivalent of the textual
representation of its arguments.
*le* _arg1_, _arg2_
Returns the boolean truth of _arg1_ <= _arg2_.
*len* _list_
Returns the integer length of its argument.
*lt* _arg1_, _arg2_
Returns the boolean truth of _arg1_ < _arg2_.
*ne* _arg1_, _arg2_
Returns the boolean truth of _arg1_ != _arg2_.
*not* _arg_
Returns the boolean negation of its single argument.
*or* _args..._
Returns the boolean OR of its arguments by returning the
first non-empty argument or the last argument, that is,
"or x y" behaves as "if x then x else y". All the
arguments are evaluated.
*path.Base* _path_
Returns the last element of _path_.
@ -281,6 +343,17 @@ All templates have the following functions available to them:
*path.Join* _elem..._
Joins any number of path elements into a single path.
*print* _args..._
Formats using the default formats for its operands and returns the resulting
string. Spaces are added between operands when neither is a string.
*printf* _format_, _args..._
Formats according to a format specifier and returns the resulting string.
*println* _args..._
Formats using the default formats for its operands and returns the resulting
string. Spaces are always added between operands and a newline is appended.
*reverse* _list_
Returns a reversed copy of the provided slice or array.
@ -302,6 +375,12 @@ All templates have the following functions available to them:
*site*
Returns site metadata (see *SITE METADATA*).
*slice* _list_, _args..._
slice returns the result of slicing its first argument by the
remaining arguments. Thus "slice x 1 2" is, in Go syntax, x[1:2],
while "slice x" is x[:], "slice x 1" is x[1:], and "slice x 1 2 3"
is x[1:2:3]. The first argument must be a string, slice, or array.
*strings.Count* _string_, _substr_
Counts the number of non-overlapping instances of _substr_ in _string_.
If _substr_ is an empty string, Count returns 1 + the number of Unicode code
@ -388,6 +467,12 @@ All templates have the following functions available to them:
Returns _string_ without the provided trailing _suffix_ string. If _string_
doesn't end with _suffix_, it is returned unchanged.
*urlquery* _args..._
Returns the escaped value of the textual representation of
its arguments in a form suitable for embedding in a URL query.
This function is unavailable in HTML templates, with a few
exceptions.
## SITE METADATA
Site metadata contains the following data: