Class: ComponentParty::ActionView::ComponentRenderer
- Inherits:
-
ActionView::TemplateRenderer
- Object
- ActionView::TemplateRenderer
- ComponentParty::ActionView::ComponentRenderer
show all
- Defined in:
- lib/component_party/action_view/component_renderer.rb
Defined Under Namespace
Classes: TagWrapperDecorator
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(lookup_context, component_path) ⇒ ComponentRenderer
8
9
10
11
|
# 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
|
Instance Attribute Details
#component_path ⇒ void
Returns the value of attribute component_path.
6
7
8
|
# File 'lib/component_party/action_view/component_renderer.rb', line 6
def component_path
@component_path
end
|
#lookup_context ⇒ void
Returns the value of attribute lookup_context.
5
6
7
|
# File 'lib/component_party/action_view/component_renderer.rb', line 5
def lookup_context
@lookup_context
end
|
Instance Method Details
#create_view_model(context, options) ⇒ void
27
28
29
30
31
32
33
34
|
# File 'lib/component_party/action_view/component_renderer.rb', line 27
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) ⇒ void
23
24
25
|
# File 'lib/component_party/action_view/component_renderer.rb', line 23
def decorate_template(template)
ComponentParty::ActionView::ComponentRenderer::TagWrapperDecorator.new(template, component_path)
end
|
#find_vm_class(options) ⇒ void
36
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/component_party/action_view/component_renderer.rb', line 36
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) ⇒ void
13
14
15
16
17
|
# File 'lib/component_party/action_view/component_renderer.rb', line 13
def render(context, options)
options[:file] = template_path_from_component_path(options[:component])
options[:locals] = { vm: create_view_model(context, options) }
super(context, options)
end
|
#render_template(template, layout_name = nil, locals = nil) ⇒ void
19
20
21
|
# File 'lib/component_party/action_view/component_renderer.rb', line 19
def render_template(template, layout_name = nil, locals = nil)
super(decorate_template(template), layout_name, locals)
end
|
#template_path_from_component_path(component_path, template_file_name: ComponentParty.configuration.template_file_name) ⇒ void
49
50
51
|
# File 'lib/component_party/action_view/component_renderer.rb', line 49
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
|