class

KrikriJinja::Engine

Inherits Reference < Object

Constructors

new(loader : Loader | Nil = nil, user_globals : Hash(String, AnyV) = {} of String => AnyV, options : LexerOptions = LexerOptions.new, autoescape : Bool = false, undefined : Undefined = Undefined.new, host_context : KrikriJinja::HostContext | Nil = nil.as(HostContext | ::Nil))
Source

Instance methods

autoescape
Source
dict_pair_unpacking

When set, {% for k, v in some_dict %} iterates the dict's (key, value) pairs instead of failing to unpack its keys, a lenient form some Ansible roles depend on.

Source
dict_pair_unpacking=(dict_pair_unpacking : Bool)

When set, {% for k, v in some_dict %} iterates the dict's (key, value) pairs instead of failing to unpack its keys, a lenient form some Ansible roles depend on.

Source
evaluate_expression(source : String, variables : Hash(String, AnyV) = {} of String => AnyV) : AnyValue
Source
evaluate_expression(source : String, variables : Hash(String, AnyValue)) : AnyValue
Source
evaluate_json(source : String, variables : Hash(String, JSON::Any) = {} of String => JSON::Any) : JSON::Any | Nil
Source
evaluate_parsed(expression : Nodes::ExprNode, variables : Hash(String, AnyValue) = {} of String => AnyValue, resolver : VariableResolver | Nil = nil, undefined : Undefined = @undefined, host_context : HostContext | Nil = @host_context) : AnyValue

Evaluates an already-parsed expression. resolver supplies any variable that variables does not define, on first use. undefined and host_context override the engine's own for this call only, so one engine (and its registered features) serves every caller.

Source
filters
Source
finalize

Jinja's finalize: applied to every {{ }} result before it is written out (never to values flowing between expressions).

Source
finalize=(finalize : Proc(AnyValue, AnyValue) | Nil)

Jinja's finalize: applied to every {{ }} result before it is written out (never to values flowing between expressions).

Source
globals
Source
host_context
Source
host_context=(host_context : HostContext | Nil)
Source
known_filter?(name : String) : Bool
Source
known_test?(name : String) : Bool
Source
load(name : String) : Nodes::TemplateNode
Source
load_source(name : String) : String
Source
loader
Source
options
Source
parsed_expression(source : String) : Nodes::ExprNode
Source
parsed_template(source : String) : Nodes::TemplateNode

Returns the parsed template for source, reusing the parse tree across calls. Parsed nodes are shared, so evaluators must never mutate them (see the **kwargs fix in eval_call).

Source
register_filter(name : String, &block : FilterFn) : self
Source
register_function(name : String, &block : FunctionFn) : self
Source
register_global(name : String, value) : self
Source
register_json_filter(name : String, &block : JsonFilterFn) : self
Source
register_json_function(name : String, &block : JsonFunctionFn) : self
Source
register_json_test(name : String, &block : JsonTestFn) : self
Source
register_loader_function(name : String, template_name : String) : self
Source
register_test(name : String, &block : TestFn) : self
Source
render(name : String, variables : Hash(String, AnyV) = {} of String => AnyV) : String

Loads a template by name from the loader and renders it.

Source
render_parsed(node : Nodes::TemplateNode, variables : Hash(String, AnyValue) = {} of String => AnyValue, resolver : VariableResolver | Nil = nil, undefined : Undefined = @undefined, host_context : HostContext | Nil = @host_context) : String

Renders an already-parsed template. resolver supplies any variable that variables does not define, on first use.

Source
render_string(source : String, variables : Hash(String, AnyV) = {} of String => AnyV) : String
Source
render_string(source : String, variables : Hash(String, AnyValue)) : String
Source
rwlock

Guards @template_cache/@expression_cache (mutated on every render/parse) and @filters/@tests/@globals (read on every render, mutated by register_*), since Crystal's Hash is not safe for concurrent access across real OS threads (-Dpreview_mt). One engine instance is commonly shared across fibers (e.g. KrikriJinja.default_engine), so this can't rely on the single-fiber-at-a-time guarantee of the default scheduler. An RWLock (not a Mutex) because filter/test/global lookups happen on every evaluation and must run concurrently with each other; only registration and cache inserts need exclusivity.

Source
tests
Source
undefined
Source
with_host_context(context : HostContext) : Engine

Derives an engine that hands context to every registered filter, test, and function invoked while rendering or evaluating.

Source
with_undefined(undefined : Undefined) : Engine
Source