Class: Scope

Inherits:
Object show all
Defined in:
lib/volt/server/scope.rb

Overview

Template parsing is fairly simple at the moment. Basically we walk the dom and do two types of replacements. 1) replacement in text nodes 2) attribute replacements

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(outer_binding_number = nil) ⇒ Scope

Returns a new instance of Scope.



9
10
11
12
13
14
# File 'lib/volt/server/scope.rb', line 9

def initialize(outer_binding_number=nil)
  # For block bindings, the outer binding number lets us know what the name
  # of the comments are that go before/after this scope block.
  @outer_binding_number = outer_binding_number
  @bindings = {}
end

Instance Attribute Details

#bindingsObject

Returns the value of attribute bindings.



7
8
9
# File 'lib/volt/server/scope.rb', line 7

def bindings
  @bindings
end

#closed_block_scopesObject

Returns the value of attribute closed_block_scopes.



7
8
9
# File 'lib/volt/server/scope.rb', line 7

def closed_block_scopes
  @closed_block_scopes
end

#last_if_bindingObject

Returns the value of attribute last_if_binding.



7
8
9
# File 'lib/volt/server/scope.rb', line 7

def last_if_binding
  @last_if_binding
end

#outer_binding_numberObject

Returns the value of attribute outer_binding_number.



7
8
9
# File 'lib/volt/server/scope.rb', line 7

def outer_binding_number
  @outer_binding_number
end

Instance Method Details

#add_binding(binding_name, setup_code) ⇒ Object



21
22
23
24
# File 'lib/volt/server/scope.rb', line 21

def add_binding(binding_name, setup_code)
  @bindings[binding_name] ||= []
  @bindings[binding_name] << setup_code
end

#add_closed_child_scope(scope) ⇒ Object



16
17
18
19
# File 'lib/volt/server/scope.rb', line 16

def add_closed_child_scope(scope)
  @closed_block_scopes ||= []
  @closed_block_scopes << scope
end

#close_if_binding!Object



34
35
36
37
38
39
40
41
# File 'lib/volt/server/scope.rb', line 34

def close_if_binding!
  if @last_if_binding
    binding_name, if_binding_setup = @last_if_binding
    @last_if_binding = nil
    
    add_binding(binding_name, if_binding_setup.to_setup_code)
  end
end

#current_if_bindingObject



30
31
32
# File 'lib/volt/server/scope.rb', line 30

def current_if_binding
  @last_if_binding
end

#start_if_binding(binding_name, if_binding_setup) ⇒ Object



26
27
28
# File 'lib/volt/server/scope.rb', line 26

def start_if_binding(binding_name, if_binding_setup)
  @last_if_binding = [binding_name, if_binding_setup]
end