Sha256: 75dc6247cf402678e5d47f47f5d34aa270db8fa9a77f053ff1b79ad9212ec1fd

Contents?: true

Size: 1012 Bytes

Versions: 4

Compression:

Stored size: 1012 Bytes

Contents

require 'volt/page/bindings/base_binding'

module Volt
  class ContentBinding < BaseBinding
    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
          res = @context.instance_eval(&getter)
        rescue => e
          Volt.logger.error("ContentBinding Error: #{e.inspect}")
          ''
        end
      end.watch_and_resolve! do |result|
        update(result)
      end
    end

    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.text = value.gsub("\n", "<br />\n")
    end

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

      super
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
volt-0.8.27.beta7 lib/volt/page/bindings/content_binding.rb
volt-0.8.27.beta6 lib/volt/page/bindings/content_binding.rb
volt-0.8.27.beta5 lib/volt/page/bindings/content_binding.rb
volt-0.8.27.beta4 lib/volt/page/bindings/content_binding.rb