stimulus-rails 1.2.1 → 1.3.4

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.
@@ -3,10 +3,12 @@ require "rails/generators/named_base"
3
3
  class StimulusGenerator < Rails::Generators::NamedBase # :nodoc:
4
4
  source_root File.expand_path("templates", __dir__)
5
5
 
6
+ class_option :skip_manifest, type: :boolean, default: false, desc: "Don't update the stimulus manifest"
7
+
6
8
  def copy_view_files
7
9
  @attribute = stimulus_attribute_value(controller_name)
8
10
  template "controller.js", "app/javascript/controllers/#{controller_name}_controller.js"
9
- rails_command "stimulus:manifest:update" unless Rails.root.join("config/importmap.rb").exist?
11
+ rails_command "stimulus:manifest:update" unless Rails.root.join("config/importmap.rb").exist? || options[:skip_manifest]
10
12
  end
11
13
 
12
14
  private
@@ -1,11 +1,4 @@
1
- // Import and register all your controllers from the importmap under controllers/*
2
-
1
+ // Import and register all your controllers from the importmap via controllers/**/*_controller
3
2
  import { application } from "controllers/application"
4
-
5
- // Eager load all controllers defined in the import map under controllers/**/*_controller
6
3
  import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
7
4
  eagerLoadControllersFrom("controllers", application)
8
-
9
- // Lazy load controllers as they appear in the DOM (remember not to preload controllers in import map!)
10
- // import { lazyLoadControllersFrom } from "@hotwired/stimulus-loading"
11
- // lazyLoadControllersFrom("controllers", application)
@@ -0,0 +1,18 @@
1
+ say "Create controllers directory"
2
+ empty_directory "app/javascript/controllers"
3
+ copy_file "#{__dir__}/app/javascript/controllers/index_for_node.js",
4
+ "app/javascript/controllers/index.js"
5
+ copy_file "#{__dir__}/app/javascript/controllers/application.js",
6
+ "app/javascript/controllers/application.js"
7
+ copy_file "#{__dir__}/app/javascript/controllers/hello_controller.js",
8
+ "app/javascript/controllers/hello_controller.js"
9
+
10
+ if (Rails.root.join("app/javascript/application.js")).exist?
11
+ say "Import Stimulus controllers"
12
+ append_to_file "app/javascript/application.js", %(import "./controllers"\n)
13
+ else
14
+ say %(Couldn't find "app/javascript/application.js".\nYou must import "./controllers" in your JavaScript entrypoint file), :red
15
+ end
16
+
17
+ say "Install Stimulus"
18
+ run "bun add @hotwired/stimulus"
@@ -11,11 +11,11 @@ say "Import Stimulus controllers"
11
11
  append_to_file "app/javascript/application.js", %(import "controllers"\n)
12
12
 
13
13
  say "Pin Stimulus"
14
- say %(Appending: pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true")
15
- append_to_file "config/importmap.rb", %(pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true\n)
14
+ say %(Appending: pin "@hotwired/stimulus", to: "stimulus.min.js")
15
+ append_to_file "config/importmap.rb", %(pin "@hotwired/stimulus", to: "stimulus.min.js"\n)
16
16
 
17
- say %(Appending: pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true)
18
- append_to_file "config/importmap.rb", %(pin "@hotwired/stimulus-loading", to: "stimulus-loading.js", preload: true\n)
17
+ say %(Appending: pin "@hotwired/stimulus-loading", to: "stimulus-loading.js")
18
+ append_to_file "config/importmap.rb", %(pin "@hotwired/stimulus-loading", to: "stimulus-loading.js"\n)
19
19
 
20
20
  say "Pin all controllers"
21
21
  say %(Appending: pin_all_from "app/javascript/controllers", under: "controllers")
@@ -15,4 +15,8 @@ else
15
15
  end
16
16
 
17
17
  say "Install Stimulus"
18
- run "yarn add @hotwired/stimulus"
18
+ if (Rails.root.join("bun.config.js")).exist?
19
+ run "bun add @hotwired/stimulus"
20
+ else
21
+ run "yarn add @hotwired/stimulus"
22
+ end
@@ -2,15 +2,17 @@ module Stimulus::Manifest
2
2
  extend self
3
3
 
4
4
  def generate_from(controllers_path)
5
- extract_controllers_from(controllers_path).collect do |controller_path|
5
+ manifest = extract_controllers_from(controllers_path).collect do |controller_path|
6
6
  import_and_register_controller(controllers_path, controller_path)
7
7
  end
8
+
9
+ manifest.uniq
8
10
  end
9
11
 
10
12
  def import_and_register_controller(controllers_path, controller_path)
11
13
  controller_path = controller_path.relative_path_from(controllers_path).to_s
12
14
  module_path = controller_path.split('.').first
13
- controller_class_name = module_path.camelize.gsub(/::/, "__")
15
+ controller_class_name = module_path.underscore.camelize.gsub(/::/, "__")
14
16
  tag_name = module_path.remove(/_controller/).gsub(/_/, "-").gsub(/\//, "--")
15
17
 
16
18
  <<-JS
@@ -1,3 +1,3 @@
1
1
  module Stimulus
2
- VERSION = "1.2.1"
2
+ VERSION = "1.3.4"
3
3
  end
@@ -1,12 +1,25 @@
1
1
  require "stimulus/manifest"
2
2
 
3
- def run_stimulus_install_template(path) system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}" end
3
+ module Stimulus
4
+ module Tasks
5
+ extend self
6
+ def run_stimulus_install_template(path)
7
+ system RbConfig.ruby, "./bin/rails", "app:template", "LOCATION=#{File.expand_path("../install/#{path}.rb", __dir__)}"
8
+ end
9
+
10
+ def using_bun?
11
+ Rails.root.join("bun.config.js").exist?
12
+ end
13
+ end
14
+ end
4
15
 
5
16
  namespace :stimulus do
6
17
  desc "Install Stimulus into the app"
7
18
  task :install do
8
19
  if Rails.root.join("config/importmap.rb").exist?
9
20
  Rake::Task["stimulus:install:importmap"].invoke
21
+ elsif Rails.root.join("package.json").exist? && Stimulus::Tasks.using_bun?
22
+ Rake::Task["stimulus:install:bun"].invoke
10
23
  elsif Rails.root.join("package.json").exist?
11
24
  Rake::Task["stimulus:install:node"].invoke
12
25
  else
@@ -17,20 +30,27 @@ namespace :stimulus do
17
30
  namespace :install do
18
31
  desc "Install Stimulus on an app running importmap-rails"
19
32
  task :importmap do
20
- run_stimulus_install_template "stimulus_with_importmap"
33
+ Stimulus::Tasks.run_stimulus_install_template "stimulus_with_importmap"
21
34
  end
22
35
 
23
36
  desc "Install Stimulus on an app running node"
24
37
  task :node do
25
- run_stimulus_install_template "stimulus_with_node"
38
+ Stimulus::Tasks.run_stimulus_install_template "stimulus_with_node"
39
+ end
40
+
41
+ desc "Install Stimulus on an app running bun"
42
+ task :bun do
43
+ Stimulus::Tasks.run_stimulus_install_template "stimulus_with_bun"
26
44
  end
27
45
  end
28
46
 
29
47
  namespace :manifest do
48
+ desc "Show the current Stimulus manifest (all installed controllers)"
30
49
  task :display do
31
50
  puts Stimulus::Manifest.generate_from(Rails.root.join("app/javascript/controllers"))
32
51
  end
33
52
 
53
+ desc "Update the Stimulus manifest (will overwrite controllers/index.js)"
34
54
  task :update do
35
55
  manifest =
36
56
  Stimulus::Manifest.generate_from(Rails.root.join("app/javascript/controllers"))
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: 1.2.1
4
+ version: 1.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: 2022-11-30 00:00:00.000000000 Z
13
+ date: 2024-08-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
@@ -48,6 +48,7 @@ files:
48
48
  - lib/install/app/javascript/controllers/hello_controller.js
49
49
  - lib/install/app/javascript/controllers/index_for_importmap.js
50
50
  - lib/install/app/javascript/controllers/index_for_node.js
51
+ - lib/install/stimulus_with_bun.rb
51
52
  - lib/install/stimulus_with_importmap.rb
52
53
  - lib/install/stimulus_with_node.rb
53
54
  - lib/stimulus-rails.rb
@@ -76,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
77
  - !ruby/object:Gem::Version
77
78
  version: '0'
78
79
  requirements: []
79
- rubygems_version: 3.3.25
80
+ rubygems_version: 3.5.17
80
81
  signing_key:
81
82
  specification_version: 4
82
83
  summary: A modest JavaScript framework for the HTML you already have.