Sha256: 49340ed6ef19a84316e61e3c991cd65a69d2a0de7e7430cd35e3c61d7a7ce808

Contents?: true

Size: 811 Bytes

Versions: 2

Compression:

Stored size: 811 Bytes

Contents

require 'volt/page/bindings/base_binding'

class ContentBinding < BaseBinding
  def initialize(page, target, context, binding_name, getter)
    super(page, target, context, binding_name)

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

    # Run the initial render
    update

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

  def update
    value = @value.cur.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.
    section.html = value.gsub("\n", "<br />\n")
  end

  def remove
    if @changed_listener
      @changed_listener.remove
      @changed_listener = nil
    end

    super
  end


end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
volt-0.7.13 lib/volt/page/bindings/content_binding.rb
volt-0.7.12 lib/volt/page/bindings/content_binding.rb