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
# File 'lib/volt/page/bindings/base_binding.rb', line 14

def initialize(page, target, context, binding_name)
  @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

#dom_sectionObject



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

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

#queue_updateObject



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

def queue_update
  if Volt.server?
    # Run right away
    update
  else
    @page.draw_cycle.queue(self)
  end
end

#removeObject



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

def remove
  @dom_section.remove if @dom_section

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

#remove_anchorsObject



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

def remove_anchors
  @dom_section.remove_anchors if @dom_section
end

#value_from_getter(getter) ⇒ Object



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

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