view_component-fragment_caching 0.7.0 → 0.8.0
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 +4 -4
- data/lib/view_component/fragment_caching/engine.rb +24 -0
- data/lib/view_component/fragment_caching/trackers/ruby_view_component_tracking.rb +50 -0
- data/lib/view_component/fragment_caching/trackers/view_component_tracking.rb +8 -49
- data/lib/view_component/fragment_caching/trackers.rb +45 -0
- data/lib/view_component/fragment_caching/version.rb +1 -1
- metadata +6 -5
- data/config/initializers/view_component/fragment_caching.rb +0 -19
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b8b6990769a19acb1f4a70339cd7c8fec0a43f6cadd030568471e5a72fe1d633
|
|
4
|
+
data.tar.gz: 064343d922e051b79dc121c5772a4a75324232d5c38e5fe5d2399378b95871e0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: aa6a351505f2324192ae1c81239f87a09e071629beabed7a084fbd8a6b2137ac746615810fc4e3d3fd748a52b036310ab7770f7b80b8330dd3dffc0fbf653b34
|
|
7
|
+
data.tar.gz: 997b33c12886d3899c0511abbc504b84bafb45162da96b85d5669c98c306ea34eb147381398987c0a5df78469053bf51bf5c0b4651f9e453c34f22313e6a2878
|
|
@@ -2,6 +2,30 @@ module ViewComponent
|
|
|
2
2
|
module FragmentCaching
|
|
3
3
|
class Engine < ::Rails::Engine
|
|
4
4
|
isolate_namespace ViewComponent::FragmentCaching
|
|
5
|
+
|
|
6
|
+
config.before_initialize do
|
|
7
|
+
ActiveSupport.on_load :action_controller do
|
|
8
|
+
next unless self == ActionController::Base
|
|
9
|
+
|
|
10
|
+
ViewComponent::FragmentCaching.initialize! context: self
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
config.after_initialize do
|
|
15
|
+
ActionView::DependencyTracker::ERBTracker.prepend ViewComponent::FragmentCaching::Trackers::ViewComponentTracking
|
|
16
|
+
|
|
17
|
+
if Rails.version >= '8.1'
|
|
18
|
+
require 'action_view/dependency_tracker/ruby_tracker'
|
|
19
|
+
ActionView::DependencyTracker::RubyTracker.prepend ViewComponent::FragmentCaching::Trackers::RubyViewComponentTracking
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
ActionView::Digestor::Node.prepend ViewComponent::FragmentCaching::Digestors::WithViewComponentRb
|
|
23
|
+
|
|
24
|
+
ViewComponent::FragmentCaching::Resolvers::ViewComponentResolver::VIEW_COMPONENT_RUBY_HANDLER.tap do |vc_rb|
|
|
25
|
+
ActionView::Template.register_template_handler vc_rb, ActionView::Template::Handlers::ERB.new
|
|
26
|
+
ActionView::DependencyTracker.register_tracker vc_rb, ActionView::DependencyTracker::ERBTracker
|
|
27
|
+
end
|
|
28
|
+
end
|
|
5
29
|
end
|
|
6
30
|
end
|
|
7
31
|
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module ViewComponent
|
|
2
|
+
module FragmentCaching
|
|
3
|
+
module Trackers
|
|
4
|
+
module RubyViewComponentTracking
|
|
5
|
+
def dependencies
|
|
6
|
+
super |
|
|
7
|
+
view_component_inheritance_dependencies |
|
|
8
|
+
explicit_view_component_dependencies
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
private
|
|
12
|
+
|
|
13
|
+
def render_dependencies
|
|
14
|
+
base_render_deps = super
|
|
15
|
+
|
|
16
|
+
vc_render_deps = []
|
|
17
|
+
render_calls = template.source.split(/\brender\b/).drop(1)
|
|
18
|
+
render_calls.each do |arguments|
|
|
19
|
+
add_view_component_dependency vc_render_deps, arguments
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
base_render_deps | vc_render_deps
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def add_view_component_dependency(dependencies, arguments)
|
|
26
|
+
arguments.scan VIEW_COMPONENT_RENDER_ARGUMENTS do
|
|
27
|
+
match = Regexp.last_match.named_captures.symbolize_keys
|
|
28
|
+
component_name = match[:view_component]
|
|
29
|
+
next if component_name.blank?
|
|
30
|
+
|
|
31
|
+
path = component_name.underscore
|
|
32
|
+
dependencies << path if dependencies.exclude? path
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def view_component_inheritance_dependencies
|
|
37
|
+
scan_source VIEW_COMPONENT_INHERITANCE_DEPENDENCY
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def explicit_view_component_dependencies
|
|
41
|
+
scan_source EXPLICIT_VIEW_COMPONENT_DEPENDENCY
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def scan_source(pattern)
|
|
45
|
+
template.source.scan(pattern).flatten.uniq.map(&:underscore)
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -2,49 +2,8 @@ module ViewComponent
|
|
|
2
2
|
module FragmentCaching
|
|
3
3
|
module Trackers
|
|
4
4
|
module ViewComponentTracking
|
|
5
|
-
EXPLICIT_VIEW_COMPONENT_DEPENDENCY = /# View Component Dependency: (\S+)/.freeze
|
|
6
|
-
private_constant :EXPLICIT_VIEW_COMPONENT_DEPENDENCY
|
|
7
|
-
|
|
8
|
-
CAMEL_PHRASE = /(?:([A-Z]+[a-z]*[0-9]*)+)/.freeze
|
|
9
|
-
private_constant :CAMEL_PHRASE
|
|
10
|
-
|
|
11
|
-
MODULE_NAME = /(?:((::)?#{CAMEL_PHRASE}+)+)/.freeze
|
|
12
|
-
private_constant :MODULE_NAME
|
|
13
|
-
|
|
14
|
-
VIEW_COMPONENT_NAME = /(?:#{MODULE_NAME}?(::)?Component)/.freeze
|
|
15
|
-
private_constant :VIEW_COMPONENT_NAME
|
|
16
|
-
|
|
17
|
-
MODULE_NAME_END = /(?:\b[^:])/.freeze
|
|
18
|
-
private_constant :MODULE_NAME_END
|
|
19
|
-
|
|
20
|
-
INVOKE_METHOD = /(?:\s*\.\s*(((public_)?send?(\s*\(?\s*):)?))/.freeze
|
|
21
|
-
private_constant :INVOKE_METHOD
|
|
22
|
-
|
|
23
|
-
INITIALIZE_METHOD_NAME = /(?:\b(new|with_collection)\b)/.freeze
|
|
24
|
-
private_constant :INITIALIZE_METHOD_NAME
|
|
25
|
-
|
|
26
|
-
VIEW_COMPONENT_RENDER_ARGUMENTS = /
|
|
27
|
-
\A
|
|
28
|
-
(?:\s*\(?\s*)
|
|
29
|
-
(?<view_component>#{VIEW_COMPONENT_NAME})
|
|
30
|
-
(?:#{INVOKE_METHOD})
|
|
31
|
-
(?:#{INITIALIZE_METHOD_NAME})
|
|
32
|
-
/xm.freeze
|
|
33
|
-
private_constant :VIEW_COMPONENT_RENDER_ARGUMENTS
|
|
34
|
-
|
|
35
|
-
CLASS_INHERITANCE = /(?:\s*\bclass\s+#{MODULE_NAME}\s*<\s*)/.freeze
|
|
36
|
-
private_constant :CLASS_INHERITANCE
|
|
37
|
-
|
|
38
|
-
VIEW_COMPONENT_INHERITANCE_DEPENDENCY = /
|
|
39
|
-
(?:#{CLASS_INHERITANCE})
|
|
40
|
-
(?<view_component>#{VIEW_COMPONENT_NAME})
|
|
41
|
-
(?:#{MODULE_NAME_END})
|
|
42
|
-
/xm.freeze
|
|
43
|
-
private_constant :VIEW_COMPONENT_INHERITANCE_DEPENDENCY
|
|
44
|
-
|
|
45
5
|
def dependencies
|
|
46
|
-
|
|
47
|
-
explicit_dependencies |
|
|
6
|
+
super |
|
|
48
7
|
view_component_inheritance_dependencies |
|
|
49
8
|
explicit_view_component_dependencies
|
|
50
9
|
end
|
|
@@ -52,15 +11,15 @@ module ViewComponent
|
|
|
52
11
|
private
|
|
53
12
|
|
|
54
13
|
def render_dependencies
|
|
55
|
-
|
|
56
|
-
render_calls = source.split(/\brender\b/).drop(1)
|
|
14
|
+
base_render_deps = super
|
|
57
15
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
end
|
|
16
|
+
vc_render_deps = []
|
|
17
|
+
render_calls = source.split(/\brender\b/).drop(1)
|
|
18
|
+
render_calls.each do |arguments|
|
|
19
|
+
add_dependencies vc_render_deps, arguments, VIEW_COMPONENT_RENDER_ARGUMENTS
|
|
63
20
|
end
|
|
21
|
+
|
|
22
|
+
base_render_deps | vc_render_deps
|
|
64
23
|
end
|
|
65
24
|
|
|
66
25
|
def add_dependencies(render_dependencies, arguments, pattern)
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
module ViewComponent
|
|
2
|
+
module FragmentCaching
|
|
3
|
+
module Trackers
|
|
4
|
+
EXPLICIT_VIEW_COMPONENT_DEPENDENCY = /# View Component Dependency: (\S+)/.freeze
|
|
5
|
+
private_constant :EXPLICIT_VIEW_COMPONENT_DEPENDENCY
|
|
6
|
+
|
|
7
|
+
CAMEL_PHRASE = /(?:([A-Z]+[a-z]*[0-9]*)+)/.freeze
|
|
8
|
+
private_constant :CAMEL_PHRASE
|
|
9
|
+
|
|
10
|
+
MODULE_NAME = /(?:((::)?#{CAMEL_PHRASE}+)+)/.freeze
|
|
11
|
+
private_constant :MODULE_NAME
|
|
12
|
+
|
|
13
|
+
VIEW_COMPONENT_NAME = /(?:#{MODULE_NAME}?(::)?Component)/.freeze
|
|
14
|
+
private_constant :VIEW_COMPONENT_NAME
|
|
15
|
+
|
|
16
|
+
MODULE_NAME_END = /(?:\b[^:])/.freeze
|
|
17
|
+
private_constant :MODULE_NAME_END
|
|
18
|
+
|
|
19
|
+
INVOKE_METHOD = /(?:\s*\.\s*(((public_)?send?(\s*\(?\s*):)?))/.freeze
|
|
20
|
+
private_constant :INVOKE_METHOD
|
|
21
|
+
|
|
22
|
+
INITIALIZE_METHOD_NAME = /(?:\b(new|with_collection)\b)/.freeze
|
|
23
|
+
private_constant :INITIALIZE_METHOD_NAME
|
|
24
|
+
|
|
25
|
+
VIEW_COMPONENT_RENDER_ARGUMENTS = /
|
|
26
|
+
\A
|
|
27
|
+
(?:\s*\(?\s*)
|
|
28
|
+
(?<view_component>#{VIEW_COMPONENT_NAME})
|
|
29
|
+
(?:#{INVOKE_METHOD})
|
|
30
|
+
(?:#{INITIALIZE_METHOD_NAME})
|
|
31
|
+
/xm.freeze
|
|
32
|
+
private_constant :VIEW_COMPONENT_RENDER_ARGUMENTS
|
|
33
|
+
|
|
34
|
+
CLASS_INHERITANCE = /(?:\s*\bclass\s+#{MODULE_NAME}\s*<\s*)/.freeze
|
|
35
|
+
private_constant :CLASS_INHERITANCE
|
|
36
|
+
|
|
37
|
+
VIEW_COMPONENT_INHERITANCE_DEPENDENCY = /
|
|
38
|
+
(?:#{CLASS_INHERITANCE})
|
|
39
|
+
(?<view_component>#{VIEW_COMPONENT_NAME})
|
|
40
|
+
(?:#{MODULE_NAME_END})
|
|
41
|
+
/xm.freeze
|
|
42
|
+
private_constant :VIEW_COMPONENT_INHERITANCE_DEPENDENCY
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: view_component-fragment_caching
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Patrick Arnett
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2026-02-25 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rails
|
|
@@ -19,7 +19,7 @@ dependencies:
|
|
|
19
19
|
version: '7.0'
|
|
20
20
|
- - "<"
|
|
21
21
|
- !ruby/object:Gem::Version
|
|
22
|
-
version: '8.
|
|
22
|
+
version: '8.2'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -29,7 +29,7 @@ dependencies:
|
|
|
29
29
|
version: '7.0'
|
|
30
30
|
- - "<"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: '8.
|
|
32
|
+
version: '8.2'
|
|
33
33
|
- !ruby/object:Gem::Dependency
|
|
34
34
|
name: view_component
|
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -167,12 +167,13 @@ files:
|
|
|
167
167
|
- MIT-LICENSE
|
|
168
168
|
- README.md
|
|
169
169
|
- Rakefile
|
|
170
|
-
- config/initializers/view_component/fragment_caching.rb
|
|
171
170
|
- lib/view_component/fragment_caching.rb
|
|
172
171
|
- lib/view_component/fragment_caching/configuration.rb
|
|
173
172
|
- lib/view_component/fragment_caching/digestors/with_view_component_rb.rb
|
|
174
173
|
- lib/view_component/fragment_caching/engine.rb
|
|
175
174
|
- lib/view_component/fragment_caching/resolvers/view_component_resolver.rb
|
|
175
|
+
- lib/view_component/fragment_caching/trackers.rb
|
|
176
|
+
- lib/view_component/fragment_caching/trackers/ruby_view_component_tracking.rb
|
|
176
177
|
- lib/view_component/fragment_caching/trackers/view_component_tracking.rb
|
|
177
178
|
- lib/view_component/fragment_caching/version.rb
|
|
178
179
|
homepage:
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
ActiveSupport.on_load :action_controller do
|
|
2
|
-
next unless self == ActionController::Base
|
|
3
|
-
|
|
4
|
-
ViewComponent::FragmentCaching.initialize! context: self
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
Rails.application.reloader.to_prepare do
|
|
8
|
-
ActiveSupport.on_load :action_view do
|
|
9
|
-
ActiveSupport.on_load :after_initialize do
|
|
10
|
-
ActionView::DependencyTracker::ERBTracker.prepend ViewComponent::FragmentCaching::Trackers::ViewComponentTracking
|
|
11
|
-
ActionView::Digestor::Node.prepend ViewComponent::FragmentCaching::Digestors::WithViewComponentRb
|
|
12
|
-
|
|
13
|
-
ViewComponent::FragmentCaching::Resolvers::ViewComponentResolver::VIEW_COMPONENT_RUBY_HANDLER.tap do |vc_rb|
|
|
14
|
-
ActionView::Template.register_template_handler vc_rb, ActionView::Template::Handlers::ERB.new
|
|
15
|
-
ActionView::DependencyTracker.register_tracker vc_rb, ActionView::DependencyTracker::ERBTracker
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|