stimulus-rails 0.3.9 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,13 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+
3
+ const application = Application.start()
4
+
5
+ // Configure Stimulus development experience
6
+ application.warnings = true
7
+ application.debug = false
8
+ window.Stimulus = application
9
+
10
+ // Import and register all your controllers from the importmap under controllers/*
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)
@@ -0,0 +1,11 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+
3
+ const application = Application.start()
4
+
5
+ // Configure Stimulus development experience
6
+ application.warnings = true
7
+ application.debug = false
8
+ window.Stimulus = application
9
+
10
+ // Import and register all your controllers
11
+ import("./hello_controller").then(c => application.register("hello", c.default))
@@ -0,0 +1,14 @@
1
+ import { Application } from "@hotwired/stimulus"
2
+
3
+ const application = Application.start()
4
+
5
+ // Configure Stimulus development experience
6
+ application.warnings = true
7
+ application.debug = false
8
+ window.Stimulus = application
9
+
10
+ // Import and register all your controllers within this directory and all subdirectories
11
+ // Controller files must be named *_controller.js or *_controller.ts
12
+ import { definitionsFromContext } from "@hotwired/stimulus"
13
+ const context = require.context("controllers", true, /_controller\.(js|ts)$/)
14
+ application.load(definitionsFromContext(context))
@@ -0,0 +1,10 @@
1
+ if (js_entrypoint_path = Rails.root.join("app/javascript/application.js")).exist?
2
+ say "Appending Stimulus setup code to JavaScript entrypoint"
3
+ append_to_file "app/javascript/application.js", %(\nimport "controllers")
4
+ else
5
+ end
6
+
7
+ say "Creating controllers directory"
8
+ directory "#{__dir__}/app/javascript/controllers", "app/javascript/controllers"
9
+
10
+ say "Add @hotwired/stimulus package"
@@ -0,0 +1,17 @@
1
+ say "Create controllers directory"
2
+ empty_directory "app/javascript/controllers"
3
+ copy_file "#{__dir__}/app/javascript/controllers/index_for_importmap.js",
4
+ "app/javascript/controllers/index.js"
5
+ copy_file "#{__dir__}/app/javascript/controllers/hello_controller.js",
6
+ "app/javascript/controllers/hello_controller.js"
7
+
8
+ say "Import Stimulus controllers"
9
+ append_to_file "app/javascript/application.js", %(import "controllers"\n)
10
+
11
+ say "Pin Stimulus"
12
+ append_to_file "config/importmap.rb" do <<-RUBY
13
+ pin "@hotwired/stimulus", to: "stimulus.js"
14
+ pin "@hotwired/stimulus-importmap-autoloader", to: "stimulus-importmap-autoloader.js"
15
+ pin_all_from "app/javascript/controllers", under: "controllers"
16
+ RUBY
17
+ end
@@ -0,0 +1,19 @@
1
+ say "Create controllers directory"
2
+ empty_directory "app/javascript/controllers"
3
+
4
+ if Rails.root.join("config/webpacker.yml").exist?
5
+ copy_file "#{__dir__}/app/javascript/controllers/index_for_webpacker.js",
6
+ "app/javascript/controllers/index.js"
7
+ else
8
+ copy_file "#{__dir__}/app/javascript/controllers/index_for_node.js",
9
+ "app/javascript/controllers/index.js"
10
+ end
11
+
12
+ copy_file "#{__dir__}/app/javascript/controllers/hello_controller.js",
13
+ "app/javascript/controllers/hello_controller.js"
14
+
15
+ say "Import Stimulus controllers"
16
+ append_to_file "app/javascript/application.js", %(import "./controllers"\n)
17
+
18
+ say "Install Stimulus"
19
+ run "yarn add @hotwired/stimulus"
@@ -2,7 +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 stimulus-importmap-autoloader )
5
+ Rails.application.config.assets.precompile += %w( stimulus )
6
6
  end
7
7
  end
8
8
  end
@@ -1,3 +1,3 @@
1
1
  module Stimulus
2
- VERSION = "0.3.9"
2
+ VERSION = "0.4.1"
3
3
  end
@@ -3,24 +3,24 @@ def run_stimulus_install_template(path) system "#{RbConfig.ruby} ./bin/rails app
3
3
  namespace :stimulus do
4
4
  desc "Install Stimulus into the app"
5
5
  task :install do
6
- if defined?(Webpacker::Engine)
7
- Rake::Task["stimulus:install:webpacker"].invoke
8
- elsif defined?(Importmap)
9
- Rake::Task["stimulus:install:asset_pipeline"].invoke
6
+ if Rails.root.join("config/importmap.rb").exist?
7
+ Rake::Task["stimulus:install:importmap"].invoke
8
+ elsif Rails.root.join("package.json").exist?
9
+ Rake::Task["stimulus:install:node"].invoke
10
10
  else
11
- puts "You must either be running Webpacker or importmap-rails to use this gem."
11
+ puts "You must either be running with node (package.json) or importmap-rails (config/importmap.rb) to use this gem."
12
12
  end
13
13
  end
14
14
 
15
15
  namespace :install do
16
- desc "Install Stimulus on the app with the asset pipeline"
17
- task :asset_pipeline do
18
- run_stimulus_install_template "stimulus_with_asset_pipeline"
16
+ desc "Install Stimulus on an app running importmap-rails"
17
+ task :importmap do
18
+ run_stimulus_install_template "stimulus_with_importmap"
19
19
  end
20
20
 
21
- desc "Install Stimulus on the app with webpacker"
22
- task :webpacker do
23
- run_stimulus_install_template "stimulus_with_webpacker"
21
+ desc "Install Stimulus on an app running node"
22
+ task :node do
23
+ run_stimulus_install_template "stimulus_with_node"
24
24
  end
25
25
  end
26
26
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimulus-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.9
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Stephenson
8
8
  - Javan Mahkmali
9
9
  - David Heinemeier Hansson
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-08-25 00:00:00.000000000 Z
13
+ date: 2021-09-03 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -26,7 +26,7 @@ dependencies:
26
26
  - - ">="
27
27
  - !ruby/object:Gem::Version
28
28
  version: 6.0.0
29
- description:
29
+ description:
30
30
  email: david@loudthinking.com
31
31
  executables: []
32
32
  extensions: []
@@ -39,10 +39,14 @@ files:
39
39
  - app/assets/javascripts/stimulus-importmap-autoloader.js
40
40
  - app/assets/javascripts/stimulus.js
41
41
  - app/assets/javascripts/stimulus@2.js
42
+ - app/assets/javascripts/stimulus@3.0.0-beta.1.js
42
43
  - lib/install/app/javascript/controllers/hello_controller.js
43
- - lib/install/app/javascript/controllers/index.js
44
- - lib/install/stimulus_with_asset_pipeline.rb
45
- - lib/install/stimulus_with_webpacker.rb
44
+ - lib/install/app/javascript/controllers/index_for_importmap.js
45
+ - lib/install/app/javascript/controllers/index_for_node.js
46
+ - lib/install/app/javascript/controllers/index_for_webpacker.js
47
+ - lib/install/install.rb
48
+ - lib/install/stimulus_with_importmap.rb
49
+ - lib/install/stimulus_with_node.rb
46
50
  - lib/stimulus-rails.rb
47
51
  - lib/stimulus/engine.rb
48
52
  - lib/stimulus/version.rb
@@ -53,7 +57,7 @@ licenses:
53
57
  metadata:
54
58
  homepage_uri: https://stimulus.hotwired.dev
55
59
  source_code_uri: https://github.com/hotwired/stimulus-rails
56
- post_install_message:
60
+ post_install_message:
57
61
  rdoc_options: []
58
62
  require_paths:
59
63
  - lib
@@ -69,7 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
69
73
  version: '0'
70
74
  requirements: []
71
75
  rubygems_version: 3.1.4
72
- signing_key:
76
+ signing_key:
73
77
  specification_version: 4
74
78
  summary: A modest JavaScript framework for the HTML you already have.
75
79
  test_files: []
@@ -1,9 +0,0 @@
1
- // Load all the controllers within this directory and all subdirectories.
2
- // Controller files must be named *_controller.js or *_controller.ts.
3
-
4
- import { Application } from "stimulus"
5
- import { definitionsFromContext } from "stimulus/webpack-helpers"
6
-
7
- window.Stimulus = Application.start()
8
- const context = require.context("controllers", true, /_controller\.(js|ts)$/)
9
- Stimulus.load(definitionsFromContext(context))
@@ -1,27 +0,0 @@
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/importmap.rb")
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 @hotwired/stimulus and @hotwired/stimulus-importmap-autoloader in your application.js.
11
- INSTRUCTIONS
12
- end
13
-
14
- say "Creating controllers directory"
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/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 @hotwired/stimulus and @hotwired/stimulus-importmap-autoloader to your importmap to reference them via ESM.
26
- INSTRUCTIONS
27
- end
@@ -1,11 +0,0 @@
1
- say "Appending Stimulus setup code to #{Webpacker.config.source_entry_path}/application.js"
2
- append_to_file "#{Webpacker.config.source_entry_path}/application.js", %(\nimport "controllers")
3
-
4
- say "Creating controllers directory"
5
- directory "#{__dir__}/app/javascript/controllers", "#{Webpacker.config.source_path}/controllers"
6
-
7
- say "Using Stimulus NPM package"
8
- gsub_file "#{Webpacker.config.source_path}/controllers/hello_controller.js", /@hotwired\//, ''
9
-
10
- say "Installing all Stimulus dependencies"
11
- run "yarn add stimulus"