Class: TemplateRenderer

Inherits:
BaseBinding show all
Defined in:
lib/volt/templates/template_renderer.rb

Instance Attribute Summary collapse

Attributes inherited from BaseBinding

#binding_name, #target

Instance Method Summary collapse

Methods inherited from BaseBinding

#queue_update, #section, #value_from_getter

Constructor Details

#initialize(target, context, binding_name, template_name) ⇒ TemplateRenderer

Returns a new instance of TemplateRenderer.



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/volt/templates/template_renderer.rb', line 5

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

Instance Attribute Details

#contextObject (readonly)

Returns the value of attribute context.



4
5
6
# File 'lib/volt/templates/template_renderer.rb', line 4

def context
  @context
end

Instance Method Details

#removeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/volt/templates/template_renderer.rb', line 35

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

#remove_anchorsObject



58
59
60
# File 'lib/volt/templates/template_renderer.rb', line 58

def remove_anchors
  section.remove_anchors
end