Module: ViewComponentDevtools::Component

Defined in:
lib/view_component_devtools/component.rb

Defined Under Namespace

Modules: ClassMethods

Constant Summary collapse

MARKER_PREFIX =
"view-component-devtools"

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
# File 'lib/view_component_devtools/component.rb', line 10

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#render_inObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/view_component_devtools/component.rb', line 32

def render_in(...)
  return super unless State.active?

   = {
    name: self.class.name,
    source_location: component_source_location,
    properties: view_component_devtools_properties
  }

  rendered = State.with_component() { super }
  component_id = [:devtools_id]
  return rendered unless component_id

  marker_id = Base64.strict_encode64(component_id)
  start_marker = "<!--#{MARKER_PREFIX}:start:#{marker_id}-->".html_safe
  end_marker = "<!--#{MARKER_PREFIX}:end:#{marker_id}-->".html_safe

  start_marker + rendered.to_s.html_safe + end_marker
end