stimulus-rails 0.3.8 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/stimulus-importmap-autoloader.js +15 -8
- data/app/assets/javascripts/stimulus.js +3 -0
- data/app/assets/javascripts/stimulus@3.0.0-beta.1.js +2058 -0
- data/lib/install/app/javascript/controllers/index_for_importmap.js +13 -0
- data/lib/install/app/javascript/controllers/index_for_node.js +12 -0
- data/lib/install/app/javascript/controllers/index_for_webpacker.js +14 -0
- data/lib/install/install.rb +10 -0
- data/lib/install/stimulus_with_importmap.rb +17 -0
- data/lib/install/stimulus_with_node.rb +19 -0
- data/lib/stimulus/engine.rb +1 -1
- data/lib/stimulus/version.rb +1 -1
- data/lib/tasks/stimulus_tasks.rake +11 -11
- metadata +9 -5
- data/lib/install/app/javascript/controllers/index.js +0 -9
- data/lib/install/stimulus_with_asset_pipeline.rb +0 -27
- data/lib/install/stimulus_with_webpacker.rb +0 -11
@@ -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,12 @@
|
|
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 HelloController from "./hello_controller"
|
12
|
+
application.register("hello", HelloController)
|
@@ -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"
|
data/lib/stimulus/engine.rb
CHANGED
@@ -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
|
5
|
+
Rails.application.config.assets.precompile += %w( stimulus )
|
6
6
|
end
|
7
7
|
end
|
8
8
|
end
|
data/lib/stimulus/version.rb
CHANGED
@@ -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
|
7
|
-
Rake::Task["stimulus:install:
|
8
|
-
elsif
|
9
|
-
Rake::Task["stimulus:install:
|
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
|
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
|
17
|
-
task :
|
18
|
-
run_stimulus_install_template "
|
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
|
22
|
-
task :
|
23
|
-
run_stimulus_install_template "
|
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,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
|
+
version: 0.4.0
|
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-
|
13
|
+
date: 2021-09-03 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rails
|
@@ -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/
|
44
|
-
- lib/install/
|
45
|
-
- lib/install/
|
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
|
@@ -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 @rails/actiontext and trix 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"
|