stimulus-rails 0.3.3 → 0.3.4
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f77f2ce48a99dfbc61800f5898cc71aecb3d6886fec0e4f65b64c1c7f772f87d
|
4
|
+
data.tar.gz: 219f51744c6f6e532bb68b474575307f18f1c348520fe157b8cacdf960b48f81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6e4099ab2741482ea33c260257e9898afa9fbb9e465072d659b96f5ac63d4aceb7355439a8e3db46b7dd06a0ec7b2f6d9973997fd3a0016f011b7f4b6badf91
|
7
|
+
data.tar.gz: 0d9269cf9234266aba718e0ddc0ddc680773d73f107f76bbf5529758321db4ebb020814f3a27c217a8b0538d08145c2c861afe304765ce295081a670e593b647
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { Application } from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
const application = Application.start()
|
4
|
+
|
5
|
+
const importmap = await JSON.parse(document.querySelector("script[type=importmap]").text)
|
6
|
+
const importedControllerPaths = Object.keys(importmap.imports).filter((e) => e.match("controllers/"))
|
7
|
+
|
8
|
+
importedControllerPaths.forEach(function(path) {
|
9
|
+
const name = path.replace("controllers/", "").replace("_controller", "").replace("/", "--").replace("_", "-")
|
10
|
+
|
11
|
+
import(path)
|
12
|
+
.then(module => application.register(name, module.default))
|
13
|
+
.catch(error => console.log(`Failed to autoload controller: ${name}`, error))
|
14
|
+
})
|
@@ -1,7 +1,20 @@
|
|
1
1
|
APP_JS_ROOT = Rails.root.join("app/assets/javascripts")
|
2
|
+
IMPORTMAP_PATH = Rails.root.join("config/initializers/importmap.rb")
|
2
3
|
|
3
4
|
say "Import Stimulus autoloader in existing app/assets/javascripts/application.js"
|
4
|
-
append_to_file APP_JS_ROOT.join("application.js"), %(
|
5
|
+
append_to_file APP_JS_ROOT.join("application.js"), %(\nimport "@hotwired/stimulus-autoloader"\n)
|
5
6
|
|
6
7
|
say "Creating controllers directory"
|
7
8
|
copy_file "#{__dir__}/app/assets/javascripts/controllers/hello_controller.js", APP_JS_ROOT.join("controllers/hello_controller.js")
|
9
|
+
|
10
|
+
if IMPORTMAP_PATH.exist?
|
11
|
+
say "Pin @hotwired/stimulus and @hotwired/stimulus-autoloader in config/initializers/importmap.rb"
|
12
|
+
insert_into_file \
|
13
|
+
IMPORTMAP_PATH.to_s,
|
14
|
+
%( pin "@hotwired/stimulus", to: "stimulus.js"\n pin "@hotwired/stimulus-autoloader", to: "stimulus-autoloader.js"\n\n),
|
15
|
+
after: "Rails.application.config.importmap.draw do\n"
|
16
|
+
else
|
17
|
+
say <<~INSTRUCTIONS, :green
|
18
|
+
You must add @rails/actiontext and trix to your importmap to reference them via ESM.
|
19
|
+
INSTRUCTIONS
|
20
|
+
end
|
data/lib/stimulus/engine.rb
CHANGED
@@ -2,16 +2,7 @@ module Stimulus
|
|
2
2
|
class Engine < ::Rails::Engine
|
3
3
|
initializer "stimulus.assets" do
|
4
4
|
if Rails.application.config.respond_to?(:assets)
|
5
|
-
Rails.application.config.assets.precompile += %w( stimulus stimulus-autoloader )
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
initializer "stimulus.importmap" do
|
10
|
-
if Rails.application.config.respond_to?(:importmap)
|
11
|
-
Rails.application.config.importmap.draw do
|
12
|
-
pin "@hotwired/stimulus", to: "stimulus.js"
|
13
|
-
pin "@hotwired/stimulus-autoloader", to: "stimulus-autoloader.js"
|
14
|
-
end
|
5
|
+
Rails.application.config.assets.precompile += %w( stimulus stimulus-autoloader stimulus-importmap-autoloader )
|
15
6
|
end
|
16
7
|
end
|
17
8
|
end
|
data/lib/stimulus/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stimulus-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Stephenson
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2021-08-
|
13
|
+
date: 2021-08-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -36,6 +36,7 @@ files:
|
|
36
36
|
- README.md
|
37
37
|
- Rakefile
|
38
38
|
- app/assets/javascripts/stimulus-autoloader.js
|
39
|
+
- app/assets/javascripts/stimulus-importmap-autoloader.js
|
39
40
|
- app/assets/javascripts/stimulus.js
|
40
41
|
- app/assets/javascripts/stimulus@2.js
|
41
42
|
- lib/install/app/assets/javascripts/controllers/hello_controller.js
|