Object
Context keeps the variable stack and resolves variables, as well as keywords
context['variable'] = 'testing' context['variable'] #=> 'testing' context['true'] #=> true context['10.2232'] #=> 10.2232 context.stack do context['bob'] = 'bobsen' end context['bob'] #=> nil class Context
# File lib/liquid/context.rb, line 18 def initialize(environments = {}, outer_scope = {}, registers = {}, rethrow_errors = false) @environments = [environments].flatten @scopes = [(outer_scope || {})] @registers = registers @errors = [] @rethrow_errors = rethrow_errors squash_instance_assigns_with_environments @interrupts = [] end
Only allow String, Numeric, Hash, Array, Proc, Boolean or Liquid::Drop
# File lib/liquid/context.rb, line 115 def []=(key, value) @scopes[0][key] = value end
Adds filters to this context.
Note that this does not register the filters with the main Template object. see Template.register_filter for that
# File lib/liquid/context.rb, line 37 def add_filters(filters) filters = [filters].flatten.compact filters.each do |f| raise ArgumentError, "Expected module but got: #{f.class}" unless f.is_a?(Module) Strainer.add_known_filter(f) strainer.extend(f) end end
# File lib/liquid/context.rb, line 110 def clear_instance_assigns @scopes[0] = {} end
# File lib/liquid/context.rb, line 62 def handle_error(e) errors.push(e) raise if @rethrow_errors case e when SyntaxError "Liquid syntax error: #{e.message}" else "Liquid error: #{e.message}" end end
are there any not handled interrupts?
# File lib/liquid/context.rb, line 48 def has_interrupt? !@interrupts.empty? end
# File lib/liquid/context.rb, line 123 def has_key?(key) resolve(key) != nil end
# File lib/liquid/context.rb, line 74 def invoke(method, *args) strainer.invoke(method, *args) end
Merge a hash of variables in the current local scope
# File lib/liquid/context.rb, line 85 def merge(new_scopes) @scopes[0].merge!(new_scopes) end
Pop from the stack. use Context#stack instead
# File lib/liquid/context.rb, line 90 def pop raise ContextError if @scopes.size == 1 @scopes.shift end
pop an interrupt from the stack
# File lib/liquid/context.rb, line 58 def pop_interrupt @interrupts.pop end
Push new local scope on the stack. use Context#stack instead
# File lib/liquid/context.rb, line 79 def push(new_scope={}) @scopes.unshift(new_scope) raise StackLevelError, "Nesting too deep" if @scopes.length > 100 end
push an interrupt to the stack. this interrupt is considered not handled.
# File lib/liquid/context.rb, line 53 def push_interrupt(e) @interrupts.push(e) end
Generated with the Darkfish Rdoc Generator 2.