Sha256: e21bd9e3a63ad914c8ae223cf803e882e58f7f1cb13ff0502440bd23b3c2597b

Contents?: true

Size: 1.37 KB

Versions: 9

Compression:

Stored size: 1.37 KB

Contents

# 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.
class BaseBinding
  attr_accessor :target, :context, :binding_name

  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

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

  def remove
    section.remove if @section

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

  def remove_anchors
    section.remove_anchors
  end

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

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

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
volt-0.7.10 lib/volt/page/bindings/base_binding.rb
volt-0.7.9 lib/volt/page/bindings/base_binding.rb
volt-0.7.8 lib/volt/page/bindings/base_binding.rb
volt-0.7.7 lib/volt/page/bindings/base_binding.rb
volt-0.7.6 lib/volt/page/bindings/base_binding.rb
volt-0.7.5 lib/volt/page/bindings/base_binding.rb
volt-0.7.4 lib/volt/page/bindings/base_binding.rb
volt-0.7.3 lib/volt/page/bindings/base_binding.rb
volt-0.7.2 lib/volt/page/bindings/base_binding.rb