Sha256: 4a83e876eb7778e186cf192db7c90a7cd55dfb83400d52422f73c76d399e9e13

Contents?: true

Size: 1.17 KB

Versions: 7

Compression:

Stored size: 1.17 KB

Contents

require 'volt/page/bindings/template_binding'

# Component bindings are the same as template bindings, but handle components
# and do not pass their context through
class ComponentBinding < TemplateBinding
  # 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.
  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)
    model_with_parent = {parent: @context}.merge(@model || {})
    
    if controller
      # The user provided a controller, pass in the model as an argument (in a 
      # sub-context)
      args = []
      args << SubContext.new(model_with_parent) if @model
      
      current_context = controller.new(*args)
    else
      # There is not a controller
      current_context = SubContext.new(model_with_parent, $page)
    end

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
volt-0.5.16 lib/volt/page/bindings/component_binding.rb
volt-0.5.15 lib/volt/page/bindings/component_binding.rb
volt-0.5.14 lib/volt/page/bindings/component_binding.rb
volt-0.5.13 lib/volt/page/bindings/component_binding.rb
volt-0.5.12 lib/volt/page/bindings/component_binding.rb
volt-0.5.11 lib/volt/page/bindings/component_binding.rb
volt-0.5.10 lib/volt/page/bindings/component_binding.rb