stimulus-rails 0.1.1 → 0.1.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: 05707ec2f2a7863922adeaa958375491a7aa2cabb57edd897f0570e0939f5d59
4
- data.tar.gz: e511d168ccfba80d881dbeb95a7c1f27b6d230f3e9d37f85db0459d91778d791
3
+ metadata.gz: 9315f38125eef25637dac7d0a752284aae1774ff9a201b4ba1053b7e4be5883e
4
+ data.tar.gz: 142e1f79541405565ee24ccf6d6db31d6f6271e0c34b29938cfcdaba5d3a6dd7
5
5
  SHA512:
6
- metadata.gz: 48db2e25592f6803fbf716a2a15ed6fe91a3dc1e4605c207644f1b31611e3719ca79fa4ae8b604738060b14b6d9f6af8433cec682633b0870934e6ea69e55e43
7
- data.tar.gz: 881aa4dc01270b88d5ca70081323891f7289f63b8c3598c907805822236bddb63ce9685e338715ebb58317ae149c6b5dd505b7af07dc18674a4ed423f2a23a2e
6
+ metadata.gz: 0d5eb9560d3b69c4f3b467b022ea7fab69fe5b1963bb1ecc2db06a047fe1e07f5e609e2f88b1cf1e723eb1d57a910a6ccf0eb0693d731dde467d89a97180f816
7
+ data.tar.gz: 0d9cce5a56e595d947455cd69367b13c514cbaa658ab6dbea783d60ceb7ff961c136b8fe79bc785b4e1744f7a17d66f439337360bda26c7b34738b765160f710
data/README.md CHANGED
@@ -14,17 +14,17 @@ If you want to use Stimulus with a bundler, you should use [Webpacker](https://g
14
14
 
15
15
  The last command will:
16
16
 
17
- 1. Create an example controller in app/assets/javascripts/controllers/hello_controller.js
18
- 2. Append the include tags to the `<head>` of your application.html.erb.
19
- 3. Initialize your importmap.json in app/assets/javascripts/importmap.json.erb.
20
- 4. Ensure JavaScript is included in your app/config/manifest.js file for compilation.
17
+ 1. Create an example controller in `app/assets/javascripts/controllers/hello_controller.js`
18
+ 2. Append the include tags to the `<head>` of your `app/views/layouts/application.html.erb`.
19
+ 3. Initialize your `importmap.json` in `app/assets/javascripts/importmap.json.erb`.
20
+ 4. Ensure JavaScript is included in your `app/config/manifest.js` file for compilation.
21
21
 
22
22
 
23
23
  ## Usage
24
24
 
25
25
  With the Stimulus include tags added, you'll automatically have activated Stimulus through the controller autoloader. You can now easily add new Stimulus controllers that'll be loaded via ESM dynamic imports.
26
26
 
27
- For example, a more advanced hello_controller could look like this:
27
+ For example, a more advanced `hello_controller` could look like this:
28
28
 
29
29
  ```javascript
30
30
  // app/assets/javascripts/controllers/hello_controller.js
@@ -43,13 +43,13 @@ And it'll be activated and registered automatically when encountering the data-c
43
43
 
44
44
  ```html
45
45
  <div data-controller="hello">
46
- <input data-target="hello.name" type="text">
46
+ <input data-hello-target="name" type="text">
47
47
 
48
48
  <button data-action="click->hello#greet">
49
49
  Greet
50
50
  </button>
51
51
 
52
- <span data-target="hello.output">
52
+ <span data-hello-target="output">
53
53
  </span>
54
54
  </div>
55
55
  ```
@@ -5,8 +5,15 @@ empty_directory "app/assets/javascripts/libraries"
5
5
  say "Add app/javascripts to asset pipeline manifest"
6
6
  append_to_file Rails.root.join("app/assets/config/manifest.js").to_s, "//= link_tree ../javascripts\n"
7
7
 
8
- say "Add Stimulus include tags in application layout"
9
- insert_into_file Rails.root.join("app/views/layouts/application.html.erb").to_s, "\n <%= stimulus_include_tags %>", before: /\s*<\/head>/
8
+ APPLICATION_LAYOUT_PATH = Rails.root.join("app/views/layouts/application.html.erb")
9
+
10
+ if APPLICATION_LAYOUT_PATH.exist?
11
+ say "Add Stimulus include tags in application layout"
12
+ insert_into_file Rails.root.join("app/views/layouts/application.html.erb").to_s, "\n <%= stimulus_include_tags %>", before: /\s*<\/head>/
13
+ else
14
+ say "Default application.html.erb is missing!", :red
15
+ say " Add <%= stimulus_include_tags %> within the <head> tag in your custom layout."
16
+ end
10
17
 
11
18
  say "Turn off development debug mode"
12
19
  comment_lines Rails.root.join("config/environments/development.rb"), /config.assets.debug = true/
@@ -1,5 +1,5 @@
1
- require "stimulus/version"
2
- require "stimulus/engine"
3
-
4
1
  module Stimulus
5
2
  end
3
+
4
+ require "stimulus/version"
5
+ require "stimulus/engine"
@@ -2,8 +2,7 @@ require "stimulus/importmap_helper"
2
2
 
3
3
  module Stimulus
4
4
  class Engine < ::Rails::Engine
5
- isolate_namespace Stimulus
6
- config.eager_load_namespaces << Stimulus
5
+ config.autoload_once_paths = %w( #{root}/app/helpers )
7
6
 
8
7
  initializer "stimulus.assets" do
9
8
  Rails.application.config.assets.precompile += %w( importmap.json stimulus/manifest )
@@ -11,7 +10,7 @@ module Stimulus
11
10
 
12
11
  initializer "stimulus.helpers" do
13
12
  ActiveSupport.on_load(:action_controller_base) do
14
- helper Stimulus::Engine.helpers
13
+ helper Stimulus::StimulusHelper
15
14
  end
16
15
 
17
16
  Rails.application.config.assets.configure do |env|
@@ -1,3 +1,3 @@
1
1
  module Stimulus
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.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.1.1
4
+ version: 0.1.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: 2020-12-23 00:00:00.000000000 Z
13
+ date: 2020-12-28 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails