[−][src]Module bracket::helper
Helper trait and types for the default set of helpers.
The Helper Trait should be implemented for custom helpers which can then be added to a registry.
Helper call()
functions accept three arguments:
- rc The active renderer.
- ctx Helper arguments and hash parameters.
- template Inner template when called as a block.
The renderer can be used to render inner templates when a helper is called as a block and provides functions for writing to the output destination.
The context is used to access the arguments and hash parameters and may also be used for type assertions using the try_get() and try_hash() methods. The arity() method can be used to assert on argument length.
When a helper is called as a block the optional template node will be Some
.
Raw helpers can access the inner text using text().
To determine how a helper was invoked requires checking for an inner template or raw text; if neither is available it is a statement:
if let Some(node) = template { // Helper was invoked as a block `{{#helper}}...{{/helper}}` } else if let Some(text) = ctx.text() { // Helper was invoked as a raw block `{{{{helper}}}}...{{{{/helper}}}}` } else { // Helper was invoked as a statement `{{helper}}` }
Return Values
The signature for helper return values is HelperValue which requires
that the call()
function returns an optional Value.
A return value is useful when a helper is invoked as a statement; when invoked as
a block return Ok(None)
.
If a statement helper is used for side-effects (such as the Log helper) then
return Ok(None)
.
Local Helpers
Local helpers are defined on rc using register_local_helper() and live for the lifetime of the parent helper call.
Clone
Helpers must implement Clone
so that we can support local helpers.
Modules
comparison | Helpers for numerical comparisons. |
each | Block helper that iterates arrays and objects. |
if | Helpers for conditional statements. |
json | Helper that returns a JSON string. |
log | Helper to print log messages. |
logical | Helpers for conditional statements. |
lookup | Helper to lookup a field of an array or object. |
unless | Block helper for negated conditional. |
with | Block helper that sets the scope. |
Structs
HelperRegistry | Collection of helpers. |
Traits
Helper | Trait for helpers. |
LocalHelper | Trait for local helpers which must implement |
Type Definitions
HelperResult | Result type returned when invoking helpers. |
HelperValue | Result type that helper implementations should return. |