class ComponentParty::ActionView::ComponentRenderer
Attributes
component_path[R]
lookup_context[R]
Public Class Methods
new(lookup_context, component_path)
click to toggle source
Calls superclass method
# File lib/component_party/action_view/component_renderer.rb, line 8 def initialize(lookup_context, component_path) @component_path = component_path super(lookup_context) end
Public Instance Methods
create_view_model(context, options)
click to toggle source
# File lib/component_party/action_view/component_renderer.rb, line 33 def create_view_model(context, options) view_model_data = options[:view_model_data] || {} view_model_data[:view] = context vm_class = find_vm_class(options) vm_class.new(view_model_data) end
decorate_template(template)
click to toggle source
# File lib/component_party/action_view/component_renderer.rb, line 29 def decorate_template(template) ComponentParty::ActionView::ComponentRenderer::TagWrapperDecorator.new(template, component_path) end
find_vm_class(options)
click to toggle source
# File lib/component_party/action_view/component_renderer.rb, line 42 def find_vm_class(options) if options[:custom_view_model] if options[:custom_view_model] == true vm_file_path = Pathname.new(options[:component]).join(ComponentParty.configuration.view_model_file_name).to_s ActiveSupport::Inflector.camelize(vm_file_path).constantize else options[:custom_view_model] end else ComponentParty::ViewModel end end
render(context, options)
click to toggle source
Calls superclass method
# File lib/component_party/action_view/component_renderer.rb, line 13 def render(context, options) options[:template] = template_path_from_component_path(options[:component]) options[:locals] = { vm: create_view_model(context, options) } super(context, options) end
template_path_from_component_path(component_path, template_file_name: ComponentParty.configuration.template_file_name)
click to toggle source
# File lib/component_party/action_view/component_renderer.rb, line 55 def template_path_from_component_path(component_path, template_file_name: ComponentParty.configuration.template_file_name) Pathname.new(component_path).join(template_file_name).to_s end