view_component_devtools 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9841af3364bbae0b7d4fb590a7ec9463476a68bb7b9c955e2d10dbf8da7657e2
|
|
4
|
+
data.tar.gz: d16c54119b57e272c70b6b4cfa15259cdc75aef61a85222dfa720383c34d0ba1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9a64b47d13bedfc1def0aec3bf2283ea598517f92558524ad4516db3607dec4a8500311478485881a5dd3fc219ce342bc7014902a80db0e21dd7e91ad4f7eb2f
|
|
7
|
+
data.tar.gz: d52edd88880944c3e307299f76e8e64e5352aed72943c21f11fd0f15aad634e80059940e1b7c23df0723b7d382b1ce43b93caf222e2e5882786d5fb90729bb2e
|
|
@@ -1,26 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "active_support/core_ext/string/output_safety"
|
|
4
|
+
require "base64"
|
|
5
|
+
|
|
3
6
|
module ViewComponentDevtools
|
|
4
7
|
module Component
|
|
8
|
+
MARKER_PREFIX = "view-component-devtools"
|
|
9
|
+
|
|
5
10
|
def self.included(base)
|
|
6
11
|
base.extend(ClassMethods)
|
|
7
12
|
end
|
|
8
13
|
|
|
9
14
|
module ClassMethods
|
|
10
|
-
def
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
def view_component_devtools_prop_names
|
|
16
|
-
declared = @view_component_devtools_props || []
|
|
17
|
-
inferred = component_initializer&.parameters&.filter_map do |kind, name|
|
|
18
|
-
name if %i[req opt keyreq key].include?(kind)
|
|
19
|
-
end || []
|
|
20
|
-
|
|
21
|
-
(declared + inferred).uniq.select do |name|
|
|
22
|
-
directly_defined_reader?(name)
|
|
23
|
-
end
|
|
15
|
+
def view_component_devtools_property_names
|
|
16
|
+
public_instance_methods(false).select do |name|
|
|
17
|
+
name != :render_in && instance_method(name).parameters.empty?
|
|
18
|
+
end.sort
|
|
24
19
|
end
|
|
25
20
|
|
|
26
21
|
private
|
|
@@ -32,15 +27,6 @@ module ViewComponentDevtools
|
|
|
32
27
|
|
|
33
28
|
instance_method(:initialize)
|
|
34
29
|
end
|
|
35
|
-
|
|
36
|
-
def directly_defined_reader?(name)
|
|
37
|
-
return false unless public_instance_methods(false).include?(name)
|
|
38
|
-
|
|
39
|
-
method = instance_method(name)
|
|
40
|
-
method.parameters.none? do |kind, _|
|
|
41
|
-
%i[req keyreq].include?(kind)
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
30
|
end
|
|
45
31
|
|
|
46
32
|
def render_in(...)
|
|
@@ -49,12 +35,23 @@ module ViewComponentDevtools
|
|
|
49
35
|
metadata = {
|
|
50
36
|
name: self.class.name,
|
|
51
37
|
source_location: component_source_location,
|
|
52
|
-
|
|
53
|
-
|
|
38
|
+
properties: self.class.view_component_devtools_property_names.to_h do |name|
|
|
39
|
+
value = public_send(name)
|
|
40
|
+
[name, value]
|
|
41
|
+
rescue StandardError => error
|
|
42
|
+
[name, "[error #{error.class.name}]"]
|
|
54
43
|
end
|
|
55
44
|
}
|
|
56
45
|
|
|
57
|
-
State.with_component(metadata) { super }
|
|
46
|
+
rendered = State.with_component(metadata) { super }
|
|
47
|
+
component_id = metadata[:devtools_id]
|
|
48
|
+
return rendered unless component_id
|
|
49
|
+
|
|
50
|
+
marker_id = Base64.strict_encode64(component_id)
|
|
51
|
+
start_marker = "<!--#{MARKER_PREFIX}:start:#{marker_id}-->".html_safe
|
|
52
|
+
end_marker = "<!--#{MARKER_PREFIX}:end:#{marker_id}-->".html_safe
|
|
53
|
+
|
|
54
|
+
start_marker + rendered.to_s.html_safe + end_marker
|
|
58
55
|
end
|
|
59
56
|
|
|
60
57
|
private
|
|
@@ -16,7 +16,6 @@ module ViewComponentDevtools
|
|
|
16
16
|
attr_accessor :allow_non_development,
|
|
17
17
|
:enabled,
|
|
18
18
|
:max_collection_size,
|
|
19
|
-
:max_components,
|
|
20
19
|
:max_depth,
|
|
21
20
|
:max_string_length,
|
|
22
21
|
:redact_keys
|
|
@@ -24,7 +23,6 @@ module ViewComponentDevtools
|
|
|
24
23
|
def initialize
|
|
25
24
|
@enabled = false
|
|
26
25
|
@allow_non_development = false
|
|
27
|
-
@max_components = 500
|
|
28
26
|
@max_depth = 8
|
|
29
27
|
@max_collection_size = 50
|
|
30
28
|
@max_string_length = 2_000
|
|
@@ -50,7 +50,6 @@ module ViewComponentDevtools
|
|
|
50
50
|
@component_stack = []
|
|
51
51
|
@event_stack = []
|
|
52
52
|
@component_count = 0
|
|
53
|
-
@truncated = false
|
|
54
53
|
@normalizer = Normalizer.new(configuration)
|
|
55
54
|
end
|
|
56
55
|
|
|
@@ -85,10 +84,10 @@ module ViewComponentDevtools
|
|
|
85
84
|
|
|
86
85
|
def payload
|
|
87
86
|
{
|
|
88
|
-
version:
|
|
87
|
+
version: 2,
|
|
89
88
|
requestId: request_id,
|
|
90
89
|
generatedAt: Time.now.utc.iso8601(3),
|
|
91
|
-
truncated:
|
|
90
|
+
truncated: false,
|
|
92
91
|
components:
|
|
93
92
|
}
|
|
94
93
|
end
|
|
@@ -98,21 +97,19 @@ module ViewComponentDevtools
|
|
|
98
97
|
attr_reader :component_stack, :components, :configuration, :event_stack, :normalizer
|
|
99
98
|
|
|
100
99
|
def build_node(payload, start_time)
|
|
101
|
-
if @component_count >= configuration.max_components
|
|
102
|
-
@truncated = true
|
|
103
|
-
return nil
|
|
104
|
-
end
|
|
105
|
-
|
|
106
100
|
@component_count += 1
|
|
107
101
|
metadata = component_stack.last
|
|
108
102
|
metadata = nil unless metadata&.fetch(:name, nil) == payload[:name]
|
|
103
|
+
id = "#{request_id}:#{@component_count}"
|
|
104
|
+
metadata[:devtools_id] = id if metadata
|
|
105
|
+
|
|
109
106
|
{
|
|
110
|
-
id
|
|
107
|
+
id:,
|
|
111
108
|
name: payload[:name] || metadata&.fetch(:name, nil) || "AnonymousComponent",
|
|
112
109
|
sourceLocation: payload[:identifier] || metadata&.fetch(:source_location, nil),
|
|
113
110
|
templateLocation: payload[:view_identifier],
|
|
114
111
|
durationMs: nil,
|
|
115
|
-
|
|
112
|
+
properties: normalizer.call(metadata&.fetch(:properties, {}) || {}),
|
|
116
113
|
children: [],
|
|
117
114
|
startedAt: start_time
|
|
118
115
|
}
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: view_component_devtools
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ViewComponent DevTools contributors
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-08-
|
|
10
|
+
date: 2026-08-12 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: activesupport
|