Class: ComponentBinding

Inherits:
TemplateBinding show all
Defined in:
lib/volt/page/bindings/component_binding.rb

Overview

Component bindings are the same as template bindings, but handle components and do not pass their context through

Instance Attribute Summary

Attributes inherited from BaseBinding

#binding_name, #context, #target

Instance Method Summary collapse

Methods inherited from TemplateBinding

#check_for_template?, #initialize, #path_for_template, #remove, #setup_path, #update

Methods inherited from BaseBinding

#initialize, #queue_update, #remove, #remove_anchors, #section, #value_from_getter

Constructor Details

This class inherits a constructor from TemplateBinding

Instance Method Details

#render_template(full_path, controller_name) ⇒ Object

The context for a component binding can be either the controller, or the component arguments (@model), with the $page as the context. This gives components access to the page collections.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/volt/page/bindings/component_binding.rb', line 9

def render_template(full_path, controller_name)
  # TODO: at the moment a :body section and a :title will both initialize different
  # controllers.  Maybe we should have a way to tie them together?
  controller = get_controller(controller_name)
  if controller
    # The user provided a controller, pass in the model as an argument (in a 
    # sub-context)
    args = []
    args << SubContext.new(@model) if @model
    
    current_context = controller.new(*args)
  else
    # The user didn't specify a model, create a 
    current_context = SubContext.new(@model || {}, $page)
  end

  @current_template = TemplateRenderer.new(@target, current_context, @binding_name, full_path)    
end