Class: Volt::ContentBinding

Inherits:
BaseBinding show all
Defined in:
lib/volt/page/bindings/content_binding.rb

Instance Attribute Summary

Attributes inherited from BaseBinding

#binding_name, #context, #target

Instance Method Summary collapse

Methods inherited from BaseBinding

#dom_section, #remove_anchors

Constructor Details

#initialize(page, target, context, binding_name, getter) ⇒ ContentBinding

Returns a new instance of ContentBinding.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/volt/page/bindings/content_binding.rb', line 5

def initialize(page, target, context, binding_name, getter)
  # puts "New Content Binding: #{self.inspect}"
  super(page, target, context, binding_name)

  # Listen for changes
  @computation = -> do
    begin
      update(@context.instance_eval(&getter))
    rescue => e
      Volt.logger.error("ContentBinding Error: #{e.inspect}")
      update('')
    end
  end.watch!
end

Instance Method Details

#removeObject



31
32
33
34
35
36
# File 'lib/volt/page/bindings/content_binding.rb', line 31

def remove
  @computation.stop if @computation
  @computation = nil

  super
end

#update(value) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/volt/page/bindings/content_binding.rb', line 20

def update(value)
  value            = value.or('')

  # Exception values display the exception as a string
  value            = value.to_s

  # Update the html in this section
  # TODO: Move the formatter into another class.
  dom_section.html = value.gsub("\n", "<br />\n")
end