class Crinja::Context

Overview

A context holds information about the state of runtime execution. This includes tracking of local variables and call stacks, access to global features and configuration settings.

Contexts form a hierarchical structure, where sub-contexts inherit from their parents, but don't pollute the outer contexts with local scoped values. Creating instances is not useful as it’s created automatically at various stages of the template evaluation and should not be created by hand.

Defined in:

runtime/context.cr

Constant Summary

AUTOESCAPE_DEFAULT = false

Constructors

Instance Method Summary

Instance methods inherited from class Crinja::Util::ScopeMap(String, Crinja::Value)

[](key : K) [], []=(*args, **options)
[]=(*args, **options, &)
[]=
, clear(*args, **options)
clear(*args, **options, &)
clear
, delete(*args, **options)
delete(*args, **options, &)
delete
, entries entries, has_key?(key : K) has_key?, has_value?(value : V) has_value?, inspect(io : IO) inspect, keys keys, merge!(*args, **options)
merge!(*args, **options, &)
merge!
, parent parent, scope scope, size size, undefined undefined, values values

Constructor methods inherited from class Crinja::Util::ScopeMap(String, Crinja::Value)

new(parent : Crinja::Util::ScopeMap(K, V) | Nil = nil, scope = nil) new

Constructor Detail

def self.new(bindings : Variables) #

def self.new(parent : Context | Nil = nil, bindings : Variables | Nil = nil) #

Instance Method Detail

def []=(key : String, value : Variables) #

Set variable key to value value in local scope.


def []=(key : String, value : Value) #

Set variable key to value value in local scope.


def []=(key : String, value) #

Set variable key to value value in local scope.


def all_macros #

def autoescape : Bool | Nil #

def autoescape=(autoescape : Bool | Nil) #

def autoescape? #

Determines if autoescape is enabled in this or any parent context.


def block_context #

def block_context=(block_context : NamedTuple(name: String, index: Int32) | Nil) #

def extend_path_stack : Crinja::Context::CallStack #

def has_macro?(name) #

def import_path_stack : Crinja::Context::CallStack #

def include_path_stack : Crinja::Context::CallStack #

def inspect(io) #

def macro(name) : Callable #

def macro_stack : Crinja::Context::CallStack #


def merge!(context : Crinja::Context) #

def merge!(bindings) #

Merges values in bindings into local scope.


def parent : Context | Nil #

Returns the parent context. It must not be altered.


def pretty_print(pp) #

def register_macro(makro) #

def root_macros #

Returns macros defined in the root context.


def session_bindings #

Returns the local variables whose scope is this context.


def undefined #

Returns an undefined value.


def unpack(vars : Array(String), values : Value) #