Class: ComponentBinding
- Inherits:
-
TemplateBinding
- Object
- BaseBinding
- TemplateBinding
- ComponentBinding
- 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
-
#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.
Methods inherited from TemplateBinding
#call_ready, #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 27 28 29 30 31 32 |
# 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_class = get_controller(controller_name) model_with_parent = {parent: @context}.merge(@model || {}) if controller_class # 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_class.new(*args) @controller = current_context else # There is not a controller current_context = SubContext.new(model_with_parent, $page) @controller = nil end @current_template = TemplateRenderer.new(@page, @target, current_context, @binding_name, full_path) call_ready end |