Class: Volt::ContentBinding
- Inherits:
-
BaseBinding
- Object
- BaseBinding
- Volt::ContentBinding
- Defined in:
- lib/volt/page/bindings/content_binding.rb
Instance Attribute Summary
Attributes inherited from BaseBinding
#binding_name, #context, #target
Instance Method Summary collapse
-
#initialize(page, target, context, binding_name, getter) ⇒ ContentBinding
constructor
A new instance of ContentBinding.
- #remove ⇒ Object
- #update(value) ⇒ Object
Methods inherited from BaseBinding
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
#remove ⇒ Object
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 |