Class: ContentBinding

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

Instance Attribute Summary

Attributes inherited from BaseBinding

#binding_name, #context, #target

Instance Method Summary collapse

Methods inherited from BaseBinding

#queue_update, #remove_anchors, #section, #value_from_getter

Constructor Details

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

Returns a new instance of ContentBinding.



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/volt/templates/content_binding.rb', line 4

def initialize(target, context, binding_name, getter)
  # puts "new content binding: #{getter}"
  super(target, context, binding_name)

  # Find the source for the content binding
  @value = value_from_getter(getter)

  # Run the initial render
  update

  @changed_listener = @value.on('changed') { update }
end

Instance Method Details

#removeObject



27
28
29
30
31
32
# File 'lib/volt/templates/content_binding.rb', line 27

def remove
  @changed_listener.remove
  @changed_listener = nil

  super
end

#updateObject



17
18
19
20
21
22
23
24
25
# File 'lib/volt/templates/content_binding.rb', line 17

def update
  value = @value.cur.or('')
  
  # Exception values display the exception as a string
  value = value.to_s
  
  # Update the text in this section
  section.text = value
end