stimulus-rails 0.3.3 → 0.3.7
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/app/assets/javascripts/stimulus-importmap-autoloader.js +14 -0
- data/lib/install/app/{assets/javascripts → javascript}/controllers/hello_controller.js +0 -0
- data/lib/install/app/{assets/javascripts → javascript}/controllers/index.js +0 -0
- data/lib/install/stimulus_with_asset_pipeline.rb +24 -4
- data/lib/install/stimulus_with_webpacker.rb +1 -1
- data/lib/stimulus/engine.rb +1 -10
- data/lib/stimulus/version.rb +1 -1
- metadata +5 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 894a81fc2be7dadaf745027c04aef2cb0d637348c6e93829b10952cd976a83a9
         | 
| 4 | 
            +
              data.tar.gz: 06ebc45e8746c0be3112feeb03852daf82cf0e1447dfcc52ad1ae3f0360325b1
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 37e58a1922f16facf066e402022ca530f6ec033f5b189503ae2f45de09708ebe9d9eefc33cc95b45a8242e37d79cabe97e643f705b87fb4f8a5e150d1f4b4f50
         | 
| 7 | 
            +
              data.tar.gz: 16f93ddcc5e7f3b65c1d8c5ddddbf2fa55edee46ff8ac2dc788d93ac1dd559a842d09366d331321d68c9eb9edfca8ed8b6335c19471579291dc4be8c8270493c
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            import { Application } from "@hotwired/stimulus"
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            const application = Application.start()
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            const importmap = 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 | 
            +
            })
         | 
| 
            File without changes
         | 
| 
            File without changes
         | 
| @@ -1,7 +1,27 @@ | |
| 1 | 
            -
            APP_JS_ROOT = Rails.root.join("app/ | 
| 1 | 
            +
            APP_JS_ROOT = Rails.root.join("app/javascript")
         | 
| 2 | 
            +
            APP_JS_PATH = APP_JS_ROOT.join("application.js")
         | 
| 3 | 
            +
            IMPORTMAP_PATH = Rails.root.join("config/initializers/importmap.rb")
         | 
| 2 4 |  | 
| 3 | 
            -
             | 
| 4 | 
            -
             | 
| 5 | 
            +
            if APP_JS_PATH.exist?
         | 
| 6 | 
            +
              say "Import Stimulus importmap autoloader in existing app/javascript/application.js"
         | 
| 7 | 
            +
              append_to_file APP_JS_PATH, %(\nimport "@hotwired/stimulus-importmap-autoloader"\n)
         | 
| 8 | 
            +
            else
         | 
| 9 | 
            +
              say <<~INSTRUCTIONS, :red
         | 
| 10 | 
            +
                You must import @hotwire/stimulus and @hotwire/stimulus-importmap-autoloader in your application.js.
         | 
| 11 | 
            +
              INSTRUCTIONS
         | 
| 12 | 
            +
            end
         | 
| 5 13 |  | 
| 6 14 | 
             
            say "Creating controllers directory"
         | 
| 7 | 
            -
            copy_file "#{__dir__}/app/ | 
| 15 | 
            +
            copy_file "#{__dir__}/app/javascript/controllers/hello_controller.js", APP_JS_ROOT.join("controllers/hello_controller.js")
         | 
| 16 | 
            +
             | 
| 17 | 
            +
            if IMPORTMAP_PATH.exist?
         | 
| 18 | 
            +
              say "Pin @hotwired/stimulus and @hotwired/stimulus-importmap-autoloader in config/initializers/importmap.rb"
         | 
| 19 | 
            +
              insert_into_file \
         | 
| 20 | 
            +
                IMPORTMAP_PATH.to_s, 
         | 
| 21 | 
            +
                %(  pin "@hotwired/stimulus", to: "stimulus.js"\n  pin "@hotwired/stimulus-importmap-autoloader", to: "stimulus-importmap-autoloader.js"\n  pin_all_from "app/javascript/controllers", under: "controllers"\n\n),
         | 
| 22 | 
            +
                after: "Rails.application.config.importmap.draw do\n"
         | 
| 23 | 
            +
            else
         | 
| 24 | 
            +
              say <<~INSTRUCTIONS, :red
         | 
| 25 | 
            +
                You must add @rails/actiontext and trix to your importmap to reference them via ESM.
         | 
| 26 | 
            +
              INSTRUCTIONS
         | 
| 27 | 
            +
            end
         | 
| @@ -2,7 +2,7 @@ say "Appending Stimulus setup code to #{Webpacker.config.source_entry_path}/appl | |
| 2 2 | 
             
            append_to_file "#{Webpacker.config.source_entry_path}/application.js", %(\nimport "controllers")
         | 
| 3 3 |  | 
| 4 4 | 
             
            say "Creating controllers directory"
         | 
| 5 | 
            -
            directory "#{__dir__}/app/ | 
| 5 | 
            +
            directory "#{__dir__}/app/javascript/controllers", "#{Webpacker.config.source_path}/controllers"
         | 
| 6 6 |  | 
| 7 7 | 
             
            say "Using Stimulus NPM package"
         | 
| 8 8 | 
             
            gsub_file "#{Webpacker.config.source_path}/controllers/hello_controller.js", /@hotwired\//, ''
         | 
    
        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.7
         | 
| 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,10 +36,11 @@ 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 | 
            -
            - lib/install/app/ | 
| 42 | 
            -
            - lib/install/app/ | 
| 42 | 
            +
            - lib/install/app/javascript/controllers/hello_controller.js
         | 
| 43 | 
            +
            - lib/install/app/javascript/controllers/index.js
         | 
| 43 44 | 
             
            - lib/install/stimulus_with_asset_pipeline.rb
         | 
| 44 45 | 
             
            - lib/install/stimulus_with_webpacker.rb
         | 
| 45 46 | 
             
            - lib/stimulus-rails.rb
         |