class Marten::Template::Context

Overview

A template context.

Defined in:

marten/template/context.cr
marten/template/context/block_stack.cr

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.new(values : Hash(String, Value)) #

Allows to initialize a new context from the specified values.


[View source]
def self.new #

Allows to initialize an empty context.


[View source]

Class Method Detail

def self.from(values : Context | Hash | NamedTuple | Nil, request : HTTP::Request) #

Initializes a context from a hash (or a named tuple) and an HTTP request.


[View source]
def self.from(values : Context | Hash | NamedTuple | Nil) #

Initializes a context from a hash or a named tuple.


[View source]

Instance Method Detail

def [](key : String | Symbol) : Value #

Returns a specific context value for a given key.


[View source]
def []=(key : String | Symbol, value : Value) #

Allows to add a new value into the context.


[View source]
def []=(key : String | Symbol, value) #

Allows to add a new value into the context.


[View source]
def []?(key : String | Symbol) : Value | Nil #

Returns a specific context value for a given key or nil if not found.


[View source]

Returns the blocks stack associated with the context.


[View source]
def empty? #

Returns true if the context is empty.


[View source]
def escape? : Bool #

Returns true if the context is marked for escaping.


[View source]
def handler : Marten::Handlers::Base? #

Returns the handler instance associated with the context if any.


[View source]
def handler=(handler : Marten::Handlers::Base | Nil) #

Allows to set the handler instance associated with the context.


[View source]
def has_key?(key : String | Symbol) #

Returns true if the context contains the specified key.


[View source]
def merge(other_context : self) #

Merges another context into the current one.


[View source]
def merge(other_context : Hash | NamedTuple) #

Merges a hash or a named tuple of context values into the current context.


[View source]
def stack(&) #

Stack another context hash and yields itself.


[View source]
def to_empty #

Returns a new empty context that retains the associated handler.


[View source]
def with_escape(new_escape : Bool, &) #

Returns a new context for which the escape flag is set to true or false.


[View source]