An encapsulation of the scope in which the bodies of tags evaluate. It’s used to provide a controlled, isolated namespace which remains the same from tag to tag.
Create a new RenderState::Scope with its initial
tag locals set to locals.
# File lib/inversion/renderstate.rb, line 24
def initialize( locals={} )
@locals = locals
end
Return the tag local with the specified name.
# File lib/inversion/renderstate.rb, line 30
def []( name )
return @locals[ name.to_sym ]
end
Set the tag local with the specified name to
value.
# File lib/inversion/renderstate.rb, line 36
def []=( name, value )
@locals[ name.to_sym ] = value
end
Return the Hash of tag locals the belongs to this scope.
# File lib/inversion/renderstate.rb, line 49
def __locals__
return @locals
end
The main trickery behind this class – intercept tag locals as method calls and map them into values from the Scope’s locals.
# File lib/inversion/renderstate.rb, line 61
def method_missing( sym, *args, &block )
return super unless sym =~ %r^\w+$/
@locals[ sym ]
end