stimulus_reflex 3.5.0.rc3 → 3.5.3
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/Gemfile.lock +144 -101
- data/README.md +2 -2
- data/app/assets/javascripts/stimulus_reflex.js +15 -13
- data/app/assets/javascripts/stimulus_reflex.umd.js +15 -12
- data/app/channels/stimulus_reflex/channel.rb +49 -53
- data/lib/generators/stimulus_reflex/stimulus_reflex_generator.rb +2 -2
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/cable_ready.js.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/index.js.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/app/javascript/config/stimulus_reflex.js.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +1 -1
- data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application.js.tt +1 -1
- data/lib/install/action_cable.rb +30 -30
- data/lib/install/broadcaster.rb +11 -11
- data/lib/install/bundle.rb +9 -9
- data/lib/install/compression.rb +5 -5
- data/lib/install/config.rb +22 -22
- data/lib/install/development.rb +19 -19
- data/lib/install/esbuild.rb +28 -28
- data/lib/install/example.rb +3 -3
- data/lib/install/importmap.rb +29 -29
- data/lib/install/initializers.rb +3 -3
- data/lib/install/mrujs.rb +25 -25
- data/lib/install/npm_packages.rb +7 -7
- data/lib/install/reflexes.rb +2 -2
- data/lib/install/shakapacker.rb +23 -23
- data/lib/install/spring.rb +7 -7
- data/lib/install/updatable.rb +7 -7
- data/lib/install/vite.rb +22 -22
- data/lib/install/webpacker.rb +27 -27
- data/lib/install/yarn.rb +9 -9
- data/lib/stimulus_reflex/html/document_fragment.rb +5 -3
- data/lib/stimulus_reflex/installer.rb +305 -277
- data/lib/stimulus_reflex/reflex.rb +14 -29
- data/lib/stimulus_reflex/reflex_data.rb +17 -17
- data/lib/stimulus_reflex/reflex_factory.rb +49 -26
- data/lib/stimulus_reflex/version.rb +1 -1
- data/lib/stimulus_reflex.rb +2 -0
- data/lib/tasks/stimulus_reflex/stimulus_reflex.rake +8 -8
- data/package.json +10 -10
- data/stimulus_reflex.gemspec +10 -8
- data/web-test-runner.config.mjs +14 -0
- data/yarn.lock +1278 -830
- metadata +34 -42
data/lib/install/vite.rb
CHANGED
@@ -2,27 +2,27 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
return if pack_path_missing?
|
5
|
+
return if StimulusReflex::Installer.pack_path_missing?
|
6
6
|
|
7
7
|
# verify that all critical dependencies are up to date; if not, queue for later
|
8
|
-
lines = package_json_path.readlines
|
8
|
+
lines = StimulusReflex::Installer.package_json_path.readlines
|
9
9
|
|
10
10
|
if !lines.index { |line| line =~ /^\s*["']stimulus-vite-helpers["']: ["']\^3["']/ }
|
11
|
-
add_package "stimulus-vite-helpers@^3"
|
11
|
+
StimulusReflex::Installer.add_package "stimulus-vite-helpers@^3"
|
12
12
|
else
|
13
13
|
say "⏩ @stimulus-vite-helpers npm package is already present. Skipping."
|
14
14
|
end
|
15
15
|
|
16
16
|
step_path = "/app/javascript/controllers/"
|
17
|
-
application_controller_src = fetch(step_path, "application_controller.js.tt")
|
18
|
-
application_controller_path = controllers_path / "application_controller.js"
|
19
|
-
application_js_src = fetch(step_path, "application.js.tt")
|
20
|
-
application_js_path = controllers_path / "application.js"
|
21
|
-
index_src = fetch(step_path, "index.js.vite.tt")
|
22
|
-
index_path = controllers_path / "index.js"
|
17
|
+
application_controller_src = StimulusReflex::Installer.fetch(step_path, "application_controller.js.tt")
|
18
|
+
application_controller_path = StimulusReflex::Installer.controllers_path / "application_controller.js"
|
19
|
+
application_js_src = StimulusReflex::Installer.fetch(step_path, "application.js.tt")
|
20
|
+
application_js_path = StimulusReflex::Installer.controllers_path / "application.js"
|
21
|
+
index_src = StimulusReflex::Installer.fetch(step_path, "index.js.vite.tt")
|
22
|
+
index_path = StimulusReflex::Installer.controllers_path / "index.js"
|
23
23
|
|
24
24
|
# create entrypoint/controllers, as well as the index, application and application_controller
|
25
|
-
empty_directory controllers_path unless controllers_path.exist?
|
25
|
+
empty_directory StimulusReflex::Installer.controllers_path unless StimulusReflex::Installer.controllers_path.exist?
|
26
26
|
|
27
27
|
copy_file(application_controller_src, application_controller_path) unless application_controller_path.exist?
|
28
28
|
copy_file(application_js_src, application_js_path) unless application_js_path.exist?
|
@@ -32,33 +32,33 @@ controllers_pattern = /import ['"](\.\.\/)?controllers['"]/
|
|
32
32
|
controllers_commented_pattern = /\s*\/\/\s*#{controllers_pattern}/
|
33
33
|
prefix = "..\/" # standard:disable Style/RedundantStringEscape
|
34
34
|
|
35
|
-
if pack.match?(controllers_pattern)
|
36
|
-
if pack.match?(controllers_commented_pattern)
|
37
|
-
proceed = if options.key? "uncomment"
|
38
|
-
options["uncomment"]
|
35
|
+
if StimulusReflex::Installer.pack.match?(controllers_pattern)
|
36
|
+
if StimulusReflex::Installer.pack.match?(controllers_commented_pattern)
|
37
|
+
proceed = if StimulusReflex::Installer.options.key? "uncomment"
|
38
|
+
StimulusReflex::Installer.options["uncomment"]
|
39
39
|
else
|
40
40
|
!no?("✨ Do you want to import your Stimulus controllers in application.js? (Y/n)")
|
41
41
|
end
|
42
42
|
|
43
43
|
if proceed
|
44
44
|
# uncomment_lines only works with Ruby comments 🙄
|
45
|
-
lines = pack_path.readlines
|
45
|
+
lines = StimulusReflex::Installer.pack_path.readlines
|
46
46
|
matches = lines.select { |line| line =~ controllers_commented_pattern }
|
47
47
|
lines[lines.index(matches.last).to_i] = "import \"#{prefix}controllers\"\n"
|
48
|
-
pack_path.write lines.join
|
49
|
-
say "✅ Uncommented Stimulus controllers import in #{friendly_pack_path}"
|
48
|
+
StimulusReflex::Installer.pack_path.write lines.join
|
49
|
+
say "✅ Uncommented Stimulus controllers import in #{StimulusReflex::Installer.friendly_pack_path}"
|
50
50
|
else
|
51
51
|
say "🤷 your Stimulus controllers are not being imported in your application.js. We trust that you have a reason for this."
|
52
52
|
end
|
53
53
|
else
|
54
|
-
say "⏩ Stimulus controllers are already being imported in #{friendly_pack_path}. Skipping."
|
54
|
+
say "⏩ Stimulus controllers are already being imported in #{StimulusReflex::Installer.friendly_pack_path}. Skipping."
|
55
55
|
end
|
56
56
|
else
|
57
|
-
lines = pack_path.readlines
|
57
|
+
lines = StimulusReflex::Installer.pack_path.readlines
|
58
58
|
matches = lines.select { |line| line =~ /^import / }
|
59
59
|
lines.insert lines.index(matches.last).to_i + 1, "import \"#{prefix}controllers\"\n"
|
60
|
-
pack_path.write lines.join
|
61
|
-
say "✅ Stimulus controllers imported in #{friendly_pack_path}"
|
60
|
+
StimulusReflex::Installer.pack_path.write lines.join
|
61
|
+
say "✅ Stimulus controllers imported in #{StimulusReflex::Installer.friendly_pack_path}"
|
62
62
|
end
|
63
63
|
|
64
|
-
complete_step :vite
|
64
|
+
StimulusReflex::Installer.complete_step :vite
|
data/lib/install/webpacker.rb
CHANGED
@@ -2,50 +2,50 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
return if pack_path_missing?
|
5
|
+
return if StimulusReflex::Installer.pack_path_missing?
|
6
6
|
|
7
7
|
# verify that all critical dependencies are up to date; if not, queue for later
|
8
|
-
lines = package_json_path.readlines
|
8
|
+
lines = StimulusReflex::Installer.package_json_path.readlines
|
9
9
|
if !lines.index { |line| line =~ /^\s*["']webpack["']: ["']\^4.46.0["']/ }
|
10
|
-
add_package "webpack@^4.46.0"
|
10
|
+
StimulusReflex::Installer.add_package "webpack@^4.46.0"
|
11
11
|
else
|
12
12
|
say "⏩ webpack npm package is already present. Skipping."
|
13
13
|
end
|
14
14
|
|
15
15
|
if !lines.index { |line| line =~ /^\s*["']webpack-cli["']: ["']\^3.3.12["']/ }
|
16
|
-
add_package "webpack-cli@^3.3.12"
|
16
|
+
StimulusReflex::Installer.add_package "webpack-cli@^3.3.12"
|
17
17
|
else
|
18
18
|
say "⏩ webpack-cli npm package is already present. Skipping."
|
19
19
|
end
|
20
20
|
|
21
21
|
if !lines.index { |line| line =~ /^\s*["']@rails\/webpacker["']: ["']\^5.4.3["']/ }
|
22
|
-
add_package "@rails/webpacker@^5.4.3"
|
22
|
+
StimulusReflex::Installer.add_package "@rails/webpacker@^5.4.3"
|
23
23
|
else
|
24
24
|
say "⏩ @rails/webpacker npm package is already present. Skipping."
|
25
25
|
end
|
26
26
|
|
27
27
|
if !lines.index { |line| line =~ /^\s*["']@hotwired\/stimulus-webpack-helpers["']: ["']\^1.0.1["']/ }
|
28
|
-
add_package "@hotwired/stimulus-webpack-helpers@^1.0.1"
|
28
|
+
StimulusReflex::Installer.add_package "@hotwired/stimulus-webpack-helpers@^1.0.1"
|
29
29
|
else
|
30
30
|
say "⏩ @hotwired/stimulus-webpack-helpers npm package is already present. Skipping."
|
31
31
|
end
|
32
32
|
|
33
33
|
if !lines.index { |line| line =~ /^\s*["']webpack-dev-server["']: ["']\^3.11.3["']/ }
|
34
|
-
add_dev_package "webpack-dev-server@^3.11.3"
|
34
|
+
StimulusReflex::Installer.add_dev_package "webpack-dev-server@^3.11.3"
|
35
35
|
else
|
36
36
|
say "⏩ @webpack-dev-server is already present. Skipping."
|
37
37
|
end
|
38
38
|
|
39
39
|
step_path = "/app/javascript/controllers/"
|
40
|
-
application_controller_src = fetch(step_path, "application_controller.js.tt")
|
41
|
-
application_controller_path = controllers_path / "application_controller.js"
|
42
|
-
application_js_src = fetch(step_path, "application.js.tt")
|
43
|
-
application_js_path = controllers_path / "application.js"
|
44
|
-
index_src = fetch(step_path, "index.js.webpacker.tt")
|
45
|
-
index_path = controllers_path / "index.js"
|
40
|
+
application_controller_src = StimulusReflex::Installer.fetch(step_path, "application_controller.js.tt")
|
41
|
+
application_controller_path = StimulusReflex::Installer.controllers_path / "application_controller.js"
|
42
|
+
application_js_src = StimulusReflex::Installer.fetch(step_path, "application.js.tt")
|
43
|
+
application_js_path = StimulusReflex::Installer.controllers_path / "application.js"
|
44
|
+
index_src = StimulusReflex::Installer.fetch(step_path, "index.js.webpacker.tt")
|
45
|
+
index_path = StimulusReflex::Installer.controllers_path / "index.js"
|
46
46
|
|
47
47
|
# create entrypoint/controllers, as well as the index, application and application_controller
|
48
|
-
empty_directory controllers_path unless controllers_path.exist?
|
48
|
+
empty_directory StimulusReflex::Installer.controllers_path unless StimulusReflex::Installer.controllers_path.exist?
|
49
49
|
|
50
50
|
copy_file(application_controller_src, application_controller_path) unless application_controller_path.exist?
|
51
51
|
# webpacker 5.4 did not colloquially feature a controllers/application.js file
|
@@ -55,36 +55,36 @@ copy_file(index_src, index_path) unless index_path.exist?
|
|
55
55
|
controllers_pattern = /import ['"]controllers['"]/
|
56
56
|
controllers_commented_pattern = /\s*\/\/\s*#{controllers_pattern}/
|
57
57
|
|
58
|
-
if pack.match?(controllers_pattern)
|
59
|
-
if pack.match?(controllers_commented_pattern)
|
60
|
-
proceed = if options.key? "uncomment"
|
61
|
-
options["uncomment"]
|
58
|
+
if StimulusReflex::Installer.pack.match?(controllers_pattern)
|
59
|
+
if StimulusReflex::Installer.pack.match?(controllers_commented_pattern)
|
60
|
+
proceed = if StimulusReflex::Installer.options.key? "uncomment"
|
61
|
+
StimulusReflex::Installer.options["uncomment"]
|
62
62
|
else
|
63
63
|
!no?("✨ Do you want to import your Stimulus controllers in application.js? (Y/n)")
|
64
64
|
end
|
65
65
|
|
66
66
|
if proceed
|
67
67
|
# uncomment_lines only works with Ruby comments 🙄
|
68
|
-
lines = pack_path.readlines
|
68
|
+
lines = StimulusReflex::Installer.pack_path.readlines
|
69
69
|
matches = lines.select { |line| line =~ controllers_commented_pattern }
|
70
70
|
lines[lines.index(matches.last).to_i] = "import \"controllers\"\n"
|
71
|
-
pack_path.write lines.join
|
72
|
-
say "✅ Uncommented Stimulus controllers import in #{friendly_pack_path}"
|
71
|
+
StimulusReflex::Installer.pack_path.write lines.join
|
72
|
+
say "✅ Uncommented Stimulus controllers import in #{StimulusReflex::Installer.friendly_pack_path}"
|
73
73
|
else
|
74
74
|
say "🤷 your Stimulus controllers are not being imported in your application.js. We trust that you have a reason for this."
|
75
75
|
end
|
76
76
|
else
|
77
|
-
say "⏩ Stimulus controllers are already being imported in #{friendly_pack_path}. Skipping."
|
77
|
+
say "⏩ Stimulus controllers are already being imported in #{StimulusReflex::Installer.friendly_pack_path}. Skipping."
|
78
78
|
end
|
79
79
|
else
|
80
|
-
lines = pack_path.readlines
|
80
|
+
lines = StimulusReflex::Installer.pack_path.readlines
|
81
81
|
matches = lines.select { |line| line =~ /^import / }
|
82
82
|
lines.insert lines.index(matches.last).to_i + 1, "import \"controllers\"\n"
|
83
|
-
pack_path.write lines.join
|
84
|
-
say "✅ Stimulus controllers imported in #{friendly_pack_path}"
|
83
|
+
StimulusReflex::Installer.pack_path.write lines.join
|
84
|
+
say "✅ Stimulus controllers imported in #{StimulusReflex::Installer.friendly_pack_path}"
|
85
85
|
end
|
86
86
|
|
87
87
|
# ensure webpacker is installed in the Gemfile
|
88
|
-
add_gem "webpacker@5.4.3"
|
88
|
+
StimulusReflex::Installer.add_gem "webpacker@5.4.3"
|
89
89
|
|
90
|
-
complete_step :webpacker
|
90
|
+
StimulusReflex::Installer.complete_step :webpacker
|
data/lib/install/yarn.rb
CHANGED
@@ -2,18 +2,18 @@
|
|
2
2
|
|
3
3
|
require "stimulus_reflex/installer"
|
4
4
|
|
5
|
-
if !package_json_path.exist?
|
5
|
+
if !StimulusReflex::Installer.package_json_path.exist?
|
6
6
|
say "⏩ No package.json file found. Skipping."
|
7
7
|
|
8
8
|
return
|
9
9
|
end
|
10
10
|
|
11
11
|
# run yarn install only when packages are waiting to be added or removed
|
12
|
-
add = package_list.exist? ? package_list.readlines.map(&:chomp) : []
|
13
|
-
dev = dev_package_list.exist? ? dev_package_list.readlines.map(&:chomp) : []
|
14
|
-
drop = drop_package_list.exist? ? drop_package_list.readlines.map(&:chomp) : []
|
12
|
+
add = StimulusReflex::Installer.package_list.exist? ? StimulusReflex::Installer.package_list.readlines.map(&:chomp) : []
|
13
|
+
dev = StimulusReflex::Installer.dev_package_list.exist? ? StimulusReflex::Installer.dev_package_list.readlines.map(&:chomp) : []
|
14
|
+
drop = StimulusReflex::Installer.drop_package_list.exist? ? StimulusReflex::Installer.drop_package_list.readlines.map(&:chomp) : []
|
15
15
|
|
16
|
-
json = JSON.parse(
|
16
|
+
json = JSON.parse(StimulusReflex::Installer.package_json_path.read)
|
17
17
|
|
18
18
|
if add.present? || dev.present? || drop.present?
|
19
19
|
|
@@ -36,20 +36,20 @@ if add.present? || dev.present? || drop.present?
|
|
36
36
|
json["devDependencies"].delete(package)
|
37
37
|
end
|
38
38
|
|
39
|
-
package_json_path.write JSON.pretty_generate(json)
|
39
|
+
StimulusReflex::Installer.package_json_path.write JSON.pretty_generate(json)
|
40
40
|
|
41
41
|
system "yarn install --silent"
|
42
42
|
else
|
43
43
|
say "⏩ No yarn depdencies to add or remove. Skipping."
|
44
44
|
end
|
45
45
|
|
46
|
-
if bundler == "esbuild" && json["scripts"]["build"] != "node esbuild.config.mjs"
|
46
|
+
if StimulusReflex::Installer.bundler == "esbuild" && json["scripts"]["build"] != "node esbuild.config.mjs"
|
47
47
|
json["scripts"]["build:default"] = json["scripts"]["build"]
|
48
48
|
json["scripts"]["build"] = "node esbuild.config.mjs"
|
49
|
-
package_json_path.write JSON.pretty_generate(json)
|
49
|
+
StimulusReflex::Installer.package_json_path.write JSON.pretty_generate(json)
|
50
50
|
say "✅ Your yarn build script has been updated to use esbuild.config.mjs"
|
51
51
|
else
|
52
52
|
say "⏩ Your yarn build script is already setup. Skipping."
|
53
53
|
end
|
54
54
|
|
55
|
-
complete_step :yarn
|
55
|
+
StimulusReflex::Installer.complete_step :yarn
|
@@ -1,12 +1,14 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
# forzen_string_literal: true
|
4
|
-
|
5
3
|
module StimulusReflex
|
6
4
|
module HTML
|
7
5
|
class DocumentFragment < Document
|
8
6
|
def parsing_class
|
9
|
-
Nokogiri
|
7
|
+
Nokogiri::HTML5::Inference
|
8
|
+
end
|
9
|
+
|
10
|
+
def document_element
|
11
|
+
@document
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|