Sha256: f98f0625b5c097a55496791fb27019cae0382450dad61e3ac56ab8d29bbb87b3

Contents?: true

Size: 1.46 KB

Versions: 23

Compression:

Stored size: 1.46 KB

Contents

require 'volt/page/bindings/base_binding'

class TemplateRenderer < BaseBinding
  attr_reader :context
  def initialize(target, context, binding_name, template_name)
    # puts "new template renderer: #{context.inspect} - #{binding_name.inspect}"
    super(target, context, binding_name)

    # puts "Template Name: #{template_name}"
    @template = $page.templates[template_name]
    @sub_bindings = []

    if @template
      html = @template['html']
      bindings = @template['bindings']
    else
      html = "<div>-- &lt; missing template #{template_name.inspect.gsub('<', '&lt;').gsub('>', '&gt;')} &gt; --</div>"
      bindings = {}
    end

    bindings = self.section.set_content_and_rezero_bindings(html, bindings)

    bindings.each_pair do |id,bindings_for_id|
      bindings_for_id.each do |binding|
        @sub_bindings << binding.call(target, context, id)
      end
    end
    
    if @context.respond_to?(:dom_ready)
      @context.dom_ready
    end

  end

  def remove
    # puts "Remove Template: #{self} - #{@sub_bindings.inspect}"

    # Remove all of the sub-bindings
    # @sub_bindings.each(&:remove)
    
    @sub_bindings.each do |binding|
      # puts "REMOVE: #{binding.inspect}"
      binding.remove
      # puts "REMOVED"
    end

    @sub_bindings = []
    
    super

    # Let the controller know we removed
    if @context.respond_to?(:dom_removed)
      @context.dom_removed
    end
    
  end
  
  def remove_anchors
    section.remove_anchors
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
volt-0.5.4 lib/volt/page/template_renderer.rb
volt-0.5.3 lib/volt/page/template_renderer.rb
volt-0.5.2 lib/volt/page/template_renderer.rb
volt-0.5.1 lib/volt/page/template_renderer.rb
volt-0.5.0 lib/volt/page/template_renderer.rb
volt-0.4.18 lib/volt/page/template_renderer.rb
volt-0.4.17 lib/volt/page/template_renderer.rb
volt-0.4.15 lib/volt/page/template_renderer.rb
volt-0.4.14 lib/volt/page/template_renderer.rb
volt-0.4.12 lib/volt/page/template_renderer.rb
volt-0.4.11 lib/volt/page/template_renderer.rb
volt-0.4.10 lib/volt/page/template_renderer.rb
volt-0.4.9 lib/volt/page/template_renderer.rb
volt-0.4.8 lib/volt/page/template_renderer.rb
volt-0.4.7 lib/volt/page/template_renderer.rb
volt-0.4.5 lib/volt/page/template_renderer.rb
volt-0.4.4 lib/volt/page/template_renderer.rb
volt-0.4.3 lib/volt/page/template_renderer.rb
volt-0.4.2 lib/volt/page/template_renderer.rb
volt-0.4.1 lib/volt/page/template_renderer.rb