class ComponentParty::ActionView::ComponentRenderer::TagWrapperDecorator
Decorates the template renderer chosen to render the current view/template/file. It overrides the render method in order to wrap the rendered template in a tag with data attributes
Attributes
component_path[R]
Public Class Methods
new(target, component_path)
click to toggle source
Calls superclass method
# File lib/component_party/action_view/component_renderer/tag_wrapper_decorator.rb, line 8 def initialize(target, component_path) @component_path = component_path super(target) end
Public Instance Methods
apply_html_namespacing(raw_html)
click to toggle source
# File lib/component_party/action_view/component_renderer/tag_wrapper_decorator.rb, line 19 def apply_html_namespacing(raw_html) component_id = component_path.to_s.gsub(%r{^/}, '').tr('/', '-') html_tag_end_regex = %r{(/?)>} raw_html.sub(html_tag_end_regex) do " data-component-path='#{component_id}' #{Regexp.last_match(1)}>" end.html_safe end
render(context, options = {}, &block)
click to toggle source
# File lib/component_party/action_view/component_renderer/tag_wrapper_decorator.rb, line 13 def render(context, options = {}, &block) rendered = __getobj__.render(context, options, &block) rendered = apply_html_namespacing(rendered.to_s) ActionView::OutputBuffer.new(rendered) end