Skip to content

Latest commit

 

History

History
76 lines (49 loc) · 4.02 KB

builtins.md

File metadata and controls

76 lines (49 loc) · 4.02 KB

Built-ins

Functions

From Go

The following functions simply expose functions from Go's standard library for convenience:

len

len() takes one argument and returns the length of a string, array, slice or map, the number of fields in a struct, or the buffer size of a channel, depending on the argument's type. (Think of it like Go's len() function.)

It panics if you pass a value of any type other than string, array, slice, map, struct or channel.

len() indirects through arbitrary layers of pointer and interface types before checking for a valid type.

isset

isset() takes an arbitrary number of index, field, chain or identifier expressions and returns true if all expressions evaluate to non-nil values. It panics only when an unexpected expression type is passed in.

exec

exec() takes a template path and optionally a value to use as context and executes the template with the current or specified context. It returns the last value returned using the return statement, or nil if no return statement was executed.

ints

ints() takes two integers as lower and upper limit and returns a Ranger producing all the integers between them, including the lower and excluding the upper limit. It panics when the arguments can't be converted to integers or when the upper limit is not strictly greater than the lower limit.

SafeWriter

Jet includes a SafeWriter function type for writing directly to the render output stream. This can be used to circumvent Jet's default HTML escaping. Jet has a few such functions built-in.

safeHtml

safeHtml is an alias for Go's template.HTMLEscape (converted to the SafeWriter type). This is the same escape function that's also applied to the evalutation result of action nodes by default. It escapes everything that could be interpreted as HTML.

safeJs

safeJs is an alias for Go's template.JSEscape. It escapes data to be safe to use in a Javascript context.

raw/unsafe

raw (alias unsafe) is a writer that escapes nothing at all, allowing you to circumvent Jet's default HTML escaping. Use with caution!

Renderer

Jet exports a Renderer interface (and RendererFunc type which implements the interface). When an action evaluates to a value implementinng this interface, it will not be rendered using fastprinter, but by calling its Render() function instead.

writeJson

writeJson renders the JSON encoding of whatever you pass in to the output, escaping only "<", ">", and "&" (just like the json function).