class Inversion::RenderState::Scope
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.
Public Class Methods
new( locals={}, fragments={} )
click to toggle source
Create a new RenderState::Scope
with its initial tag locals set to ‘locals`.
# File lib/inversion/renderstate.rb, line 23 def initialize( locals={}, fragments={} ) @locals = locals @fragments = fragments end
Public Instance Methods
+( values )
click to toggle source
[]( name )
click to toggle source
Return the tag local with the specified ‘name`.
# File lib/inversion/renderstate.rb, line 30 def []( name ) return @locals[ name.to_sym ] end
[]=( name, value )
click to toggle source
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
__fragments__()
click to toggle source
Returns the Hash of rendered fragments that belong to this scope.
# File lib/inversion/renderstate.rb, line 56 def __fragments__ return @fragments end
__locals__()
click to toggle source
Return the Hash of tag locals the belongs to this scope.
# File lib/inversion/renderstate.rb, line 49 def __locals__ return @locals end
Also aliased as: to_hash
Protected Instance Methods
method_missing( sym, *args, &block )
click to toggle source
The main trickery behind this class – intercept tag locals as method calls and map them into values from the Scope’s locals.
Calls superclass method
# File lib/inversion/renderstate.rb, line 67 def method_missing( sym, *args, &block ) return super unless sym =~ /^\w+$/ return @locals[ sym ].nil? ? @fragments[ sym ] : @locals[ sym ] end