react_on_rails 2.0.0.rc.1 → 2.0.0.rc.3

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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc +1 -1
  3. data/.rubocop.yml +1 -1
  4. data/.travis.yml +1 -2
  5. data/CHANGELOG.md +46 -0
  6. data/Gemfile +0 -7
  7. data/README.md +16 -2
  8. data/Rakefile +1 -1
  9. data/docs/additional_reading/manual_installation.md +3 -4
  10. data/lib/generators/react_on_rails/base_generator.rb +12 -6
  11. data/lib/generators/react_on_rails/bootstrap_generator.rb +5 -4
  12. data/lib/generators/react_on_rails/dev_tests_generator.rb +20 -2
  13. data/lib/generators/react_on_rails/generator_helper.rb +8 -5
  14. data/lib/generators/react_on_rails/generator_messages.rb +39 -0
  15. data/lib/generators/react_on_rails/heroku_deployment_generator.rb +3 -3
  16. data/lib/generators/react_on_rails/install_generator.rb +34 -14
  17. data/lib/generators/react_on_rails/js_linters_generator.rb +1 -1
  18. data/lib/generators/react_on_rails/react_no_redux_generator.rb +5 -7
  19. data/lib/generators/react_on_rails/react_with_redux_generator.rb +1 -2
  20. data/lib/generators/react_on_rails/ruby_linters_generator.rb +5 -3
  21. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev-hot.tt +4 -0
  22. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +0 -1
  23. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt +66 -0
  24. data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +3 -2
  25. data/lib/generators/react_on_rails/templates/base/base/client/server.js +2 -2
  26. data/lib/generators/react_on_rails/templates/base/base/client/{webpack.client.base.config.js.tt → webpack.client.base.config.js} +4 -2
  27. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js.tt +6 -6
  28. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js +3 -3
  29. data/lib/generators/react_on_rails/templates/base/base/package.json +4 -1
  30. data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +3 -3
  31. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_post-bootstrap.scss +1 -1
  32. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintrc +1 -1
  33. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +9 -7
  34. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +6 -1
  35. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx +4 -4
  36. data/lib/generators/react_on_rails/templates/ruby_linters/{ruby-lint.yml → ruby-lint.yml.tt} +6 -0
  37. data/lib/react_on_rails/version.rb +1 -1
  38. data/package.json +5 -3
  39. data/rakelib/example_type.rb +1 -1
  40. data/rakelib/lint.rake +4 -3
  41. data/react_on_rails.gemspec +12 -2
  42. data/ruby-lint.yml +1 -0
  43. metadata +153 -12
  44. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +0 -39
  45. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +0 -50
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1a3532d98dcdbf8b585e955a5c605d9c884ac6df
4
- data.tar.gz: f7b3342e9599a2ba77087bb44b4004ac38eac4df
3
+ metadata.gz: f249c2ba093b9c1f2099bb6b5d9be21c932023e1
4
+ data.tar.gz: 8fa0f6dae77949df12cdaea2d4e5bfe176e68bd6
5
5
  SHA512:
6
- metadata.gz: d6524e9358002a3124ffbf24620de5b7c4234ce78bf2a2851f8b32093c0d75f8189602b0a972ba94e0f4df7808fe1e29922fe680283e4ce655b7a8c9f3c2a466
7
- data.tar.gz: 35510b925a6828dac60290ad1cb6ca803e2726f412d032d06c4338bc18fa0373b8a5261c15519c8b648a3197609e86ef76da045fedd4beede3f42bd3f5792603
6
+ metadata.gz: 8217b7fa116f964384bcecfb176eeb9036ad990da12d545ec8a2d52d3bc36f0be9edf73b23d3311962748ab72f4f75dc6f41e9e99d4d6bc547785baa3751f079
7
+ data.tar.gz: 7d5ce3efd0ada7e7d9b722c6fb14e7cfa89466db9c58d95ff5773a7a6a929cf834ef95864749e080092878de8e50ce11de6974a10be8f93c9f278928730d7400
data/.eslintrc CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  parser: babel-eslint
3
3
 
4
- extends: eslint-config-airbnb
4
+ extends: eslint-config-shakacode
5
5
 
6
6
  plugins:
7
7
  - react
@@ -57,7 +57,7 @@ Metrics/ParameterLists:
57
57
  # Offense count: 9
58
58
  # Configuration parameters: CountComments.
59
59
  Metrics/MethodLength:
60
- Max: 38
60
+ Max: 41
61
61
 
62
62
  # Offense count: 1
63
63
  # Configuration parameters: CountComments.
@@ -12,8 +12,7 @@ gemfile:
12
12
  - spec/dummy/Gemfile
13
13
 
14
14
  env:
15
- - export RAILS_ENV=test
16
- - export DRIVER=selenium_chrome
15
+ - export RAILS_ENV=test DRIVER=selenium_chrome
17
16
 
18
17
  before_install:
19
18
  - sudo apt-get update
@@ -1,6 +1,52 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file. Items under `Unreleased` is upcoming features that will be out in next version.
3
3
 
4
+ ## v2.0.0
5
+ - Move JavaScript part of react_on_rails to npm package 'react-on-rails'.
6
+ - Converted JavaScript code to ES6! with tests!
7
+ - No global namespace pollution. ReactOnRails is the only global added.
8
+ - New API. Instead of placing React components on the global namespace, you instead call ReactOnRails.register, passing an object where keys are the names of your components.
9
+ ```
10
+ import ReactOnRails from 'react-on-rails';
11
+ ReactOnRails.registerComponent({name: component});
12
+ ```
13
+ Best done with Object destructing
14
+ ```
15
+ import ReactOnRails from 'react-on-rails';
16
+ ReactOnRails.registerComponent(
17
+ {
18
+ Component1,
19
+ Component2
20
+ }
21
+ );
22
+ ```
23
+ Previously, you used
24
+ ```
25
+ window.Component1 = Component1;
26
+ window.Component2 = Component2;
27
+ ```
28
+ This would pollute the global namespace. See details in the README.md for more information.
29
+ - Your jade template for the WebpackDevServer setup should use the new API:
30
+ ```
31
+ ReactOnRails.render(componentName, props, domNodeId);
32
+ ```
33
+ such as:
34
+ ```
35
+ ReactOnRails.render("HelloWorldApp", {name: "Stranger"}, 'app');
36
+ ```
37
+ - All npm dependency libraries updated. Most notable is going to Babel 6.
38
+ - Dropped support for react 0.13.
39
+ - JS Linter uses ShakaCode JavaScript style: https://github.com/shakacode/style-guide-javascript
40
+ - Generators account these differences.
41
+
42
+ ## v1.2.2
43
+ ### Fixed
44
+ - Missing Lodash from generated package.json [#175](https://github.com/shakacode/react_on_rails/pull/175)
45
+ - Rails 3.2 could not run generators [#182](https://github.com/shakacode/react_on_rails/pull/182)
46
+ - Better placement of jquery_ujs dependency [#171](https://github.com/shakacode/react_on_rails/pull/171)
47
+ - Add more detailed description when adding --help option to generator [#161](https://github.com/shakacode/react_on_rails/pull/161)
48
+ - Lots of better docs.
49
+
4
50
  ## v1.2.0
5
51
  ### Added
6
52
  - Support `--skip-bootstrap` or `-b` option for generator.
data/Gemfile CHANGED
@@ -7,7 +7,6 @@ gemspec
7
7
  # They must be defined here because of the way Travis CI works, in that it will only
8
8
  # bundle install from a single Gemfile. Therefore, all gems that we will need for any dummy/example
9
9
  # app have to be manually added to this file.
10
- gem "awesome_print"
11
10
  gem "bootstrap-sass"
12
11
  gem "capybara"
13
12
  gem "capybara-screenshot"
@@ -17,12 +16,6 @@ gem "jbuilder", "~> 2.0"
17
16
  gem "jquery-rails"
18
17
  gem "launchy"
19
18
  gem "poltergeist"
20
- gem "pry"
21
- gem "pry-byebug"
22
- gem "pry-doc"
23
- gem "pry-rails"
24
- gem "pry-rescue"
25
- gem "pry-stack_explorer"
26
19
  gem "puma"
27
20
  gem "rails", "4.2.5"
28
21
  gem "rails_12factor"
data/README.md CHANGED
@@ -1,5 +1,13 @@
1
1
  [![Build Status](https://travis-ci.org/shakacode/react_on_rails.svg?branch=master)](https://travis-ci.org/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) [![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)
2
2
 
3
+ # NEWS
4
+ 2.0 is about to ship! Please grab the latest and let us know if you see any issues!
5
+
6
+ * https://rubygems.org/gems/react_on_rails
7
+ * https://www.npmjs.com/package/react-on-rails
8
+ * Branch: https://github.com/shakacode/react_on_rails/tree/npm-react-on-rails-js
9
+ * PR: https://github.com/shakacode/react_on_rails/pull/148
10
+
3
11
  # React on Rails
4
12
  React on Rails integrates Facebook's [React](https://github.com/facebook/react) front-end framework with Rails. Currently, both React v0.14 and v0.13 are supported, with server rendering. [Redux](https://github.com/rackt/redux) and [React-Router](https://github.com/rackt/react-redux) are supported as well. See the Rails on Maui [blog post](http://www.railsonmaui.com/blog/2014/10/03/integrating-webpack-and-the-es6-transpiler-into-an-existing-rails-project/) that started it all!
5
13
 
@@ -106,10 +114,16 @@ We're definitely not doing that. With react_on_rails, webpack is mainly generati
106
114
  1. Add the following to your Gemfile and bundle install:
107
115
 
108
116
  ```ruby
109
- gem "react_on_rails"
117
+ gem "react_on_rails", "~> 2.0.0"
118
+ ```
119
+
120
+ 2. See help for the generator:
121
+
122
+ ```bash
123
+ rails generate react_on_rails:install --help
110
124
  ```
111
125
 
112
- 2. Run the generator with a simple "Hello World" example:
126
+ 2. Run the generator with a simple "Hello World" example (more options below):
113
127
 
114
128
  ```bash
115
129
  rails generate react_on_rails:install
data/Rakefile CHANGED
@@ -4,4 +4,4 @@ require "coveralls/rake/task"
4
4
  Coveralls::RakeTask.new
5
5
 
6
6
  desc "Run all tests and linting"
7
- task default: ["run_rspec", "docker:lint", "coveralls:push"]
7
+ task default: ["run_rspec", "lint", "coveralls:push"]
@@ -44,7 +44,7 @@ See the next section for a sample webpack.server.rails.config.js.
44
44
  entry: ['./app/startup/serverRegistration'],
45
45
  ```
46
46
  3. Ensure the name of your ouput file (shown [here](https://github.com/shakacode/react-webpack-rails-tutorial/blob/537c985dc82faee333d80509343ca32a3965f9dd/client/webpack.server.rails.config.js#L9)) of your server bundle corresponds to the configuration of the gem. The default path is `app/assets/javascripts/generated`. See below for customization of configuration variables.
47
- 4. Expose `React` in your webpack config, like [this](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/webpack.server.rails.config.js#L23)
47
+ 4. Expose `React` in your webpack config, like [this](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/webpack.server.rails.build.config.js#L54-L55)
48
48
 
49
49
  ```javascript
50
50
  { test: require.resolve('react'), loader: 'expose?React' },
@@ -52,9 +52,8 @@ See the next section for a sample webpack.server.rails.config.js.
52
52
  // For React 0.14
53
53
  { test: require.resolve('react-dom/server'), loader: 'expose?ReactDOMServer' }, // not in client one, only server
54
54
  ```
55
-
56
- ### Sample webpack.server.rails.config.js (ONLY for server rendering)
57
- Be sure to check out the latest example version of [client/webpack.server.rails.config.js](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/webpack.server.rails.config.js).
55
+ ### Sample webpack.server.rails.build.config.js (ONLY for server rendering)
56
+ Be sure to check out the latest example version of [client/webpack.server.rails.build.config.js](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/webpack.server.rails.build.config.js).
58
57
 
59
58
  ```javascript
60
59
  // Common webpack configuration for server bundle
@@ -1,12 +1,12 @@
1
1
  require "rails/generators"
2
- require File.expand_path("../generator_helper", __FILE__)
3
-
4
- include GeneratorHelper
2
+ require_relative "generator_messages"
3
+ require_relative "generator_helper"
5
4
 
6
5
  module ReactOnRails
7
6
  module Generators
8
7
  class BaseGenerator < Rails::Generators::Base # rubocop:disable Metrics/ClassLength
9
- hide!
8
+ include GeneratorHelper
9
+ Rails::Generators.hide_namespace(namespace)
10
10
  source_root(File.expand_path("../templates", __FILE__))
11
11
 
12
12
  # --redux
@@ -62,7 +62,11 @@ module ReactOnRails
62
62
  /app/assets/javascripts/generated/*
63
63
  DATA
64
64
 
65
- dest_file_exists?(".gitignore") ? append_to_file(".gitignore", data) : puts_setup_file_error(".gitignore", data)
65
+ if dest_file_exists?(".gitignore")
66
+ append_to_file(".gitignore", data)
67
+ else
68
+ GeneratorMessages.add_error(setup_file_error(".gitignore", data))
69
+ end
66
70
  end
67
71
 
68
72
  def update_application_js
@@ -111,6 +115,7 @@ module ReactOnRails
111
115
  client/.babelrc
112
116
  client/index.jade
113
117
  client/server.js
118
+ client/webpack.client.base.config.js
114
119
  client/webpack.client.rails.config.js
115
120
  REACT_ON_RAILS.md
116
121
  client/REACT_ON_RAILS_CLIENT_README.md
@@ -120,8 +125,9 @@ module ReactOnRails
120
125
  def template_base_files
121
126
  base_path = "base/base/"
122
127
  %w(Procfile.dev
128
+ Procfile.dev-hot
123
129
  app/views/hello_world/index.html.erb
124
- client/webpack.client.base.config.js
130
+ client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx
125
131
  client/webpack.client.hot.config.js
126
132
  client/package.json).each { |file| template(base_path + file + ".tt", file) }
127
133
  end
@@ -1,11 +1,12 @@
1
1
  require "rails/generators"
2
- require File.expand_path("../generator_helper", __FILE__)
3
- include GeneratorHelper
2
+ require_relative "generator_helper"
3
+ require_relative "generator_messages"
4
4
 
5
5
  module ReactOnRails
6
6
  module Generators
7
7
  class BootstrapGenerator < Rails::Generators::Base
8
- hide!
8
+ include GeneratorHelper
9
+ Rails::Generators.hide_namespace(namespace)
9
10
  source_root(File.expand_path("../templates", __FILE__))
10
11
 
11
12
  def copy_bootstrap_files
@@ -54,7 +55,7 @@ module ReactOnRails
54
55
  if File.exist?(application_scss)
55
56
  append_to_file(application_scss, data)
56
57
  else
57
- puts_setup_file_error(application_scss, data)
58
+ GeneratorMessages.add_error(setup_file_error(application_scss, data))
58
59
  end
59
60
  end
60
61
 
@@ -1,11 +1,11 @@
1
1
  require "rails/generators"
2
2
  require_relative "generator_helper"
3
- include GeneratorHelper
4
3
 
5
4
  module ReactOnRails
6
5
  module Generators
7
6
  class DevTestsGenerator < Rails::Generators::Base
8
- hide!
7
+ include GeneratorHelper
8
+ Rails::Generators.hide_namespace(namespace)
9
9
  source_root(File.expand_path("../templates/dev_tests", __FILE__))
10
10
 
11
11
  def copy_rspec_files
@@ -28,6 +28,24 @@ module ReactOnRails
28
28
  File.open(package_json, "w+") { |f| f.puts new_contents }
29
29
  end
30
30
 
31
+ def change_webpack_client_base_config_to_include_fallback
32
+ text = <<-TEXT
33
+ },
34
+
35
+ // This fixes an issue with resolving 'react' when using a local symlinked version
36
+ // of the node_package folder
37
+ resolveLoader: {
38
+ fallback: [path.join(__dirname, 'node_modules')],
39
+ },
40
+ plugins: [
41
+ TEXT
42
+ sentinel = /^\s\s},\n\s\splugins: \[\n/
43
+ config = File.join(destination_root, "client", "webpack.client.base.config.js")
44
+ old_contents = File.read(config)
45
+ new_contents = old_contents.gsub(sentinel, text)
46
+ File.open(config, "w+") { |f| f.puts new_contents }
47
+ end
48
+
31
49
  def add_test_related_gems_to_gemfile
32
50
  gem("rspec-rails", group: :test)
33
51
  gem("capybara", group: :test)
@@ -1,3 +1,5 @@
1
+ require "rainbow"
2
+
1
3
  module GeneratorHelper
2
4
  # Takes a relative path from the destination root, such as `.gitignore` or `app/assets/javascripts/application.js`
3
5
  def dest_file_exists?(file)
@@ -10,11 +12,12 @@ module GeneratorHelper
10
12
  Dir.exist?(dest_dir) ? dest_dir : nil
11
13
  end
12
14
 
13
- # Takes the missing file and the
14
- def puts_setup_file_error(file, data)
15
- puts "** #{file} was not found."
16
- puts "Please add the following content to your #{file} file:"
17
- puts "\n#{data}\n"
15
+ def setup_file_error(file, data)
16
+ <<-MSG
17
+ #{file} was not found.
18
+ Please add the following content to your #{file} file:
19
+ #{data}
20
+ MSG
18
21
  end
19
22
 
20
23
  def empty_directory_with_keep_file(destination, config = {})
@@ -0,0 +1,39 @@
1
+ module GeneratorMessages
2
+ class << self
3
+ def output
4
+ @output ||= []
5
+ end
6
+
7
+ def add_error(message)
8
+ output << format_error(message)
9
+ end
10
+
11
+ def add_warning(message)
12
+ output << format_warning(message)
13
+ end
14
+
15
+ def add_info(message)
16
+ output << format_info(message)
17
+ end
18
+
19
+ def errors
20
+ output
21
+ end
22
+
23
+ def format_error(msg)
24
+ Rainbow("ERROR: #{msg}").red
25
+ end
26
+
27
+ def format_warning(msg)
28
+ Rainbow("WARNING: #{msg}").orange
29
+ end
30
+
31
+ def format_info(msg)
32
+ Rainbow("#{msg}").green
33
+ end
34
+
35
+ def clear
36
+ @output = []
37
+ end
38
+ end
39
+ end
@@ -1,11 +1,11 @@
1
1
  require "rails/generators"
2
- require File.expand_path("../generator_helper", __FILE__)
3
- include GeneratorHelper
2
+ require_relative "generator_helper"
4
3
 
5
4
  module ReactOnRails
6
5
  module Generators
7
6
  class HerokuDeploymentGenerator < Rails::Generators::Base
8
- hide!
7
+ include GeneratorHelper
8
+ Rails::Generators.hide_namespace(namespace)
9
9
  source_root(File.expand_path("../templates", __FILE__))
10
10
 
11
11
  def copy_heroku_deployment_files
@@ -1,8 +1,12 @@
1
1
  require "rails/generators"
2
+ require_relative "generator_helper"
3
+ require_relative "generator_messages"
2
4
 
3
5
  module ReactOnRails
4
6
  module Generators
5
7
  class InstallGenerator < Rails::Generators::Base
8
+ include GeneratorHelper
9
+
6
10
  # fetch USAGE file for details generator description
7
11
  source_root(File.expand_path("../", __FILE__))
8
12
 
@@ -43,14 +47,32 @@ module ReactOnRails
43
47
  desc: "Skip integrating Bootstrap and don't initialize files and regarding configs. Default: false",
44
48
  aliases: "-b"
45
49
 
50
+ # --ignore-warnings
51
+ class_option :ignore_warnings,
52
+ type: :boolean,
53
+ default: false,
54
+ desc: "Skip warnings. Default: false"
55
+
46
56
  def run_generators
47
- return unless installation_prerequisites_met?
48
- warn_if_nvm_is_not_installed
49
- invoke_generators
57
+ if installation_prerequisites_met? || options.ignore_warnings?
58
+ invoke_generators
59
+ else
60
+ error = "react_on_rails generator prerequisites not met!"
61
+ GeneratorMessages.add_error(error)
62
+ # fail("react_on_rails generator prerequisites not met!")
63
+ end
64
+ ensure
65
+ print_errors
50
66
  end
51
67
 
68
+ # Everything here is not run automatically b/c it's private
69
+
52
70
  private
53
71
 
72
+ def print_errors
73
+ GeneratorMessages.errors.each { |errors| puts errors }
74
+ end
75
+
54
76
  def invoke_generators # rubocop:disable Metrics/CyclomaticComplexity
55
77
  invoke "react_on_rails:base"
56
78
  invoke "react_on_rails:react_no_redux" unless options.redux?
@@ -70,29 +92,27 @@ module ReactOnRails
70
92
 
71
93
  def missing_npm?
72
94
  return false unless `which npm`.blank?
73
- error = "** npm is required. Please install it before continuing."
95
+ error = "npm is required. Please install it before continuing. "
74
96
  error << "https://www.npmjs.com/"
75
- puts error
97
+ GeneratorMessages.add_error(error)
98
+ true
76
99
  end
77
100
 
78
101
  def missing_node?
79
102
  return false unless `which node`.blank?
80
- error = "** nodejs is required. Please install it before continuing."
103
+ error = "** nodejs is required. Please install it before continuing. "
81
104
  error << "https://nodejs.org/en/"
82
- puts error
105
+ GeneratorMessages.add_error(error)
106
+ true
83
107
  end
84
108
 
85
109
  def uncommitted_changes?
86
110
  return false if ENV["COVERAGE"]
87
111
  status = `git status`
88
112
  return false if status.include?("nothing to commit, working directory clean")
89
- error = "** You have uncommitted code. Please commit or stash your changes before continuing"
90
- puts error
91
- end
92
-
93
- def warn_if_nvm_is_not_installed
94
- return true unless `which nvm`.blank?
95
- puts "** nvm is advised. Please consider installing it. https://github.com/creationix/nvm"
113
+ error = "You have uncommitted code. Please commit or stash your changes before continuing"
114
+ GeneratorMessages.add_error(error)
115
+ true
96
116
  end
97
117
  end
98
118
  end