stimulus-rails 0.4.1 → 0.4.2

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: 3658754f53d1cec9d1cd7fa3296712e68ec6707e8f0688e3024a9b69954aaf3a
4
- data.tar.gz: 289338078bfe2df5c3b8f6ddd8d5315d498b329fadd551d96f1e928555caf644
3
+ metadata.gz: 2e7e80a2e07dc6e40f109bc5c009bbea41b02057c8a7b489b638c0a964d14f22
4
+ data.tar.gz: aa0979ef349cd0c4a49b27c11448663cb40728643bbf43f68a3136ae491e7ab7
5
5
  SHA512:
6
- metadata.gz: bf15c39c9e961d069748a0ffbe22d23382ce926973753b73a38ee084bc98b4332888690d39ab60f1ce479e8963c437ca6cbe610b5686cc9b4df2c5f855073906
7
- data.tar.gz: b9d374fcfc36a1372aafd653ec1837265b864a08ccef95651b4a93059073b9a99b536d92e8c8298eb34793395dbdaa9d21ba866454401c7fb26f1bc787da4714
6
+ metadata.gz: 694ab07e593aca69e7abfb0e22c4459ddc27be5d7a5f8cdaa35dfb957f05d6da45e580ec7b9c22af09911a0c2901b4b459a4fdad5ecbbf9165052c047d44d56e
7
+ data.tar.gz: 3c1412141e0c2a9c2b29fea34f3946c0c14610d69b37c15557100d0a12422948f9be6d6d8977b7059d8b0aa233e1456eb3d82b78ec164881df39a2d1c3a8dc1d
@@ -1,13 +1,17 @@
1
1
  // FIXME: es-module-shim won't shim the dynamic import without this explicit import
2
2
  import "@hotwired/stimulus"
3
3
 
4
- export function registerControllersFrom(under, importmap, application) {
5
- const paths = Object.keys(importmap)
4
+ export function registerControllersFrom(under, application) {
5
+ const paths = Object.keys(parseImportmapJson())
6
6
  .filter(path => path.match(new RegExp(`^${under}/.*_controller$`)))
7
7
 
8
8
  paths.forEach(path => registerControllerFromPath(path, under, application))
9
9
  }
10
10
 
11
+ export function parseImportmapJson() {
12
+ return JSON.parse(document.querySelector("script[type=importmap]").text).imports
13
+ }
14
+
11
15
  function registerControllerFromPath(path, under, application) {
12
16
  const name = path
13
17
  .replace(`${under}/`, "")
@@ -9,5 +9,4 @@ window.Stimulus = application
9
9
 
10
10
  // Import and register all your controllers from the importmap under controllers/*
11
11
  import { registerControllersFrom } from "@hotwired/stimulus-importmap-autoloader"
12
- const importmap = JSON.parse(document.querySelector("script[type=importmap]").text).imports
13
- registerControllersFrom("controllers", importmap, application)
12
+ registerControllersFrom("controllers", application)
@@ -12,8 +12,12 @@ end
12
12
  copy_file "#{__dir__}/app/javascript/controllers/hello_controller.js",
13
13
  "app/javascript/controllers/hello_controller.js"
14
14
 
15
- say "Import Stimulus controllers"
16
- append_to_file "app/javascript/application.js", %(import "./controllers"\n)
15
+ if (Rails.root.join("app/javascript/application.js")).exist?
16
+ say "Import Stimulus controllers"
17
+ append_to_file "app/javascript/application.js", %(import "./controllers"\n)
18
+ else
19
+ say %(You must import "./controllers" in your JavaScript entrypoint), :red
20
+ end
17
21
 
18
22
  say "Install Stimulus"
19
23
  run "yarn add @hotwired/stimulus"
@@ -1,3 +1,3 @@
1
1
  module Stimulus
2
- VERSION = "0.4.1"
2
+ VERSION = "0.4.2"
3
3
  end
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.4.1
4
+ version: 0.4.2
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-09-03 00:00:00.000000000 Z
13
+ date: 2021-09-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails