react_on_rails 8.0.1 → 8.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +11 -1
  3. data/.travis.yml +9 -11
  4. data/CHANGELOG.md +13 -1
  5. data/CONTRIBUTING.md +2 -2
  6. data/Gemfile +8 -18
  7. data/README.md +7 -3
  8. data/Rakefile +6 -1
  9. data/app/helpers/react_on_rails_helper.rb +41 -35
  10. data/docs/basics/generator.md +1 -1
  11. data/lib/generators/react_on_rails/base_generator.rb +13 -11
  12. data/lib/generators/react_on_rails/dev_tests_generator.rb +8 -16
  13. data/lib/generators/react_on_rails/generator_helper.rb +4 -0
  14. data/lib/generators/react_on_rails/generator_messages.rb +2 -0
  15. data/lib/generators/react_on_rails/install_generator.rb +4 -4
  16. data/lib/generators/react_on_rails/node_generator.rb +4 -2
  17. data/lib/generators/react_on_rails/react_no_redux_generator.rb +3 -1
  18. data/lib/generators/react_on_rails/react_with_redux_generator.rb +5 -3
  19. data/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb +2 -0
  20. data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +2 -0
  21. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +2 -0
  22. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +2 -0
  23. data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +2 -0
  24. data/lib/react_on_rails/assets_precompile.rb +11 -5
  25. data/lib/react_on_rails/configuration.rb +3 -1
  26. data/lib/react_on_rails/controller.rb +2 -0
  27. data/lib/react_on_rails/engine.rb +2 -0
  28. data/lib/react_on_rails/git_utils.rb +2 -0
  29. data/lib/react_on_rails/json_output.rb +2 -0
  30. data/lib/react_on_rails/locales_to_js.rb +13 -9
  31. data/lib/react_on_rails/prerender_error.rb +13 -10
  32. data/lib/react_on_rails/react_component/options.rb +2 -0
  33. data/lib/react_on_rails/server_rendering_pool/exec.rb +8 -0
  34. data/lib/react_on_rails/server_rendering_pool/node.rb +3 -1
  35. data/lib/react_on_rails/server_rendering_pool.rb +2 -0
  36. data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +4 -0
  37. data/lib/react_on_rails/test_helper/node_process_launcher.rb +2 -0
  38. data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +4 -2
  39. data/lib/react_on_rails/test_helper/webpack_assets_status_checker.rb +2 -0
  40. data/lib/react_on_rails/test_helper.rb +3 -1
  41. data/lib/react_on_rails/utils.rb +49 -3
  42. data/lib/react_on_rails/version.rb +3 -1
  43. data/lib/react_on_rails/version_checker.rb +2 -0
  44. data/lib/react_on_rails/version_syntax_converter.rb +2 -0
  45. data/lib/react_on_rails.rb +2 -0
  46. data/lib/tasks/assets.rake +12 -9
  47. data/lib/tasks/locale.rake +7 -4
  48. data/package.json +2 -2
  49. data/rakelib/docker.rake +2 -0
  50. data/rakelib/dummy_apps.rake +3 -6
  51. data/rakelib/example_type.rb +3 -1
  52. data/rakelib/examples.rake +4 -1
  53. data/rakelib/lint.rake +2 -0
  54. data/rakelib/node_package.rake +3 -1
  55. data/rakelib/release.rake +3 -1
  56. data/rakelib/run_rspec.rake +10 -13
  57. data/rakelib/task_helpers.rb +2 -4
  58. data/react_on_rails.gemspec +7 -3
  59. metadata +30 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04272c42e87265c2007505eddd7a236c1eddc7ea
4
- data.tar.gz: 2e8fe89b83cfe9a3b3ed65823655008e612b79a1
3
+ metadata.gz: 8e87c2d5daec14b131563f66b8813aadc20962b0
4
+ data.tar.gz: d04373277451a8cd984a63e1e325fa520b7c932e
5
5
  SHA512:
6
- metadata.gz: 853652ede40c5a0f79fc9d81533ae5240a5c5b610334b7f46fe2b973cab2fa371dc296b1387190b9e1a82c48d60510732c2bfaa8719a3f15635a3c7538b2dcac
7
- data.tar.gz: 4782f170a4cde2012df509e22ff88a60c22a669901ea5df7afc43af123a459d9c8a87dbe9916f3376abc99a64a515457f18bd152d3fa27113871388374fe9341
6
+ metadata.gz: 7779155e1479945571bcf199003b158c78422a8f61ae0bde697544132e78e6a48e42617b0662cb664a455b2f305da7badd53286776206b54b55d6eed5fa19f02
7
+ data.tar.gz: 656b9484ca39ab1b67d26dcaf3e1d38f695c8b8e5be6a1bf8836be392614146eac2c0e8e05576408cee9222d19398372623342f877c4fa026b085a9b7a1cc0ad
data/.rubocop.yml CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  AllCops:
5
5
  DisplayCopNames: true
6
- TargetRubyVersion: 2.1
6
+ TargetRubyVersion: 2.3
7
7
 
8
8
  Include:
9
9
  - '**/Rakefile'
@@ -23,12 +23,22 @@ AllCops:
23
23
  - 'bin/**/*'
24
24
  - !ruby/regexp /old_and_unused\.rb$/
25
25
  - 'spec/react_on_rails/dummy-for-generators/**/*'
26
+ - 'spec/dummy/Procfile.*'
26
27
  - 'spec/dummy/bin/**/*'
27
28
  - 'spec/dummy/client/node_modules/**/*'
28
29
  - 'spec/dummy/client/node_modules/**/.*'
29
30
  - 'gen-examples/examples/**/.*'
30
31
  - 'gen-examples/examples/**/*'
31
32
 
33
+ Style/FileName:
34
+ Exclude:
35
+ - 'Gemfile'
36
+ - 'spec/dummy/Gemfile'
37
+
38
+ # Turn off until we require 2.3 ruby
39
+ Style/SafeNavigation:
40
+ Enabled: false
41
+
32
42
  Metrics/LineLength:
33
43
  Max: 120
34
44
 
data/.travis.yml CHANGED
@@ -3,12 +3,9 @@ sudo: required
3
3
  language: ruby
4
4
 
5
5
  rvm:
6
- # Ruby 2.0.0 fails due to newer Nokogir
7
- # nokogiri-1.7.0.1 requires ruby version >= 2.1.0, which is incompatible with the current version, ruby 2.0.0p648
8
6
  # Rails 5 requires 2.2
9
- # - 2.1.10
10
- - 2.2.6
11
7
  - 2.3.1
8
+ - 2.4.1
12
9
  services:
13
10
  - docker
14
11
 
@@ -36,20 +33,21 @@ before_install:
36
33
  - "/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_99.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :99 -ac -screen scn 1600x1200x16"
37
34
 
38
35
  install:
39
- - travis_retry nvm install node
36
+ - travis_retry gem install bundler
37
+ - travis_retry nvm install node 8.0.0
40
38
  - node -v
41
- - travis_retry npm i -g yarn@0.20.3
42
- - travis_retry yarn
39
+ - travis_retry npm i -g yarn@0.24.6
40
+ - travis_retry yarn global add babel-cli
43
41
  - travis_retry bundle install
44
- - rake dummy_apps
45
- - rake examples
46
- - rake node_package
42
+ - travis_retry yarn
43
+ - travis_retry yarn run build
44
+ - bundle exec rake prepare_for_ci
47
45
 
48
46
  before_script:
49
47
  - "export DISPLAY=:99"
50
48
 
51
49
  script:
52
- - rake
50
+ - bundle exec rake
53
51
 
54
52
  notifications:
55
53
  slack:
data/CHANGELOG.md CHANGED
@@ -8,6 +8,16 @@ Changes since last non-beta release.
8
8
 
9
9
  *Please add entries here for your pull requests.*
10
10
 
11
+ ## [8.0.2]
12
+ ### Fixed
13
+ - Any failure in webpack to build test files quits tests.
14
+ - CI Improvements:
15
+ - Switched to yarn link and removed relative path install of react-on-rails
16
+ - Removed testing of Turbolinks 2
17
+ - All tests run against Rails 5.1.1
18
+ - Fixed test failures against Ruby 2.4
19
+ - [#862](https://github.com/shakacode/react_on_rails/pull/862) by [justin808](https://github.com/justin808)
20
+
11
21
  ## [8.0.1]
12
22
  ### Fixed
13
23
  - Generator no longer modifies `assets.rb`. [#859](https://github.com/shakacode/react_on_rails/pull/859) by [justin808](https://github.com/justin808)
@@ -596,7 +606,9 @@ Best done with Object destructing:
596
606
  ##### Fixed
597
607
  - Fix several generator related issues.
598
608
 
599
- [Unreleased]: https://github.com/shakacode/react_on_rails/compare/8.0.0...master
609
+ [Unreleased]: https://github.com/shakacode/react_on_rails/compare/8.0.2...master
610
+ [8.0.2]: https://github.com/shakacode/react_on_rails/compare/8.0.1...8.0.2
611
+ [8.0.1]: https://github.com/shakacode/react_on_rails/compare/8.0.0...8.0.1
600
612
  [8.0.0]: https://github.com/shakacode/react_on_rails/compare/7.0.4...8.0.0
601
613
  [8.0.0-beta.3]: https://github.com/shakacode/react_on_rails/compare/8.0.0-beta.2...8.0.0-beta.3
602
614
  [8.0.0-beta.2]: https://github.com/shakacode/react_on_rails/compare/8.0.0-beta.1...8.0.0-beta.2
data/CONTRIBUTING.md CHANGED
@@ -111,7 +111,7 @@ When you use a relative path, be sure to run the above `yarn` command whenever y
111
111
 
112
112
  #### Example: Testing NPM changes with the dummy app
113
113
  1. Add `console.log('Hello!')` [here](https://github.com/shakacode/react_on_rails/blob/master/node_package/src/clientStartup.js#L181) in `react_on_rails/node_package/src/clientStartup.js` to confirm we're getting an update to the node package.
114
- 2. Run the install script `npm run install-react-on-rails` in `react_on_rails/spec/dummy` to copy over our changes to the dummy app. Alternatively, you can run `rm -rf node_modules/react-on-rails && npm i 'file:../../../'` in `react_on_rails/spec/dummy/client`. Our NPM changes are now available in the dummy app.
114
+ 2. The "postinstall" script of "spec/dummy/client" calls "yarn link react-on-rails" to setup a sym link to the parent package.
115
115
  3. Refresh the browser if the server is already running or start the server using `foreman start` from `react_on_rails/spec/dummy` and navigate to `http://localhost:5000/`. You will now see the `Hello!` message printed in the browser's console.
116
116
 
117
117
  _Note: running `npm i` automatically builds the npm package before installing. However, when using yarn you will need to run `yarn run build` in the root directory before the install script. This will be updated when [yarn issue #2649](https://github.com/yarnpkg/yarn/issues/2649) (above) is resolved._
@@ -215,7 +215,7 @@ If you run `rspec` at the top level, you'll see this message: `require': cannot
215
215
 
216
216
  After running a test, you can view the coverage results SimpleCov reports by opening `coverage/index.html`.
217
217
 
218
- To test `spec/dummy` against Turbolinks 2, install the gem by running `ENABLE_TURBOLINKS_2=TRUE bundle install` in the `spec/dummy` directory before running `rake`. Turbolinks 5 is the default.
218
+ Turbolinks 5 is included in the test app, unless "DISABLE_TURBOLINKS" is set to YES in the environment.
219
219
 
220
220
  Run `rake -T` or `rake -D` to see testing options.
221
221
 
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem"s dependencies in react_on_rails.gemspec
@@ -14,20 +16,16 @@ gem "mini_racer"
14
16
  gem "puma"
15
17
  gem "rails", "5.1.1"
16
18
  gem "rails_12factor"
17
- gem "rubocop", "0.47.1", require: false
19
+ gem "rubocop", require: false
18
20
  gem "ruby-lint", require: false
19
21
  gem "sass-rails", "~> 5.0"
20
22
  gem "scss_lint", require: false
21
- gem "sdoc", "~> 0.4.0", group: :doc
23
+ gem "sdoc", group: :doc
22
24
  gem "spring"
23
25
  gem "sqlite3"
24
- if ENV["ENABLE_TURBOLINKS_2"].nil? || ENV["ENABLE_TURBOLINKS_2"].strip.empty?
25
- gem "turbolinks", "~> 5.0"
26
- else
27
- gem "turbolinks", "2.5.3"
28
- end
29
- gem "uglifier", ">= 2.7.2"
30
- gem "web-console", "~> 2.0", group: :development
26
+ gem "turbolinks", "~> 5.0"
27
+ gem "uglifier"
28
+ gem "web-console", group: :development
31
29
 
32
30
  # below are copied from spec/dummy/Gemfile
33
31
  gem "capybara"
@@ -42,12 +40,4 @@ gem "poltergeist"
42
40
  gem "selenium-webdriver"
43
41
  gem "webpacker_lite"
44
42
 
45
- ################################################################################
46
- # Favorite debugging gems
47
- gem "pry"
48
- gem "pry-byebug"
49
- gem "pry-doc"
50
- gem "pry-rails"
51
- gem "pry-rescue"
52
- gem "pry-stack_explorer"
53
- ################################################################################
43
+ gem "rainbow"
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  [![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/shakacode/react_on_rails) [![Codeship Status for shakacode/react_on_rails](https://app.codeship.com/projects/cec6c040-971f-0134-488f-0a5146246bd8/status?branch=master)](https://app.codeship.com/projects/187011) [![Dependency Status](https://gemnasium.com/shakacode/react_on_rails.svg)](https://gemnasium.com/shakacode/react_on_rails) [![Gem Version](https://badge.fury.io/rb/react_on_rails.svg)](https://badge.fury.io/rb/react_on_rails) [![npm version](https://badge.fury.io/js/react-on-rails.svg)](https://badge.fury.io/js/react-on-rails) [![Code Climate](https://codeclimate.com/github/shakacode/react_on_rails/badges/gpa.svg)](https://codeclimate.com/github/shakacode/react_on_rails) [![Coverage Status](https://coveralls.io/repos/shakacode/react_on_rails/badge.svg?branch=master&service=github)](https://coveralls.io/github/shakacode/react_on_rails?branch=master)
2
2
 
3
- The Docs here on `master` refer to 8.0.0 including support for [webpacker_lite](https://github.com/shakacode/webpacker_lite)! [7.0.4 docs](https://github.com/shakacode/react_on_rails/tree/7.0.4).
3
+ The Docs here on `master` refer to 8.0.0 including support for [webpacker_lite](https://github.com/shakacode/webpacker_lite)!
4
+ *Use the [7.0.4 docs](https://github.com/shakacode/react_on_rails/tree/7.0.4) to refer to the older asset pipeline way.*
4
5
 
5
- **[VERSION 8.0.0](https://rubygems.org/gems/react_on_rails/versions/8.0.0.beta.3)** has shipped with [webpacker_lite](https://github.com/shakacode/webpacker_lite) support! [react-webpack-rails-tutorial PR #395](https://github.com/shakacode/react-webpack-rails-tutorial/pull/395) shows the changes needed to go to Webpacker Lite.
6
- * Why did we fork webpacker to make webpacker_lite? Please provide feedback on my draft article: [Webpacker Lite: Why Did We Fork Webpacker?](https://medium.com/@railsonmaui/webpacker-lite-why-did-we-fork-webpacker-ee3305688d66) (Draft will soon become regular article).
6
+ **[VERSION 8.0.0](https://rubygems.org/gems/react_on_rails/versions/8.0.0.beta.3)** has shipped with [webpacker_lite](https://github.com/shakacode/webpacker_lite) support! [react-webpack-rails-tutorial PR #395](https://github.com/shakacode/react-webpack-rails-tutorial/pull/395) shows the changes needed to migrate from the Asset Pipeline to Webpacker Lite. For more information, see my article: [Webpacker Lite: Why Fork Webpacker?](https://blog.shakacode.com/webpacker-lite-why-fork-webpacker-f0a7707fac92). Per recent discussions, we may [eventually merge Webpacker Lite changes back into Webpacker](https://github.com/rails/webpacker/issues/464). If so, any changes will be minor if you're using Webpacker Lite.
7
7
 
8
8
  **For a complete example of this gem, see our live demo at [www.reactrails.com](http://www.reactrails.com). ([Source Code](https://github.com/shakacode/react-webpack-rails-tutorial))**
9
9
 
@@ -38,6 +38,7 @@ For more testimonials, see [Live Projects](PROJECTS.md) and [Kudos](./KUDOS.md).
38
38
 
39
39
  ### Articles
40
40
 
41
+ * [Webpacker Lite: Why Fork Webpacker?](https://blog.shakacode.com/webpacker-lite-why-fork-webpacker-f0a7707fac92)
41
42
  * [React on Rails, 2000+ 🌟 Stars](https://medium.com/shakacode/react-on-rails-2000-stars-32ff5cfacfbf#.6gmfb2gpy)
42
43
  * [The React on Rails Doctrine](https://medium.com/@railsonmaui/the-react-on-rails-doctrine-3c59a778c724)
43
44
 
@@ -512,6 +513,9 @@ Node.js can be used as the backend for server-side rendering instead of [execJS]
512
513
 
513
514
  ## Additional Documentation
514
515
  **Try out our new [Documentation Gitbook](https://shakacode.gitbooks.io/react-on-rails/content/) for improved readability & reference!**
516
+ + **Webpacker Lite**
517
+ + [Webpacker Lite: Why Fork Webpacker?](https://blog.shakacode.com/webpacker-lite-why-fork-webpacker-f0a7707fac92)
518
+
515
519
  + **Rails**
516
520
  + [Rails Assets](./docs/additional-reading/rails-assets.md)
517
521
  + [Rails Engine Integration](./docs/additional-reading/rails-engine-integration.md)
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Rake will automatically load any *.rake files inside of the "rakelib" folder
2
4
  # See rakelib/
3
- tasks = %w(run_rspec lint)
5
+ tasks = %w[run_rspec lint]
4
6
  if ENV["USE_COVERALLS"] == "TRUE"
5
7
  require "coveralls/rake/task"
6
8
  Coveralls::RakeTask.new
@@ -12,3 +14,6 @@ task default: tasks
12
14
 
13
15
  desc "All actions but no examples, good for local developer run."
14
16
  task all_but_examples: ["run_rspec:all_but_examples", "lint"]
17
+
18
+ desc "Prepare for ci, including node_package, dummy app, and generator examples"
19
+ task prepare_for_ci: %w[node_package dummy_apps examples]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # rubocop:disable Metrics/ModuleLength
2
4
  # NOTE:
3
5
  # For any heredoc JS:
@@ -11,7 +13,7 @@ require "react_on_rails/json_output"
11
13
  module ReactOnRailsHelper
12
14
  include ReactOnRails::Utils::Required
13
15
 
14
- COMPONENT_HTML_KEY = "componentHtml".freeze
16
+ COMPONENT_HTML_KEY = "componentHtml"
15
17
 
16
18
  # The env_javascript_include_tag and env_stylesheet_link_tag support the usage of a webpack
17
19
  # dev server for providing the JS and CSS assets during development mode. See
@@ -175,7 +177,7 @@ module ReactOnRailsHelper
175
177
  # that contains a data props.
176
178
  def redux_store_hydration_data
177
179
  return if @registered_stores_defer_render.blank?
178
- @registered_stores_defer_render.reduce("") do |accum, redux_store_data|
180
+ @registered_stores_defer_render.reduce("".dup) do |accum, redux_store_data|
179
181
  accum << render_redux_store_data(redux_store_data)
180
182
  end.html_safe
181
183
  end
@@ -188,32 +190,32 @@ module ReactOnRailsHelper
188
190
  # If you have more than one line that needs to be executed, wrap it in an IIFE.
189
191
  # JS exceptions are caught and console messages are handled properly.
190
192
  def server_render_js(js_expression, options = {})
191
- wrapper_js = <<-JS
192
- (function() {
193
- var htmlResult = '';
194
- var consoleReplayScript = '';
195
- var hasErrors = false;
196
-
197
- try {
198
- htmlResult =
193
+ wrapper_js = <<-JS.strip_heredoc
199
194
  (function() {
200
- return #{js_expression};
201
- })();
202
- } catch(e) {
203
- htmlResult = ReactOnRails.handleError({e: e, name: null,
204
- jsCode: '#{escape_javascript(js_expression)}', serverSide: true});
205
- hasErrors = true;
206
- }
207
-
208
- consoleReplayScript = ReactOnRails.buildConsoleReplay();
209
-
210
- return JSON.stringify({
211
- html: htmlResult,
212
- consoleReplayScript: consoleReplayScript,
213
- hasErrors: hasErrors
214
- });
215
-
216
- })()
195
+ var htmlResult = '';
196
+ var consoleReplayScript = '';
197
+ var hasErrors = false;
198
+
199
+ try {
200
+ htmlResult =
201
+ (function() {
202
+ return #{js_expression};
203
+ })();
204
+ } catch(e) {
205
+ htmlResult = ReactOnRails.handleError({e: e, name: null,
206
+ jsCode: '#{escape_javascript(js_expression)}', serverSide: true});
207
+ hasErrors = true;
208
+ }
209
+
210
+ consoleReplayScript = ReactOnRails.buildConsoleReplay();
211
+
212
+ return JSON.stringify({
213
+ html: htmlResult,
214
+ consoleReplayScript: consoleReplayScript,
215
+ hasErrors: hasErrors
216
+ });
217
+
218
+ })()
217
219
  JS
218
220
 
219
221
  result = ReactOnRails::ServerRenderingPool.server_render_js_with_console_logging(wrapper_js)
@@ -300,11 +302,13 @@ module ReactOnRailsHelper
300
302
 
301
303
  def compose_react_component_html_with_spec_and_console(component_specification_tag, rendered_output, console_script)
302
304
  # IMPORTANT: Ensure that we mark string as html_safe to avoid escaping.
305
+ # rubocop:disable Layout/IndentHeredoc
303
306
  <<-HTML.html_safe
304
307
  #{component_specification_tag}
305
308
  #{rendered_output}
306
309
  #{console_script}
307
310
  HTML
311
+ # rubocop:enable Layout/IndentHeredoc
308
312
  end
309
313
 
310
314
  # prepend the rails_context if not yet applied
@@ -367,6 +371,7 @@ module ReactOnRailsHelper
367
371
  #
368
372
  # Read more here: http://timelessrepo.com/json-isnt-a-javascript-subset
369
373
 
374
+ # rubocop:disable Layout/IndentHeredoc
370
375
  wrapper_js = <<-JS
371
376
  (function() {
372
377
  var railsContext = #{rails_context(server_side: true).to_json};
@@ -381,6 +386,7 @@ module ReactOnRailsHelper
381
386
  });
382
387
  })()
383
388
  JS
389
+ # rubocop:enable Layout/IndentHeredoc
384
390
 
385
391
  result = ReactOnRails::ServerRenderingPool.server_render_js_with_console_logging(wrapper_js)
386
392
 
@@ -407,22 +413,22 @@ module ReactOnRailsHelper
407
413
 
408
414
  def initialize_redux_stores
409
415
  return "" unless @registered_stores.present? || @registered_stores_defer_render.present?
410
- declarations = "var reduxProps, store, storeGenerator;\n"
416
+ declarations = "var reduxProps, store, storeGenerator;\n".dup
411
417
 
412
418
  all_stores = (@registered_stores || []) + (@registered_stores_defer_render || [])
413
419
 
414
- result = <<-JS
420
+ result = <<-JS.dup
415
421
  ReactOnRails.clearHydratedStores();
416
422
  JS
417
423
 
418
424
  result << all_stores.each_with_object(declarations) do |redux_store_data, memo|
419
425
  store_name = redux_store_data[:store_name]
420
426
  props = props_string(redux_store_data[:props])
421
- memo << <<-JS
422
- reduxProps = #{props};
423
- storeGenerator = ReactOnRails.getStoreGenerator('#{store_name}');
424
- store = storeGenerator(reduxProps, railsContext);
425
- ReactOnRails.setStore('#{store_name}', store);
427
+ memo << <<-JS.strip_heredoc
428
+ reduxProps = #{props};
429
+ storeGenerator = ReactOnRails.getStoreGenerator('#{store_name}');
430
+ store = storeGenerator(reduxProps, railsContext);
431
+ ReactOnRails.setStore('#{store_name}', store);
426
432
  JS
427
433
  end
428
434
  result
@@ -486,7 +492,7 @@ ReactOnRails.setStore('#{store_name}', store);
486
492
  def send_tag_method(tag_method_name, args)
487
493
  asset_type = use_hot_reloading? ? :hot : :static
488
494
  assets = Array(args[asset_type])
489
- options = args.delete_if { |key, _value| %i(hot static).include?(key) }
495
+ options = args.delete_if { |key, _value| %i[hot static].include?(key) }
490
496
  send(tag_method_name, *assets, options) unless assets.empty?
491
497
  end
492
498
 
@@ -41,7 +41,7 @@ can pass the redux option if you'd like to have redux setup for you automaticall
41
41
 
42
42
  After running the generator, you will want to:
43
43
 
44
- bundle && npm i
44
+ bundle && yarn
45
45
 
46
46
  Then you may run
47
47
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators"
2
4
  require_relative "generator_messages"
3
5
  require_relative "generator_helper"
@@ -38,26 +40,26 @@ module ReactOnRails
38
40
  end
39
41
 
40
42
  def create_react_directories
41
- dirs = %w(components containers startup)
43
+ dirs = %w[components containers startup]
42
44
  dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
43
45
  end
44
46
 
45
47
  def copy_base_files
46
48
  base_path = "base/base/"
47
- base_files = %w(app/controllers/hello_world_controller.rb
49
+ base_files = %w[app/controllers/hello_world_controller.rb
48
50
  config/webpacker_lite.yml
49
51
  client/.babelrc
50
52
  client/webpack.config.js
51
- client/REACT_ON_RAILS_CLIENT_README.md)
53
+ client/REACT_ON_RAILS_CLIENT_README.md]
52
54
  base_files.each { |file| copy_file("#{base_path}#{file}", file) }
53
55
  end
54
56
 
55
57
  def template_base_files
56
58
  base_path = "base/base/"
57
- %w(app/views/layouts/hello_world.html.erb
59
+ %w[app/views/layouts/hello_world.html.erb
58
60
  config/initializers/react_on_rails.rb
59
61
  Procfile.dev
60
- client/package.json).each { |file| template("#{base_path}#{file}.tt", file) }
62
+ client/package.json].each { |file| template("#{base_path}#{file}.tt", file) }
61
63
  end
62
64
 
63
65
  def template_package_json
@@ -136,12 +138,12 @@ STRING
136
138
  regexp = / {2}"scripts": {/
137
139
  else
138
140
  regexp = /^{/
139
- replacement = <<-STRING
140
- {
141
- "scripts": {
142
- #{postinstall}
143
- },
144
- STRING
141
+ replacement = <<-STRING.strip_heredoc
142
+ {
143
+ "scripts": {
144
+ #{postinstall}
145
+ },
146
+ STRING
145
147
  end
146
148
 
147
149
  contents.gsub!(regexp, replacement)
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "rails/generators"
2
4
  require_relative "generator_helper"
3
5
 
4
6
  module ReactOnRails
5
7
  module Generators
6
- FALLBACK_OPTION_FOR_NODE_MODULES = <<-TEXT.freeze
8
+ FALLBACK_OPTION_FOR_NODE_MODULES = <<-TEXT
7
9
  // This fixes an issue with resolving 'react' when using a local symlinked version
8
10
  // of the node_package folder
9
11
  modules: [
@@ -26,29 +28,20 @@ module ReactOnRails
26
28
  desc: "Setup prerender true for server rendered examples"
27
29
 
28
30
  def copy_rspec_files
29
- %w(spec/spec_helper.rb
31
+ %w[spec/spec_helper.rb
30
32
  spec/rails_helper.rb
31
33
  spec/simplecov_helper.rb
32
- .rspec).each { |file| copy_file(file) }
34
+ .rspec].each { |file| copy_file(file) }
33
35
  end
34
36
 
35
37
  def copy_tests
36
- %w(spec/features/hello_world_spec.rb).each { |file| copy_file(file) }
37
- end
38
-
39
- # We want to use the node module in the local build, not the one published to NPM
40
- def change_package_json_to_use_local_react_on_rails_module
41
- package_json = File.join(destination_root, "client", "package.json")
42
- old_contents = File.read(package_json)
43
- new_contents = old_contents.gsub(/"react-on-rails": ".+",/,
44
- '"react-on-rails": "file:../../../..",')
45
- File.open(package_json, "w+") { |f| f.puts new_contents }
38
+ %w[spec/features/hello_world_spec.rb].each { |file| copy_file(file) }
46
39
  end
47
40
 
48
41
  def add_test_related_gems_to_gemfile
49
42
  gem("rspec-rails", group: :test)
43
+ gem("poltergeist", group: :test)
50
44
  gem("coveralls", require: false)
51
- gem("poltergeist")
52
45
  end
53
46
 
54
47
  def replace_prerender_if_server_rendering
@@ -66,8 +59,7 @@ module ReactOnRails
66
59
  contents = File.read(client_package_json)
67
60
  replacement_value = <<-STRING
68
61
  "scripts": {
69
- "postinstall": "yarn run install-react-on-rails",
70
- "install-react-on-rails": "rm -rf node_modules/react-on-rails && npm i 'file:../../../..'",
62
+ "postinstall": "yarn link react-on-rails",
71
63
  STRING
72
64
  new_client_package_json_contents = contents.gsub(/ {2}"scripts": {/,
73
65
  replacement_value)