stimulus_reflex 3.5.0.pre8 → 3.5.0.pre9

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of stimulus_reflex might be problematic. Click here for more details.

Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +2 -1218
  3. data/Gemfile.lock +109 -152
  4. data/README.md +39 -5
  5. data/Rakefile +0 -8
  6. data/app/assets/javascripts/stimulus_reflex.js +969 -0
  7. data/app/assets/javascripts/stimulus_reflex.min.js +2 -0
  8. data/app/assets/javascripts/stimulus_reflex.min.js.map +1 -0
  9. data/app/assets/javascripts/stimulus_reflex.umd.js +904 -0
  10. data/app/assets/javascripts/stimulus_reflex.umd.min.js +905 -0
  11. data/app/assets/javascripts/stimulus_reflex.umd.min.js.map +1 -0
  12. data/app/channels/stimulus_reflex/channel.rb +20 -1
  13. data/lib/stimulus_reflex/engine.rb +29 -0
  14. data/lib/stimulus_reflex/importmap.rb +4 -0
  15. data/lib/stimulus_reflex/open_struct_fix.rb +29 -0
  16. data/lib/stimulus_reflex/reflex.rb +9 -2
  17. data/lib/stimulus_reflex/reflex_data.rb +4 -0
  18. data/lib/stimulus_reflex/reflex_factory.rb +2 -1
  19. data/lib/stimulus_reflex/utils/logger.rb +2 -0
  20. data/lib/stimulus_reflex/utils/sanity_checker.rb +0 -58
  21. data/lib/stimulus_reflex/version.rb +1 -1
  22. data/lib/stimulus_reflex.rb +2 -6
  23. data/package.json +67 -0
  24. data/rollup.config.js +85 -0
  25. data/stimulus_reflex.gemspec +63 -0
  26. data/test/broadcasters/broadcaster_test_case.rb +1 -1
  27. data/test/broadcasters/nothing_broadcaster_test.rb +2 -1
  28. data/test/broadcasters/page_broadcaster_test.rb +4 -2
  29. data/test/broadcasters/selector_broadcaster_test.rb +12 -6
  30. data/test/callbacks_test.rb +23 -23
  31. data/test/reflex_test.rb +2 -2
  32. data/test/tmp/app/reflexes/application_reflex.rb +3 -10
  33. data/test/tmp/app/reflexes/{demo_reflex.rb → user_reflex.rb} +10 -2
  34. data/web-test-runner.config.mjs +12 -0
  35. data/yarn-error.log +4964 -0
  36. data/yarn.lock +4520 -0
  37. metadata +107 -41
  38. data/lib/generators/USAGE +0 -14
  39. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt +0 -101
  40. data/lib/generators/stimulus_reflex/templates/app/javascript/controllers/application_controller.js.tt +0 -60
  41. data/lib/generators/stimulus_reflex/templates/app/reflexes/%file_name%_reflex.rb.tt +0 -41
  42. data/lib/generators/stimulus_reflex/templates/app/reflexes/application_reflex.rb.tt +0 -19
  43. data/lib/tasks/stimulus_reflex/install.rake +0 -116
metadata CHANGED
@@ -1,45 +1,45 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stimulus_reflex
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.5.0.pre8
4
+ version: 3.5.0.pre9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Hopkins
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-11-22 00:00:00.000000000 Z
11
+ date: 2022-04-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rack
14
+ name: actioncable
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '5.2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '5.2'
27
27
  - !ruby/object:Gem::Dependency
28
- name: nokogiri
28
+ name: actionpack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '5.2'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '5.2'
41
41
  - !ruby/object:Gem::Dependency
42
- name: rails
42
+ name: actionview
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,49 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '5.2'
55
55
  - !ruby/object:Gem::Dependency
56
- name: redis
56
+ name: activesupport
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '5.2'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '5.2'
69
+ - !ruby/object:Gem::Dependency
70
+ name: railties
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '5.2'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '5.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cable_ready
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 5.0.0.pre9
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: 5.0.0.pre9
97
+ - !ruby/object:Gem::Dependency
98
+ name: nokogiri
57
99
  requirement: !ruby/object:Gem::Requirement
58
100
  requirements:
59
101
  - - ">="
@@ -67,19 +109,33 @@ dependencies:
67
109
  - !ruby/object:Gem::Version
68
110
  version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
- name: cable_ready
112
+ name: rack
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: redis
71
127
  requirement: !ruby/object:Gem::Requirement
72
128
  requirements:
73
- - - '='
129
+ - - ">="
74
130
  - !ruby/object:Gem::Version
75
- version: 5.0.0.pre8
131
+ version: '0'
76
132
  type: :runtime
77
133
  prerelease: false
78
134
  version_requirements: !ruby/object:Gem::Requirement
79
135
  requirements:
80
- - - '='
136
+ - - ">="
81
137
  - !ruby/object:Gem::Version
82
- version: 5.0.0.pre8
138
+ version: '0'
83
139
  - !ruby/object:Gem::Dependency
84
140
  name: bundler
85
141
  requirement: !ruby/object:Gem::Requirement
@@ -95,7 +151,7 @@ dependencies:
95
151
  - !ruby/object:Gem::Version
96
152
  version: '2.0'
97
153
  - !ruby/object:Gem::Dependency
98
- name: github_changelog_generator
154
+ name: mocha
99
155
  requirement: !ruby/object:Gem::Requirement
100
156
  requirements:
101
157
  - - ">="
@@ -109,7 +165,7 @@ dependencies:
109
165
  - !ruby/object:Gem::Version
110
166
  version: '0'
111
167
  - !ruby/object:Gem::Dependency
112
- name: mocha
168
+ name: pry
113
169
  requirement: !ruby/object:Gem::Requirement
114
170
  requirements:
115
171
  - - ">="
@@ -123,7 +179,7 @@ dependencies:
123
179
  - !ruby/object:Gem::Version
124
180
  version: '0'
125
181
  - !ruby/object:Gem::Dependency
126
- name: pry
182
+ name: pry-nav
127
183
  requirement: !ruby/object:Gem::Requirement
128
184
  requirements:
129
185
  - - ">="
@@ -137,19 +193,19 @@ dependencies:
137
193
  - !ruby/object:Gem::Version
138
194
  version: '0'
139
195
  - !ruby/object:Gem::Dependency
140
- name: pry-nav
196
+ name: rails
141
197
  requirement: !ruby/object:Gem::Requirement
142
198
  requirements:
143
199
  - - ">="
144
200
  - !ruby/object:Gem::Version
145
- version: '0'
201
+ version: '5.2'
146
202
  type: :development
147
203
  prerelease: false
148
204
  version_requirements: !ruby/object:Gem::Requirement
149
205
  requirements:
150
206
  - - ">="
151
207
  - !ruby/object:Gem::Version
152
- version: '0'
208
+ version: '5.2'
153
209
  - !ruby/object:Gem::Dependency
154
210
  name: rake
155
211
  requirement: !ruby/object:Gem::Requirement
@@ -178,7 +234,7 @@ dependencies:
178
234
  - - "~>"
179
235
  - !ruby/object:Gem::Version
180
236
  version: '1.0'
181
- description:
237
+ description:
182
238
  email:
183
239
  - natehop@gmail.com
184
240
  executables: []
@@ -193,19 +249,20 @@ files:
193
249
  - LICENSE.txt
194
250
  - README.md
195
251
  - Rakefile
252
+ - app/assets/javascripts/stimulus_reflex.js
253
+ - app/assets/javascripts/stimulus_reflex.min.js
254
+ - app/assets/javascripts/stimulus_reflex.min.js.map
255
+ - app/assets/javascripts/stimulus_reflex.umd.js
256
+ - app/assets/javascripts/stimulus_reflex.umd.min.js
257
+ - app/assets/javascripts/stimulus_reflex.umd.min.js.map
196
258
  - app/channels/stimulus_reflex/channel.rb
197
259
  - bin/console
198
260
  - bin/loc
199
261
  - bin/rake
200
262
  - bin/setup
201
263
  - bin/standardize
202
- - lib/generators/USAGE
203
264
  - lib/generators/stimulus_reflex/initializer_generator.rb
204
265
  - lib/generators/stimulus_reflex/stimulus_reflex_generator.rb
205
- - lib/generators/stimulus_reflex/templates/app/javascript/controllers/%file_name%_controller.js.tt
206
- - lib/generators/stimulus_reflex/templates/app/javascript/controllers/application_controller.js.tt
207
- - lib/generators/stimulus_reflex/templates/app/reflexes/%file_name%_reflex.rb.tt
208
- - lib/generators/stimulus_reflex/templates/app/reflexes/application_reflex.rb.tt
209
266
  - lib/generators/stimulus_reflex/templates/config/initializers/stimulus_reflex.rb
210
267
  - lib/stimulus_reflex.rb
211
268
  - lib/stimulus_reflex/broadcasters/broadcaster.rb
@@ -219,6 +276,9 @@ files:
219
276
  - lib/stimulus_reflex/configuration.rb
220
277
  - lib/stimulus_reflex/dataset.rb
221
278
  - lib/stimulus_reflex/element.rb
279
+ - lib/stimulus_reflex/engine.rb
280
+ - lib/stimulus_reflex/importmap.rb
281
+ - lib/stimulus_reflex/open_struct_fix.rb
222
282
  - lib/stimulus_reflex/policies/reflex_invocation_policy.rb
223
283
  - lib/stimulus_reflex/reflex.rb
224
284
  - lib/stimulus_reflex/reflex_data.rb
@@ -229,7 +289,9 @@ files:
229
289
  - lib/stimulus_reflex/utils/logger.rb
230
290
  - lib/stimulus_reflex/utils/sanity_checker.rb
231
291
  - lib/stimulus_reflex/version.rb
232
- - lib/tasks/stimulus_reflex/install.rake
292
+ - package.json
293
+ - rollup.config.js
294
+ - stimulus_reflex.gemspec
233
295
  - test/broadcasters/broadcaster_test.rb
234
296
  - test/broadcasters/broadcaster_test_case.rb
235
297
  - test/broadcasters/nothing_broadcaster_test.rb
@@ -242,7 +304,10 @@ files:
242
304
  - test/reflex_test.rb
243
305
  - test/test_helper.rb
244
306
  - test/tmp/app/reflexes/application_reflex.rb
245
- - test/tmp/app/reflexes/demo_reflex.rb
307
+ - test/tmp/app/reflexes/user_reflex.rb
308
+ - web-test-runner.config.mjs
309
+ - yarn-error.log
310
+ - yarn.lock
246
311
  homepage: https://github.com/stimulusreflex/stimulus_reflex
247
312
  licenses:
248
313
  - MIT
@@ -268,28 +333,29 @@ required_ruby_version: !ruby/object:Gem::Requirement
268
333
  requirements:
269
334
  - - ">="
270
335
  - !ruby/object:Gem::Version
271
- version: '0'
336
+ version: 2.7.0
272
337
  required_rubygems_version: !ruby/object:Gem::Requirement
273
338
  requirements:
274
339
  - - ">"
275
340
  - !ruby/object:Gem::Version
276
341
  version: 1.3.1
277
342
  requirements: []
278
- rubygems_version: 3.1.6
279
- signing_key:
343
+ rubygems_version: 3.3.3
344
+ signing_key:
280
345
  specification_version: 4
281
346
  summary: Build reactive applications with the Rails tooling you already know and love.
282
347
  test_files:
283
- - test/generators/stimulus_reflex_generator_test.rb
284
- - test/element_test.rb
285
- - test/broadcasters/page_broadcaster_test.rb
286
- - test/broadcasters/broadcaster_test_case.rb
287
348
  - test/broadcasters/broadcaster_test.rb
288
- - test/broadcasters/selector_broadcaster_test.rb
349
+ - test/broadcasters/broadcaster_test_case.rb
289
350
  - test/broadcasters/nothing_broadcaster_test.rb
351
+ - test/broadcasters/page_broadcaster_test.rb
352
+ - test/broadcasters/selector_broadcaster_test.rb
353
+ - test/callbacks_test.rb
354
+ - test/concern_enhancer_test.rb
355
+ - test/element_test.rb
356
+ - test/generators/stimulus_reflex_generator_test.rb
290
357
  - test/reflex_test.rb
291
358
  - test/test_helper.rb
292
- - test/callbacks_test.rb
293
- - test/tmp/app/reflexes/demo_reflex.rb
294
359
  - test/tmp/app/reflexes/application_reflex.rb
295
- - test/concern_enhancer_test.rb
360
+ - test/tmp/app/reflexes/user_reflex.rb
361
+ ...
data/lib/generators/USAGE DELETED
@@ -1,14 +0,0 @@
1
- Description:
2
- Generate boilerplate files to help get you up and running with StimulusReflex
3
-
4
- Example:
5
- rails generate stimulus_reflex User update do_stuff [options]
6
-
7
- This will create, but not overwrite the following files:
8
-
9
- app/javascript/controllers/application_controller.js
10
- app/javascript/controllers/user_controller.js
11
- app/reflexes/application_reflex.rb
12
- app/reflexes/user_reflex.rb
13
-
14
- Don't forget to setup the application: https://docs.stimulusreflex.com/hello-world/setup
@@ -1,101 +0,0 @@
1
- import ApplicationController from './application_controller'
2
-
3
- /* This is the custom StimulusReflex controller for the <%= class_name %> Reflex.
4
- * Learn more at: https://docs.stimulusreflex.com
5
- */
6
- export default class extends ApplicationController {
7
- /*
8
- * Regular Stimulus lifecycle methods
9
- * Learn more at: https://stimulusjs.org/reference/lifecycle-callbacks
10
- *
11
- * If you intend to use this controller as a regular stimulus controller as well,
12
- * make sure any Stimulus lifecycle methods overridden in ApplicationController call super.
13
- *
14
- * Important:
15
- * By default, StimulusReflex overrides the -connect- method so make sure you
16
- * call super if you intend to do anything else when this controller connects.
17
- */
18
-
19
- connect () {
20
- super.connect()
21
- // add your code here, if applicable
22
- }
23
-
24
- /* Reflex specific lifecycle methods.
25
- *
26
- * For every method defined in your Reflex class, a matching set of lifecycle methods become available
27
- * in this javascript controller. These are optional, so feel free to delete these stubs if you don't
28
- * need them.
29
- *
30
- * Important:
31
- * Make sure to add data-controller="<%= class_name.underscore.dasherize %>" to your markup alongside
32
- * data-reflex="<%= class_name %>#dance" for the lifecycle methods to fire properly.
33
- *
34
- * Example:
35
- *
36
- * <a href="#" data-reflex="click-><%= class_name %>#dance" data-controller="<%= class_name.underscore.dasherize %>">Dance!</a>
37
- *
38
- * Arguments:
39
- *
40
- * element - the element that triggered the reflex
41
- * may be different than the Stimulus controller's this.element
42
- *
43
- * reflex - the name of the reflex e.g. "<%= class_name %>#dance"
44
- *
45
- * error/noop - the error message (for reflexError), otherwise null
46
- *
47
- * reflexId - a UUID4 or developer-provided unique identifier for each Reflex
48
- */
49
-
50
- <% if actions.empty? -%>
51
- // Assuming you create a "<%= class_name %>#dance" action in your Reflex class
52
- // you'll be able to use the following lifecycle methods:
53
-
54
- // beforeDance(element, reflex, noop, reflexId) {
55
- // element.innerText = 'Putting dance shoes on...'
56
- // }
57
-
58
- // danceSuccess(element, reflex, noop, reflexId) {
59
- // element.innerText = '\nDanced like no one was watching! Was someone watching?'
60
- // }
61
-
62
- // danceError(element, reflex, error, reflexId) {
63
- // console.error('danceError', error);
64
- // element.innerText = "\nCouldn\'t dance!"
65
- // }
66
-
67
- // afterDance(element, reflex, noop, reflexId) {
68
- // element.innerText = '\nWhatever that was, it\'s over now.'
69
- // }
70
-
71
- // finalizeDance(element, reflex, noop, reflexId) {
72
- // element.innerText = '\nNow, the cleanup can begin!'
73
- // }
74
- <% end -%>
75
- <% actions.each do |action| -%>
76
- // <%= "before_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
77
- // console.log("before <%= action %>", element, reflex, reflexId)
78
- // }
79
-
80
- // <%= "#{action}_success".camelize(:lower) %>(element, reflex, noop, reflexId) {
81
- // console.log("<%= action %> success", element, reflex, reflexId)
82
- // }
83
-
84
- // <%= "#{action}_error".camelize(:lower) %>(element, reflex, error, reflexId) {
85
- // console.error("<%= action %> error", element, reflex, error, reflexId)
86
- // }
87
-
88
- // <%= "#{action}_halted".camelize(:lower) %>(element, reflex, noop, reflexId) {
89
- // console.warn("<%= action %> halted", element, reflex, reflexId)
90
- // }
91
-
92
- // <%= "after_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
93
- // console.log("after <%= action %>", element, reflex, reflexId)
94
- // }
95
-
96
- // <%= "finalize_#{action}".camelize(:lower) %>(element, reflex, noop, reflexId) {
97
- // console.log("finalize <%= action %>", element, reflex, reflexId)
98
- // }
99
- <%= "\n" unless action == actions.last -%>
100
- <% end -%>
101
- }
@@ -1,60 +0,0 @@
1
- import { Controller } from 'stimulus'
2
- import StimulusReflex from 'stimulus_reflex'
3
-
4
- /* This is your ApplicationController.
5
- * All StimulusReflex controllers should inherit from this class.
6
- *
7
- * Example:
8
- *
9
- * import ApplicationController from './application_controller'
10
- *
11
- * export default class extends ApplicationController { ... }
12
- *
13
- * Learn more at: https://docs.stimulusreflex.com
14
- */
15
- export default class extends Controller {
16
- connect () {
17
- StimulusReflex.register(this)
18
- }
19
-
20
- /* Application-wide lifecycle methods
21
- *
22
- * Use these methods to handle lifecycle concerns for the entire application.
23
- * Using the lifecycle is optional, so feel free to delete these stubs if you don't need them.
24
- *
25
- * Arguments:
26
- *
27
- * element - the element that triggered the reflex
28
- * may be different than the Stimulus controller's this.element
29
- *
30
- * reflex - the name of the reflex e.g. "Example#demo"
31
- *
32
- * error/noop - the error message (for reflexError), otherwise null
33
- *
34
- * reflexId - a UUID4 or developer-provided unique identifier for each Reflex
35
- */
36
-
37
- beforeReflex (element, reflex, noop, reflexId) {
38
- // document.body.classList.add('wait')
39
- }
40
-
41
- reflexSuccess (element, reflex, noop, reflexId) {
42
- // show success message
43
- }
44
-
45
- reflexError (element, reflex, error, reflexId) {
46
- // show error message
47
- }
48
-
49
- reflexHalted (element, reflex, error, reflexId) {
50
- // handle aborted Reflex action
51
- }
52
-
53
- afterReflex (element, reflex, noop, reflexId) {
54
- // document.body.classList.remove('wait')
55
- }
56
-
57
- finalizeReflex (element, reflex, noop, reflexId) {
58
- // all operations have completed, animation etc is now safe
59
- }
60
- }
@@ -1,41 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class <%= class_name %>Reflex < ApplicationReflex
4
- # Add Reflex methods in this file.
5
- #
6
- # All Reflex instances include CableReady::Broadcaster and expose the following properties:
7
- #
8
- # - connection - the ActionCable connection
9
- # - channel - the ActionCable channel
10
- # - request - an ActionDispatch::Request proxy for the socket connection
11
- # - session - the ActionDispatch::Session store for the current visitor
12
- # - flash - the ActionDispatch::Flash::FlashHash for the current request
13
- # - url - the URL of the page that triggered the reflex
14
- # - params - parameters from the element's closest form (if any)
15
- # - element - a Hash like object that represents the HTML element that triggered the reflex
16
- # - signed - use a signed Global ID to map dataset attribute to a model eg. element.signed[:foo]
17
- # - unsigned - use an unsigned Global ID to map dataset attribute to a model eg. element.unsigned[:foo]
18
- # - cable_ready - a special cable_ready that can broadcast to the current visitor (no brackets needed)
19
- # - reflex_id - a UUIDv4 that uniquely identies each Reflex
20
- # - tab_id - a UUIDv4 that uniquely identifies the browser tab
21
- #
22
- # Example:
23
- #
24
- # before_reflex do
25
- # # throw :abort # this will prevent the Reflex from continuing
26
- # # learn more about callbacks at https://docs.stimulusreflex.com/rtfm/lifecycle
27
- # end
28
- #
29
- # def example(argument=true)
30
- # # Your logic here...
31
- # # Any declared instance variables will be made available to the Rails controller and view.
32
- # end
33
- #
34
- # Learn more at: https://docs.stimulusreflex.com/rtfm/reflex-classes
35
-
36
- <% actions.each do |action| -%>
37
- def <%= action %>
38
- end
39
- <%= "\n" unless action == actions.last -%>
40
- <% end -%>
41
- end
@@ -1,19 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- class ApplicationReflex < StimulusReflex::Reflex
4
- # Put application-wide Reflex behavior and callbacks in this file.
5
- #
6
- # Learn more at: https://docs.stimulusreflex.com/rtfm/reflex-classes
7
- #
8
- # If your ActionCable connection is: `identified_by :current_user`
9
- # delegate :current_user, to: :connection
10
- #
11
- # If you need to localize your Reflexes, you can set the I18n locale here:
12
- #
13
- # before_reflex do
14
- # I18n.locale = :fr
15
- # end
16
- #
17
- # For code examples, considerations and caveats, see:
18
- # https://docs.stimulusreflex.com/rtfm/patterns#internationalization
19
- end
@@ -1,116 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "fileutils"
4
- require "stimulus_reflex/version"
5
-
6
- namespace :stimulus_reflex do
7
- desc "✨ Install StimulusReflex in this application"
8
- task install: :environment do
9
- system "rails dev:cache" unless Rails.root.join("tmp", "caching-dev.txt").exist?
10
- gem_version = StimulusReflex::VERSION.gsub(".pre", "-pre")
11
- system "yarn add stimulus_reflex@#{gem_version}"
12
- system "bundle exec rails webpacker:install:stimulus"
13
- main_folder = defined?(Webpacker) ? Webpacker.config.source_path.to_s.gsub("#{Rails.root}/", "") : "app/javascript"
14
-
15
- FileUtils.mkdir_p Rails.root.join("#{main_folder}/controllers"), verbose: true
16
- FileUtils.mkdir_p Rails.root.join("app/reflexes"), verbose: true
17
-
18
- filepath = [
19
- "#{main_folder}/controllers/index.js",
20
- "#{main_folder}/controllers/index.ts",
21
- "#{main_folder}/packs/application.js",
22
- "#{main_folder}/packs/application.ts"
23
- ]
24
- .select { |path| File.exist?(path) }
25
- .map { |path| Rails.root.join(path) }
26
- .first
27
-
28
- puts "✨ Updating #{filepath}"
29
- lines = File.readlines(filepath)
30
-
31
- unless lines.find { |line| line.start_with?("import StimulusReflex") }
32
- matches = lines.select { |line| line =~ /\A(require|import)/ }
33
- lines.insert lines.index(matches.last).to_i + 1, "import StimulusReflex from 'stimulus_reflex'\n"
34
- end
35
-
36
- unless lines.find { |line| line.start_with?("import consumer") }
37
- matches = lines.select { |line| line =~ /\A(require|import)/ }
38
- lines.insert lines.index(matches.last).to_i + 1, "import consumer from '../channels/consumer'\n"
39
- end
40
-
41
- unless lines.find { |line| line.start_with?("import controller") }
42
- matches = lines.select { |line| line =~ /\A(require|import)/ }
43
- lines.insert lines.index(matches.last).to_i + 1, "import controller from '../controllers/application_controller'\n"
44
- end
45
-
46
- initialize_line = lines.find { |line| line.start_with?("StimulusReflex.initialize") }
47
- lines << "application.consumer = consumer\n"
48
- lines << "StimulusReflex.initialize(application, { controller, isolate: true })\n" unless initialize_line
49
- lines << "StimulusReflex.debug = process.env.RAILS_ENV === 'development'\n" unless initialize_line
50
- File.write(filepath, lines.join)
51
-
52
- puts
53
- puts "✨ Updating config/environments/development.rb"
54
- filepath = Rails.root.join("config/environments/development.rb")
55
- lines = File.readlines(filepath)
56
- unless lines.find { |line| line.include?("config.session_store") }
57
- matches = lines.select { |line| line =~ /\A(Rails.application.configure do)/ }
58
- lines.insert lines.index(matches.last).to_i + 1, " config.session_store :cache_store\n\n"
59
- puts
60
- puts "✨ Using :cache_store for session storage. We recommend switching to Redis for cache and session storage."
61
- puts
62
- puts "https://docs.stimulusreflex.com/appendices/deployment#use-redis-as-your-cache-store"
63
- File.write(filepath, lines.join)
64
- end
65
-
66
- if defined?(ActionMailer)
67
- lines = File.readlines(filepath)
68
- unless lines.find { |line| line.include?("config.action_mailer.default_url_options") }
69
- matches = lines.select { |line| line =~ /\A(Rails.application.configure do)/ }
70
- lines.insert lines.index(matches.last).to_i + 1, " config.action_mailer.default_url_options = {host: \"localhost\", port: 3000}\n\n"
71
- File.write(filepath, lines.join)
72
- end
73
- end
74
-
75
- lines = File.readlines(filepath)
76
- unless lines.find { |line| line.include?("config.action_controller.default_url_options") }
77
- matches = lines.select { |line| line =~ /\A(Rails.application.configure do)/ }
78
- lines.insert lines.index(matches.last).to_i + 1, " config.action_controller.default_url_options = {host: \"localhost\", port: 3000}\n"
79
- File.write(filepath, lines.join)
80
- end
81
-
82
- puts
83
- puts "✨ Updating config/cable.yml to use Redis in development"
84
- filepath = Rails.root.join("config/cable.yml")
85
- lines = File.readlines(filepath)
86
- if lines[1].include?("adapter: async")
87
- lines.delete_at 1
88
- lines.insert 1, " adapter: redis\n"
89
- lines.insert 2, " url: <%= ENV.fetch(\"REDIS_URL\") { \"redis://localhost:6379/1\" } %>\n"
90
- lines.insert 3, " channel_prefix: " + File.basename(Rails.root.to_s).tr("\\", "").tr("-. ", "_").underscore + "_development\n"
91
- File.write(filepath, lines.join)
92
- end
93
-
94
- puts
95
- puts "✨ Generating default StimulusReflex and CableReady configuration files"
96
- puts
97
- system "bundle exec rails generate stimulus_reflex:initializer"
98
- system "bundle exec rails generate cable_ready:initializer"
99
- system "bundle exec rails generate cable_ready:helpers"
100
-
101
- puts
102
- puts "✨ Generating ApplicationReflex class and Stimulus controllers, plus an example Reflex class and controller"
103
- puts
104
- system "bundle exec rails generate stimulus_reflex example"
105
-
106
- puts
107
- puts "🎉 StimulusReflex and CableReady have been successfully installed! 🎉"
108
- puts
109
- puts "https://docs.stimulusreflex.com/hello-world/quickstart"
110
- puts
111
- puts "😊 The fastest way to get support is to say hello on Discord:"
112
- puts
113
- puts "https://discord.gg/stimulus-reflex"
114
- puts
115
- end
116
- end