Class: ComponentParty::ActionView::ComponentRenderer
- Inherits:
-
ActionView::TemplateRenderer
- Object
- ActionView::TemplateRenderer
- ComponentParty::ActionView::ComponentRenderer
- Defined in:
- lib/component_party/action_view/component_renderer.rb
Defined Under Namespace
Classes: TagWrapperDecorator
Instance Attribute Summary collapse
-
#component_path ⇒ void
readonly
Returns the value of attribute component_path.
-
#lookup_context ⇒ void
readonly
Returns the value of attribute lookup_context.
Instance Method Summary collapse
- #create_view_model(context, options) ⇒ void
- #decorate_template(template) ⇒ void
- #find_vm_class(options) ⇒ void
-
#initialize(lookup_context, component_path) ⇒ ComponentRenderer
constructor
A new instance of ComponentRenderer.
- #render(context, options) ⇒ void
-
#render_template(template, layout_name = nil, locals = nil) ⇒ void
:nodoc:.
- #template_path_from_component_path(component_path, template_file_name: ComponentParty.configuration.template_file_name) ⇒ void
Constructor Details
#initialize(lookup_context, component_path) ⇒ ComponentRenderer
Returns a new instance of 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 (readonly)
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 (readonly)
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
33 34 35 36 37 38 39 40 |
# File 'lib/component_party/action_view/component_renderer.rb', line 33 def create_view_model(context, ) view_model_data = [:view_model_data] || {} view_model_data[:view] = context vm_class = find_vm_class() vm_class.new(view_model_data) end |
#decorate_template(template) ⇒ void
29 30 31 |
# 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) ⇒ void
42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/component_party/action_view/component_renderer.rb', line 42 def find_vm_class() if [:custom_view_model] if [:custom_view_model] == true vm_file_path = Pathname.new([:component]).join(ComponentParty.configuration.view_model_file_name).to_s ActiveSupport::Inflector.camelize(vm_file_path).constantize else [: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, ) [:template] = template_path_from_component_path([:component]) [:locals] = { vm: create_view_model(context, ) } super(context, ) end |
#render_template(template, layout_name = nil, locals = nil) ⇒ void
:nodoc:
20 21 22 |
# File 'lib/component_party/action_view/component_renderer.rb', line 20 def render_template(context, template, layout_name = nil, locals = nil) #:nodoc: super(context, decorate_template(template), layout_name, locals) end |
#template_path_from_component_path(component_path, template_file_name: ComponentParty.configuration.template_file_name) ⇒ void
55 56 57 |
# 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 |