polaris_view_components 2.5.1 → 3.0.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
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0401eafd4296a2e4a90c6d94df41561a3c229bc6516e7f51e09d4277c35daff7
|
|
4
|
+
data.tar.gz: 700dcba3e74a4f5f9369823326a00cec589a18f44047ad4fd4392a0053ac78f0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bd8cd4053ee75a8f6acc119c95805f4635bf1dd2c78a53e020719f07211fd00822ed0834150ba9ec3daf7aa992b366f6a7c442522af6b1ec7ace92f32f7395c4
|
|
7
|
+
data.tar.gz: 14ba3fd7007a8c0bc1d5c7884b0ace90fec13368b34586c81e4709251e6c934153fb019eee2cc60a6d26567c22de43c7d2d6bd652b268ec98ca5d119667d92e9
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
require "polaris/view_components/codemods/v3_slot_setters"
|
|
2
|
-
|
|
3
1
|
namespace :polaris_view_components do
|
|
4
2
|
desc "Setup Polaris::ViewComponents for the app"
|
|
5
3
|
task :install do
|
|
6
4
|
system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/install.rb", __dir__)}"
|
|
7
5
|
end
|
|
8
|
-
|
|
9
|
-
task detect_legacy_slots: :environment do
|
|
10
|
-
ARGV.each { |a| task a.to_sym {} }
|
|
11
|
-
custom_paths = ARGV.compact.map { |path| Rails.root.join(path) }
|
|
12
|
-
Polaris::ViewComponents::Codemods::V3SlotSetters.new(view_path: custom_paths).call
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
task migrate_legacy_slots: :environment do
|
|
16
|
-
ARGV.each { |a| task a.to_sym {} }
|
|
17
|
-
custom_paths = ARGV.compact.map { |path| Rails.root.join(path) }
|
|
18
|
-
Polaris::ViewComponents::Codemods::V3SlotSetters.new(view_path: custom_paths, migrate: true).call
|
|
19
|
-
end
|
|
20
6
|
end
|
metadata
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: polaris_view_components
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version:
|
|
4
|
+
version: 3.0.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Dan Gamble
|
|
8
8
|
- Kirill Platonov
|
|
9
|
-
autorequire:
|
|
10
9
|
bindir: bin
|
|
11
10
|
cert_chain: []
|
|
12
|
-
date:
|
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
13
12
|
dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
|
15
14
|
name: rails
|
|
@@ -17,14 +16,14 @@ dependencies:
|
|
|
17
16
|
requirements:
|
|
18
17
|
- - ">="
|
|
19
18
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
19
|
+
version: 7.1.0
|
|
21
20
|
type: :runtime
|
|
22
21
|
prerelease: false
|
|
23
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
23
|
requirements:
|
|
25
24
|
- - ">="
|
|
26
25
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
26
|
+
version: 7.1.0
|
|
28
27
|
- !ruby/object:Gem::Dependency
|
|
29
28
|
name: view_component
|
|
30
29
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -34,7 +33,7 @@ dependencies:
|
|
|
34
33
|
version: 3.0.0
|
|
35
34
|
- - "<"
|
|
36
35
|
- !ruby/object:Gem::Version
|
|
37
|
-
version: 4.
|
|
36
|
+
version: 4.2.0
|
|
38
37
|
type: :runtime
|
|
39
38
|
prerelease: false
|
|
40
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -44,7 +43,7 @@ dependencies:
|
|
|
44
43
|
version: 3.0.0
|
|
45
44
|
- - "<"
|
|
46
45
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: 4.
|
|
46
|
+
version: 4.2.0
|
|
48
47
|
- !ruby/object:Gem::Dependency
|
|
49
48
|
name: webdrivers
|
|
50
49
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -65,14 +64,14 @@ dependencies:
|
|
|
65
64
|
requirements:
|
|
66
65
|
- - "~>"
|
|
67
66
|
- !ruby/object:Gem::Version
|
|
68
|
-
version: '4.
|
|
67
|
+
version: '4.9'
|
|
69
68
|
type: :development
|
|
70
69
|
prerelease: false
|
|
71
70
|
version_requirements: !ruby/object:Gem::Requirement
|
|
72
71
|
requirements:
|
|
73
72
|
- - "~>"
|
|
74
73
|
- !ruby/object:Gem::Version
|
|
75
|
-
version: '4.
|
|
74
|
+
version: '4.9'
|
|
76
75
|
- !ruby/object:Gem::Dependency
|
|
77
76
|
name: minitest
|
|
78
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -143,7 +142,6 @@ dependencies:
|
|
|
143
142
|
- - ">="
|
|
144
143
|
- !ruby/object:Gem::Version
|
|
145
144
|
version: '0'
|
|
146
|
-
description:
|
|
147
145
|
email:
|
|
148
146
|
- dan@dangamble.co.uk
|
|
149
147
|
executables: []
|
|
@@ -929,7 +927,6 @@ files:
|
|
|
929
927
|
- config/locales/en.yml
|
|
930
928
|
- lib/install/install.rb
|
|
931
929
|
- lib/polaris/view_components.rb
|
|
932
|
-
- lib/polaris/view_components/codemods/v3_slot_setters.rb
|
|
933
930
|
- lib/polaris/view_components/engine.rb
|
|
934
931
|
- lib/polaris/view_components/version.rb
|
|
935
932
|
- lib/polaris_view_components.rb
|
|
@@ -939,7 +936,6 @@ licenses:
|
|
|
939
936
|
- MIT
|
|
940
937
|
metadata:
|
|
941
938
|
allowed_push_host: https://rubygems.org
|
|
942
|
-
post_install_message:
|
|
943
939
|
rdoc_options: []
|
|
944
940
|
require_paths:
|
|
945
941
|
- lib
|
|
@@ -947,15 +943,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
947
943
|
requirements:
|
|
948
944
|
- - ">="
|
|
949
945
|
- !ruby/object:Gem::Version
|
|
950
|
-
version: 2.
|
|
946
|
+
version: 3.2.0
|
|
951
947
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
952
948
|
requirements:
|
|
953
949
|
- - ">="
|
|
954
950
|
- !ruby/object:Gem::Version
|
|
955
951
|
version: '0'
|
|
956
952
|
requirements: []
|
|
957
|
-
rubygems_version: 3.
|
|
958
|
-
signing_key:
|
|
953
|
+
rubygems_version: 3.6.9
|
|
959
954
|
specification_version: 4
|
|
960
955
|
summary: ViewComponents for Polaris Design System
|
|
961
956
|
test_files: []
|
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Polaris
|
|
4
|
-
module ViewComponents
|
|
5
|
-
# Usage:
|
|
6
|
-
#
|
|
7
|
-
# Run via rake task:
|
|
8
|
-
#
|
|
9
|
-
# bin/rails polaris_view_components:detect_legacy_slots
|
|
10
|
-
# bin/rails polaris_view_components:migrate_legacy_slots
|
|
11
|
-
# bin/rails polaris_view_components:migrate_legacy_slots app/views
|
|
12
|
-
#
|
|
13
|
-
# Or run via rails console if you need to pass custom paths:
|
|
14
|
-
#
|
|
15
|
-
# Polaris::ViewComponents::Codemods::V3SlotSetters.new(
|
|
16
|
-
# view_path: Rails.root.join("app/views"),
|
|
17
|
-
# ).call
|
|
18
|
-
module Codemods
|
|
19
|
-
class V3SlotSetters
|
|
20
|
-
TEMPLATE_LANGUAGES = %w[erb slim haml].join(",").freeze
|
|
21
|
-
RENDER_REGEX = /render[( ](?<component>\w+(?:::\w+)*)\.new[) ]+(do|\{) \|(?<arg>\w+)\b/ # standard:disable Lint/MixedRegexpCaptureTypes
|
|
22
|
-
|
|
23
|
-
Suggestion = Struct.new(:file, :line, :message)
|
|
24
|
-
|
|
25
|
-
def initialize(view_component_path: [], view_path: [], migrate: false)
|
|
26
|
-
Rails.application.eager_load!
|
|
27
|
-
|
|
28
|
-
@view_component_path = view_component_path
|
|
29
|
-
@view_path = view_path
|
|
30
|
-
@migrate = migrate
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
def call
|
|
34
|
-
puts "Using ViewComponent path: #{view_component_paths.join(", ")}"
|
|
35
|
-
puts "Using Views path: #{view_paths.join(", ")}"
|
|
36
|
-
puts "#{view_components.size} ViewComponents found"
|
|
37
|
-
puts "#{slottable_components.size} ViewComponents using Slots found"
|
|
38
|
-
puts "#{view_component_files.size} ViewComponent templates found"
|
|
39
|
-
puts "#{view_files.size} view files found"
|
|
40
|
-
process_all_files
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def process_all_files
|
|
44
|
-
all_files.each do |file|
|
|
45
|
-
process_file(file)
|
|
46
|
-
end
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
def process_file(file)
|
|
50
|
-
@suggestions = []
|
|
51
|
-
@suggestions += scan_exact_matches(file)
|
|
52
|
-
@suggestions += scan_uncertain_matches(file)
|
|
53
|
-
|
|
54
|
-
if @suggestions.any?
|
|
55
|
-
puts
|
|
56
|
-
puts "File: #{file}"
|
|
57
|
-
@suggestions.each do |s|
|
|
58
|
-
puts "=> line #{s.line}: #{s.message}"
|
|
59
|
-
end
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
|
|
63
|
-
private
|
|
64
|
-
|
|
65
|
-
def scan_exact_matches(file)
|
|
66
|
-
[].tap do |suggestions|
|
|
67
|
-
rendered_components = []
|
|
68
|
-
content = File.read(file)
|
|
69
|
-
|
|
70
|
-
if (render_match = content.match(RENDER_REGEX))
|
|
71
|
-
component = render_match[:component]
|
|
72
|
-
arg = render_match[:arg]
|
|
73
|
-
|
|
74
|
-
if registered_slots.key?(component.constantize)
|
|
75
|
-
used_slots_names = registered_slots[component.constantize]
|
|
76
|
-
rendered_components << {component: component, arg: arg, slots: used_slots_names}
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
File.open(file, "r+") do |f|
|
|
81
|
-
lines = []
|
|
82
|
-
f.each_line do |line|
|
|
83
|
-
rendered_components.each do |rendered_component|
|
|
84
|
-
arg = rendered_component[:arg]
|
|
85
|
-
slots = rendered_component[:slots]
|
|
86
|
-
|
|
87
|
-
if (matches = line.scan(/#{arg}\.#{Regexp.union(slots)}/))
|
|
88
|
-
matches.each do |match|
|
|
89
|
-
new_value = match.gsub("#{arg}.", "#{arg}.with_")
|
|
90
|
-
message = if @migrate
|
|
91
|
-
"replaced `#{match}` with `#{new_value}`"
|
|
92
|
-
else
|
|
93
|
-
"probably replace `#{match}` with `#{new_value}`"
|
|
94
|
-
end
|
|
95
|
-
suggestions << Suggestion.new(file, f.lineno, message)
|
|
96
|
-
if @migrate
|
|
97
|
-
line.gsub!("#{arg}.", "#{arg}.with_")
|
|
98
|
-
end
|
|
99
|
-
end
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
lines << line
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
if @migrate
|
|
106
|
-
f.rewind
|
|
107
|
-
f.write(lines.join)
|
|
108
|
-
end
|
|
109
|
-
end
|
|
110
|
-
end
|
|
111
|
-
end
|
|
112
|
-
|
|
113
|
-
def scan_uncertain_matches(file)
|
|
114
|
-
[].tap do |suggestions|
|
|
115
|
-
File.open(file, "r+") do |f|
|
|
116
|
-
lines = []
|
|
117
|
-
f.each_line do |line|
|
|
118
|
-
if (matches = line.scan(/(?<!\s)\.(?<slot>#{Regexp.union(all_registered_slot_names)})\b/))
|
|
119
|
-
matches.flatten.each do |match|
|
|
120
|
-
next if @suggestions.find { |s| s.file == file && s.line == f.lineno }
|
|
121
|
-
|
|
122
|
-
message = if @migrate
|
|
123
|
-
"replaced `#{match}` with `with_#{match}`"
|
|
124
|
-
else
|
|
125
|
-
"maybe replace `#{match}` with `with_#{match}`"
|
|
126
|
-
end
|
|
127
|
-
suggestions << Suggestion.new(file, f.lineno, message)
|
|
128
|
-
if @migrate
|
|
129
|
-
line.gsub!(/(?<!\s)\.(#{match})\b/, ".with_\\1")
|
|
130
|
-
end
|
|
131
|
-
end
|
|
132
|
-
end
|
|
133
|
-
lines << line
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
if @migrate
|
|
137
|
-
f.rewind
|
|
138
|
-
f.write(lines.join)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
end
|
|
143
|
-
|
|
144
|
-
def view_components
|
|
145
|
-
ViewComponent::Base.descendants
|
|
146
|
-
end
|
|
147
|
-
|
|
148
|
-
def slottable_components
|
|
149
|
-
view_components.select do |comp|
|
|
150
|
-
comp.registered_slots.any?
|
|
151
|
-
end
|
|
152
|
-
end
|
|
153
|
-
|
|
154
|
-
def registered_slots
|
|
155
|
-
@registered_slots ||= {}.tap do |slots|
|
|
156
|
-
puts
|
|
157
|
-
puts "Detected slots:"
|
|
158
|
-
slottable_components.each do |comp|
|
|
159
|
-
puts "- `#{comp}` has slots: #{comp.registered_slots.keys.join(", ")}"
|
|
160
|
-
slots[comp] = comp.registered_slots.map do |slot_name, slot|
|
|
161
|
-
normalized_slot_name(slot_name, slot)
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
def all_registered_slot_names
|
|
168
|
-
@all_registered_slot_names ||= registered_slots.values.flatten.uniq
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
def view_component_files
|
|
172
|
-
Dir.glob(Pathname.new(File.join(view_component_path_glob, "**", "*.{rb,#{TEMPLATE_LANGUAGES}}")))
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
def view_files
|
|
176
|
-
Dir.glob(Pathname.new(File.join(view_path_glob, "**", "*.{#{TEMPLATE_LANGUAGES}}")))
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
def all_files
|
|
180
|
-
view_component_files + view_files
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
def view_component_paths
|
|
184
|
-
@view_component_paths ||= [
|
|
185
|
-
Rails.application.config.view_component.view_component_path,
|
|
186
|
-
@view_component_path
|
|
187
|
-
].flatten.compact.uniq
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
def view_component_path_glob
|
|
191
|
-
return view_component_paths.first if view_component_paths.size == 1
|
|
192
|
-
|
|
193
|
-
"{#{view_component_paths.join(",")}}"
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
def rails_view_paths
|
|
197
|
-
ActionController::Base.view_paths.select do |path|
|
|
198
|
-
path.to_s.include?(Rails.root.to_s)
|
|
199
|
-
end.map(&:to_s)
|
|
200
|
-
end
|
|
201
|
-
|
|
202
|
-
def view_paths
|
|
203
|
-
@view_paths ||= [
|
|
204
|
-
rails_view_paths,
|
|
205
|
-
Rails.application.config.view_component.preview_paths,
|
|
206
|
-
@view_path
|
|
207
|
-
].flatten.compact.uniq
|
|
208
|
-
end
|
|
209
|
-
|
|
210
|
-
def view_path_glob
|
|
211
|
-
return view_paths.first if view_paths.size == 1
|
|
212
|
-
|
|
213
|
-
"{#{view_paths.join(",")}}"
|
|
214
|
-
end
|
|
215
|
-
|
|
216
|
-
def normalized_slot_name(slot_name, slot)
|
|
217
|
-
slot[:collection] ? ActiveSupport::Inflector.singularize(slot_name) : slot_name.to_s
|
|
218
|
-
end
|
|
219
|
-
end
|
|
220
|
-
end
|
|
221
|
-
end
|
|
222
|
-
end
|