Class: BaseBinding

Inherits:
Object show all
Defined in:
lib/volt/page/bindings/base_binding.rb

Overview

The BaseBinding class is the base for all bindings. It takes 4 arguments that should be passed up from the children (via super)

  1. page - this class instance should provide:

    - a #templates methods that returns a hash for templates
    - an #events methods that returns an instance of DocumentEvents
    
  2. target - an DomTarget or AttributeTarget

  3. context - the context object the binding will be evaluated in

  4. binding_name - the id for the comment (or id for attributes) where the

    binding will be inserted.
    

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(page, target, context, binding_name) ⇒ BaseBinding

Returns a new instance of BaseBinding.



14
15
16
17
18
19
20
21
22
# File 'lib/volt/page/bindings/base_binding.rb', line 14

def initialize(page, target, context, binding_name)
  # puts "NEW #{context.inspect} - #{self.inspect}"
  @page = page
  @target = target
  @context = context
  @binding_name = binding_name

  @@binding_number ||= 10000
end

Instance Attribute Details

#binding_nameObject

Returns the value of attribute binding_name.



12
13
14
# File 'lib/volt/page/bindings/base_binding.rb', line 12

def binding_name
  @binding_name
end

#contextObject

Returns the value of attribute context.



12
13
14
# File 'lib/volt/page/bindings/base_binding.rb', line 12

def context
  @context
end

#targetObject

Returns the value of attribute target.



12
13
14
# File 'lib/volt/page/bindings/base_binding.rb', line 12

def target
  @target
end

Instance Method Details

#queue_updateObject



41
42
43
44
45
46
47
48
# File 'lib/volt/page/bindings/base_binding.rb', line 41

def queue_update
  if Volt.server?
    # Run right away
    update
  else

  end
end

#removeObject



28
29
30
31
32
33
34
35
# File 'lib/volt/page/bindings/base_binding.rb', line 28

def remove
  section.remove

  # Clear any references
  @target = nil
  @context = nil
  @section = nil
end

#remove_anchorsObject



37
38
39
# File 'lib/volt/page/bindings/base_binding.rb', line 37

def remove_anchors
  section.remove_anchors
end

#sectionObject



24
25
26
# File 'lib/volt/page/bindings/base_binding.rb', line 24

def section
  @section ||= target.section(@binding_name)
end

#value_from_getter(getter) ⇒ Object



50
51
52
53
# File 'lib/volt/page/bindings/base_binding.rb', line 50

def value_from_getter(getter)
  # Evaluate the getter proc in the context
  return @context.instance_eval(&getter)
end