class ActionComponent::Component::Renderer

Attributes

view_model[R]

Public Class Methods

new(lookup_context, view_model) click to toggle source
# File lib/actioncomponent/component/renderer.rb, line 9
def initialize(lookup_context, view_model)
  @lookup_context = lookup_context
  @view_model = view_model
end

Public Instance Methods

apply_html_namespacing(raw_html, component_path) click to toggle source
# 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:) click to toggle source
Calls superclass method
# 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) click to toggle source
# 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