Sha256: 1f4422d968703e32544f5a971ed2e2a46ca0be99a7f921c5e44a8de19e365328

Contents?: true

Size: 1.28 KB

Versions: 6

Compression:

Stored size: 1.28 KB

Contents

require 'volt/page/bindings/base_binding'

class TemplateRenderer < BaseBinding
  attr_reader :context
  def initialize(page, target, context, binding_name, template_name)
    # puts "new template renderer: #{context.inspect} - #{binding_name.inspect}"
    super(page, 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(page, target, context, id)
      end
    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
  end
  
  def remove_anchors
    section.remove_anchors
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
volt-0.6.5 lib/volt/page/template_renderer.rb
volt-0.6.4 lib/volt/page/template_renderer.rb
volt-0.6.3 lib/volt/page/template_renderer.rb
volt-0.6.2 lib/volt/page/template_renderer.rb
volt-0.6.1 lib/volt/page/template_renderer.rb
volt-0.6.0 lib/volt/page/template_renderer.rb