class Liquid::Context

Overview

A Context object provides the variables used by the Template object. These variables are stored as key-value pairs of type String, Liquid::Any.

Defined in:

liquid/context.cr
liquid/json.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(strict : Bool) #

DEPRECATED Use initialize(ErrorMode) instead.


[View source]
def self.new(error_mode : Liquid::Context::ErrorMode = :lax, data : Hash(String, Liquid::Any) = Hash(String, Any).new) #

Creates a new Context with the given error_mode and data.


[View source]

Instance Method Detail

def [](var : String) : Any #

Alias for #get


[View source]
def []=(var, value : Any) : Any #

Alias for #set


[View source]
def []=(var, value : Any::Type) : Any #

Alias for #set


[View source]
def []=(var : String, val : Array(String)) #

DEPRECATED Use #set instead.


[View source]
def []=(var : String, val : Hash(String, String)) #

DEPRECATED Use #set instead.


[View source]
def []?(var : String) : Any | Nil #

Returns the value for the variable given by var, or nil if the variable isn't found.

This doesn't trigger any exceptions or store any errors if the variable doesn't exists.


[View source]
def error_mode : ErrorMode #

[View source]
def error_mode=(error_mode : ErrorMode) #

[View source]

Returns a list of errors found when rendering using this context.


[View source]
def get(var, strict : Bool) #

DEPRECATED Use #[] or #[]? instead.


[View source]
def get(var : String) : Any #

Fetch a variable from context, add UndefinedVariable error if the variable isn't found and behave according the error mode.


[View source]
def lax?(*args, **options) #

[View source]
def lax?(*args, **options, &) #

[View source]
def set(var : String, value : Any) : Any #

Sets the value of var to the given value.


[View source]
def set(var : String, value : Any::Type) : Any #

Sets the value for var to an instance of Liquid::Any generated from value.


[View source]
def set(var : String, json : JSON::Any) : Nil #

Set the contents of a JSON::Any to the context.

NOTE You need to require "liquid/json" to use this method.


[View source]
def strict : Bool #

DEPRECATED Use #error_mode instead.


[View source]
def strict=(value : Bool) : Bool #

DEPRECATED Use #error_mode= instead.


[View source]
def strict?(*args, **options) #

[View source]
def strict?(*args, **options, &) #

[View source]
def to_s(io : IO) #
Description copied from class Reference

Appends a short String representation of this object which includes its class name and its object address.

class Person
  def initialize(@name : String, @age : Int32)
  end
end

Person.new("John", 32).to_s # => #<Person:0x10a199f20>

[View source]
def warn?(*args, **options) #

[View source]
def warn?(*args, **options, &) #

[View source]