Class: ActionComponent::Component::Renderer
- Inherits:
-
ActionView::TemplateRenderer
- Object
- ActionView::TemplateRenderer
- ActionComponent::Component::Renderer
- Defined in:
- lib/actioncomponent/component/renderer.rb
Defined Under Namespace
Classes: ComponentTemplateFileNotFound
Instance Attribute Summary collapse
-
#view_model ⇒ void
readonly
Returns the value of attribute view_model.
Instance Method Summary collapse
- #apply_html_namespacing(raw_html, component_path) ⇒ void
-
#initialize(lookup_context, view_model) ⇒ Renderer
constructor
A new instance of Renderer.
- #render(component_path:) ⇒ void
- #template_path_from_component_path(component_path, template_file_name: ActionComponent.configuration.template_file_name) ⇒ void
Constructor Details
#initialize(lookup_context, view_model) ⇒ Renderer
Returns a new instance of Renderer.
9 10 11 12 |
# File 'lib/actioncomponent/component/renderer.rb', line 9 def initialize(lookup_context, view_model) @lookup_context = lookup_context @view_model = view_model end |
Instance Attribute Details
#view_model ⇒ void (readonly)
Returns the value of attribute view_model.
7 8 9 |
# File 'lib/actioncomponent/component/renderer.rb', line 7 def view_model @view_model end |
Instance Method Details
#apply_html_namespacing(raw_html, component_path) ⇒ void
25 26 27 28 |
# File 'lib/actioncomponent/component/renderer.rb', line 25 def apply_html_namespacing(raw_html, component_path) component_id = component_path.gsub(%r{^/}, '').tr('/', '-') "<div class='action-component' data-action-component-id='#{component_id}'>" + raw_html + '</div>'.html_safe end |
#render(component_path:) ⇒ void
14 15 16 17 18 19 |
# File 'lib/actioncomponent/component/renderer.rb', line 14 def render(component_path:) file_path = template_path_from_component_path(component_path) rendered = super(view_model, file: file_path) rendered = apply_html_namespacing(rendered, component_path) ActionView::OutputBuffer.new(rendered) end |
#template_path_from_component_path(component_path, template_file_name: ActionComponent.configuration.template_file_name) ⇒ void
21 22 23 |
# File 'lib/actioncomponent/component/renderer.rb', line 21 def template_path_from_component_path(component_path, template_file_name: ActionComponent.configuration.template_file_name) File.join(component_path, template_file_name).to_s end |