react_on_rails 2.0.1 → 2.0.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
  SHA1:
3
- metadata.gz: e5ca55badb6ceca9925da1de262b446c426c3136
4
- data.tar.gz: 7759b5eb04038825848f76b951f894a9112609d7
3
+ metadata.gz: c2f1692d27068c5ff56f536cb757df449c45f24b
4
+ data.tar.gz: 318551a2d916e05290e9016c3b6b711e5626df6c
5
5
  SHA512:
6
- metadata.gz: 27a7c6c0571f9bf5ac2633b5c668cd91eda08a4c8ede17a13b8e34c404fd8a4dd9f86689864e5ccef3fb7dbb8802e95e5aeedede49a655dad6e0e461437d7ed2
7
- data.tar.gz: bdd6e4ce1686febd1b91b21a98f3cc0c3fe8cf2f637bd5d7ece41e2d9017e20b33a718e89e5a4bc763b219e3d566f761a5811651e8a54f5f91395bd771779ba1
6
+ metadata.gz: bccce7baf521f616d7e3114e4ec3a1ce76d838c2079255ae842f17190c92b732a664f72bff6fc750b8751bbfd8e482ace93573c5b61d84767a8c4c376cbcdc80
7
+ data.tar.gz: cd5e62885e22cf3f30e3402f65dc2e4d1d25adbeb9e1a941848821e73315c9ccd2408e8de4f8c49d45d25c3ed145611b6cbfc097222c2f2cff7b0aa89d66811c
data/CHANGELOG.md CHANGED
@@ -5,50 +5,51 @@ All notable changes to this project will be documented in this file. Items under
5
5
  - Move JavaScript part of react_on_rails to npm package 'react-on-rails'.
6
6
  - Converted JavaScript code to ES6! with tests!
7
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
- ```
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.register({name: component});
12
+ ```
13
+ Best done with Object destructing:
14
+ ```
10
15
  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(
16
+ ReactOnRails.register(
17
17
  {
18
18
  Component1,
19
19
  Component2
20
20
  }
21
21
  );
22
- ```
23
- Previously, you used
22
+ ```
23
+ Previously, you used
24
24
  ```
25
25
  window.Component1 = Component1;
26
26
  window.Component2 = Component2;
27
27
  ```
28
28
  This would pollute the global namespace. See details in the README.md for more information.
29
29
  - Your jade template for the WebpackDevServer setup should use the new API:
30
- ```
30
+ ```
31
31
  ReactOnRails.render(componentName, props, domNodeId);
32
- ```
32
+ ```
33
33
  such as:
34
- ```
34
+ ```
35
35
  ReactOnRails.render("HelloWorldApp", {name: "Stranger"}, 'app');
36
- ```
36
+ ```
37
37
  - All npm dependency libraries updated. Most notable is going to Babel 6.
38
38
  - Dropped support for react 0.13.
39
- - JS Linter uses ShakaCode JavaScript style: https://github.com/shakacode/style-guide-javascript
39
+ - JS Linter uses ShakaCode JavaScript style: https://github.com/shakacode/style-guide-javascript
40
40
  - Generators account these differences.
41
41
 
42
42
  ### Migration Steps
43
43
  [Example of upgrading](https://github.com/shakacode/react-webpack-rails-tutorial/commit/5b1b8698e8daf0f0b94e987740bc85ee237ef608)
44
44
 
45
- 1. Update the `react_on_rails` gem
46
- 2. Search you app for 'generator_function' and remove lines in layouts and rb files that contain it. Determination of a generator function is handled automatically.
47
- 3. Find your files where you registered client and server globals, and use the new ReactOnRails.register syntax. Optionally rename the files `clientRegistration.jsx` and `serverRegistration.jsx` rather than `Globals`.
48
- 4. Update your index.jade to use the new API `ReactOnRails.render("MyApp", !{props}, 'app');`
49
- 5. Update your webpack files per the example commit. Remove globally exposing React and ReactDom, as well as their inclusion in the `entry` section. These are automatically included now.
50
-
51
- That's it!
45
+ 1. Update the `react_on_rails` gem.
46
+ 2. Remove `//= require react_on_rails` from any files such as `app/assets/javascripts/application.js`. This file comes from npm now.
47
+ 3. Search you app for 'generator_function' and remove lines in layouts and rb files that contain it. Determination of a generator function is handled automatically.
48
+ 4. Find your files where you registered client and server globals, and use the new ReactOnRails.register syntax. Optionally rename the files `clientRegistration.jsx` and `serverRegistration.jsx` rather than `Globals`.
49
+ 5. Update your index.jade to use the new API `ReactOnRails.render("MyApp", !{props}, 'app');`
50
+ 6. Update your webpack files per the example commit. Remove globally exposing React and ReactDom, as well as their inclusion in the `entry` section. These are automatically included now.
51
+ 7. Run `cd client && npm i --save react-on-rails` to get react-on-rails into your `client/package.json`.
52
+ 8. You should also update any other dependencies if possible to match up with the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/).
52
53
 
53
54
  ## v1.2.2
54
55
  ### Fixed
data/README.md CHANGED
@@ -2,10 +2,13 @@
2
2
 
3
3
  # NEWS
4
4
 
5
- * 2.0 has shipped! Please grab the latest and let us know if you see any issues!
6
- * It does not yet have *generator* support for CSS modules and hot reloading via the Rails server per shown in the [shakacode/react-webpack-rails-tutorial]. We're always looking for contributors! Thus, the setup for webpack, foreman, and sass will be somewhat different until we get the generators caught up.
5
+ * 2.0 has shipped! Please grab the latest and let us know if you see any issues! [Migration steps from 1.x](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md#migration-steps).
6
+ * It does not yet have *generator* support for building new apps that use CSS modules and hot reloading via the Rails server as is demonstrated in the [shakacode/react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/). *We do support this, but we don't generate the code.* If you did generate a fresh app from react_on_rails and want to move to CSS Modules, then see [PR 175: Babel 6 / CSS Modules / Rails hot reloading](https://github.com/shakacode/react-webpack-rails-tutorial/pull/175). Note, while there are probably fixes after this PR was accepted, this has the majority of the changes. See [the tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/#news) for more information. Ping us if you want to help!
7
7
 
8
8
  # React on Rails
9
+
10
+ **Project Objective**: To provide an opinionated and optimal framework for integrating **Ruby on Rails** with modern JavaScript tooling and libraries, including [**Webpack**](http://webpack.github.io/), [**Babel**](https://babeljs.io/), [**React**](https://github.com/rackt/react-router), [**Redux**](https://github.com/rackt/redux), [**React-Router**](https://github.com/rackt/react-router). This differs significantly from typical Rails. When considering what goes into **react_on_rails**, we ask ourselves, is the functionality related to the intersection of using Rails and with modern JavaScript? If so, then the functionality belongs right here. In other cases, we're releasing separate npm packages or Ruby gems.
11
+
9
12
  React on Rails integrates Facebook's [React](https://github.com/facebook/react) front-end framework with Rails. React v0.14.x is 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!
10
13
 
11
14
  Be sure to see the [React Webpack Rails Tutorial Code](https://github.com/shakacode/react-webpack-rails-tutorial) along with the live example at [www.reactrails.com](http://www.reactrails.com).
@@ -25,22 +28,22 @@ Please see [Getting Started](#getting-started) for how to set up your Rails proj
25
28
  ```
26
29
 
27
30
  + The `component_name` parameter is a string matching the name you used to globally expose your React component. So, in the above examples, if you had a React component named "HelloWorldApp," you would register it with the following lines:
28
-
31
+
29
32
  ```js
30
33
  import ReactOnRails from 'react-on-rails';
31
34
  import HelloWorldApp from './HelloWorldApp';
32
35
  ReactOnRails.register({ HelloWorldApp });
33
36
  ```
34
-
37
+
35
38
  Exposing your component in this way is how React on Rails is able to reference your component from a Rails view. You can expose as many components as you like, as long as their names do not collide. See below for the details of how you expose your components via the react_on_rails webpack configuration.
36
-
39
+
37
40
  + `@some_props` can be either a hash or JSON string. This is an optional argument assuming you do not need to pass any options (if you want to pass options, such as `prerender: true`, but you do not want to pass any properties, simply pass an empty hash `{}`). This will make the data available in your component:
38
41
 
39
42
  ```ruby
40
43
  # Rails View
41
44
  <%= react_component("HelloWorldApp", { name: "Stranger" })
42
45
  ```
43
-
46
+
44
47
  ```javascript
45
48
  // inside your React component
46
49
  this.props.name // "Stranger"
@@ -87,9 +90,7 @@ Like the [react-rails](https://github.com/reactjs/react-rails) gem, React on Rai
87
90
  + [Redux](https://github.com/rackt/redux)
88
91
  + [Webpack dev server](https://webpack.github.io/docs/webpack-dev-server.html) with [hot module replacement](https://webpack.github.io/docs/hot-module-replacement-with-webpack.html)
89
92
  + [Webpack optimization functionality](https://github.com/webpack/docs/wiki/optimization)
90
- + _*(Coming Soon)*_ [React Router](https://github.com/rackt/react-router)
91
- + *([Gem *Pull Request*](https://github.com/shakacode/react_on_rails/pull/68))*
92
- + *([Tutorial Pull Request](https://github.com/shakacode/react-webpack-rails-tutorial/pull/128))*
93
+ + [React Router](https://github.com/rackt/react-router)
93
94
 
94
95
  See the [react-webpack-rails-tutorial](https://github.com/shakacode/react-webpack-rails-tutorial) for an example of a live implementation and code.
95
96
 
@@ -126,7 +127,7 @@ We're definitely not doing that. With react_on_rails, webpack is mainly generati
126
127
  rails generate react_on_rails:install
127
128
  ```
128
129
 
129
- 3. NPM install. Make sure you are on a recent version of node, preferably using nvm.
130
+ 3. NPM install. Make sure you are on a recent version of node, preferably using nvm. We've heard some reports that you need at least Node v5.
130
131
 
131
132
  ```bash
132
133
  npm install
@@ -208,7 +209,7 @@ This is how you actually render the React components you exposed to `window` ins
208
209
  #### react_component
209
210
  `react_component(component_name, props = {}, options = {})`
210
211
 
211
- + **react_component_name:** Can be a React component, created using a ES6 class, or `React.createClass`, or a generator function that returns a React component.
212
+ + **component_name:** Can be a React component, created using a ES6 class, or `React.createClass`, or a generator function that returns a React component.
212
213
  + **props:** Ruby Hash which contains the properties to pass to the react object, or a JSON string. If you pass a string, we'll escape it for you.
213
214
  + **options:**
214
215
  + **prerender:** enable server-side rendering of component. Set to false when debugging!
@@ -231,7 +232,7 @@ This is a helper method that takes any JavaScript expression and returns the out
231
232
 
232
233
  ## Generator
233
234
  The `react_on_rails:install` generator combined with the example pull requests of generator runs will get you up and running efficiently. There's a fair bit of setup with integrating Webpack with Rails. Defaults for options are such that the default is for the flag to be off. For example, the default for `-R` is that `redux` is off, and the default of `-b` means that `skip-bootstrap` is off.
234
-
235
+
235
236
  Run `rails generate react_on_rails:install --help` for descriptions of all available options:
236
237
 
237
238
  ```
@@ -256,10 +257,10 @@ Description:
256
257
  Create react on rails files for install generator.
257
258
  ```
258
259
 
259
- For a clear example of what each generator option will do, see our generator results repo: [Generator Results](https://github.com/shakacode/react_on_rails-generator-results/blob/master/README.md). Each pull request shows a git "diff" that highlights the changes that the generator has made.
260
+ For a clear example of what each generator option will do, see our generator results repo: [Generator Results](https://github.com/shakacode/react_on_rails-generator-results/blob/master/README.md). Each pull request shows a git "diff" that highlights the changes that the generator has made. Another good option is to create a simple test app per the [Tutorial for v2.0](docs/tutorial-v2.md).
260
261
 
261
262
  ### Understanding the Organization of the Generated Client Code
262
- The generated client code follows our organization scheme. Each unique set of functionality, is given its own folder inside of `client/app/bundles`. This encourages for modularity of DOMAINS.
263
+ The generated client code follows our organization scheme. Each unique set of functionality, is given its own folder inside of `client/app/bundles`. This encourages for modularity of *domains*.
263
264
 
264
265
  Inside of the generated "HelloWorld" domain you will find the following folders:
265
266
 
data/docs/tutorial-v2.md CHANGED
@@ -1,3 +1,5 @@
1
+ # Tutorial for v2.0
2
+
1
3
  I just released RC3 of [React On Rails](https://github.com/shakacode/react_on_rails/tree/npm-react-on-rails-js). Here's a tiny tutorial to get you started. This tutorial setups up a new Rails app with **React on Rails**, demonstrating Rails + React + Redux + Server Rendering.
2
4
 
3
5
  You can find:
@@ -46,7 +48,7 @@ npm run rails-server
46
48
  Visit http://localhost:3000/hello_world and see your React On Rails app running!
47
49
 
48
50
  ```
49
- npm run node-server-hot
51
+ npm run express-server
50
52
  ```
51
53
 
52
54
  <img src="http://forum.shakacode.com/uploads/default/original/1X/5bd396a7f9c0764929b693fb79eb6685ec6f62cf.png" width="470" height="499">
@@ -192,6 +192,24 @@ module ReactOnRails
192
192
  new_name = File.join(destination_root, "#{base_path}application.scss")
193
193
  File.rename(bad_name, new_name)
194
194
  end
195
+
196
+ def print_helpful_message
197
+ message = <<-MSG.strip_heredoc
198
+
199
+ What to do next:
200
+
201
+ - Ensure your bundle and npm are up to date.
202
+
203
+ bundle && npm i
204
+
205
+ - Run the npm rails-server command to load the rails server.
206
+
207
+ npm run rails-server
208
+
209
+ - Visit http://localhost:3000/hello_world and see your React On Rails app running!
210
+ MSG
211
+ GeneratorMessages.add_info(message)
212
+ end
195
213
  end
196
214
  end
197
215
  end
@@ -16,7 +16,7 @@ module GeneratorMessages
16
16
  output << format_info(message)
17
17
  end
18
18
 
19
- def errors
19
+ def messages
20
20
  output
21
21
  end
22
22
 
@@ -62,15 +62,15 @@ module ReactOnRails
62
62
  # fail("react_on_rails generator prerequisites not met!")
63
63
  end
64
64
  ensure
65
- print_errors
65
+ print_generator_messages
66
66
  end
67
67
 
68
68
  # Everything here is not run automatically b/c it's private
69
69
 
70
70
  private
71
71
 
72
- def print_errors
73
- GeneratorMessages.errors.each { |errors| puts errors }
72
+ def print_generator_messages
73
+ GeneratorMessages.messages.each { |message| puts message }
74
74
  end
75
75
 
76
76
  def invoke_generators # rubocop:disable Metrics/CyclomaticComplexity
@@ -45,6 +45,17 @@ module ReactOnRails
45
45
  location = "client/app/bundles/HelloWorld/startup"
46
46
  template("redux/base/#{location}/HelloWorldAppClient.jsx.tt", "#{location}/#{filename}")
47
47
  end
48
+
49
+ def print_helpful_message
50
+ message = <<-MSG
51
+ - Run the npm express-server command to load the node server with hot reloading support.
52
+
53
+ npm run express-server
54
+
55
+ - Visit http://localhost:4000 and see your React On Rails app running using the Webpack Dev server.
56
+ MSG
57
+ GeneratorMessages.add_info(message)
58
+ end
48
59
  end
49
60
  end
50
61
  end
@@ -1,4 +1,4 @@
1
- <%- require 'react_on_rails/version' -%>
1
+ <%- require "react_on_rails/version_syntax_converter" -%>
2
2
  {
3
3
  "name": "react-webpack-rails-tutorial",
4
4
  "version": "1.1.0",
@@ -64,7 +64,7 @@
64
64
  "react-bootstrap": "^0.28.1",
65
65
  <%- end -%>
66
66
  "react-dom": "^0.14.3",
67
- "react-on-rails": "<%= x = ReactOnRails::VERSION.match(/(\d+\.\d+\.\d+)/); "#{x[1]}" %>",
67
+ "react-on-rails": "<%= VersionSyntaxConverter.new.rubygem_to_npm %>",
68
68
  <%- if options.redux? -%>
69
69
  "react-redux": "^4.0.5",
70
70
  "redux": "^3.0.5",
@@ -10,7 +10,7 @@
10
10
  "scripts": {
11
11
  "postinstall": "cd client && npm install",
12
12
  "test": "rspec && (cd client && npm run lint)",
13
- "node-server-hot": "echo 'visit http://localhost:4000' && cd client && npm start",
13
+ "express-server": "echo 'visit http://localhost:4000' && cd client && npm start",
14
14
  "rails-server": "echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev"
15
15
  },
16
16
  "repository": {
@@ -1,3 +1,3 @@
1
1
  module ReactOnRails
2
- VERSION = "2.0.1"
2
+ VERSION = "2.0.2"
3
3
  end
@@ -1,6 +1,9 @@
1
1
  require_relative "version"
2
+ require_relative "version_syntax_converter"
2
3
 
3
4
  module ReactOnRails
5
+ # Responsible for checking versions of rubygem versus npm node package
6
+ # against each otherat runtime.
4
7
  class VersionChecker
5
8
  attr_reader :node_package_version, :logger
6
9
 
@@ -13,10 +16,12 @@ module ReactOnRails
13
16
  @node_package_version = node_package_version
14
17
  end
15
18
 
16
- # For compatibility, the gem and the node package versions should always match, unless the user
17
- # really knows what they're doing. So we will give a warning if they do not.
19
+ # For compatibility, the gem and the node package versions should always match,
20
+ # unless the user really knows what they're doing. So we will give a
21
+ # warning if they do not.
18
22
  def warn_if_gem_and_node_package_versions_differ
19
- return if node_package_version.major == gem_major_version || node_package_version.relative_path?
23
+ return if node_package_version.relative_path?
24
+ return if node_package_version.major == gem_major_version
20
25
  log_differing_versions_warning
21
26
  end
22
27
 
@@ -58,21 +63,13 @@ module ReactOnRails
58
63
  JSON.parse(package_json_contents)["dependencies"]["react-on-rails"]
59
64
  end
60
65
 
61
- def normalized
62
- match = raw
63
- .tr("-", ".")
64
- .strip
65
- .match(/(\d.*)/)
66
- match.present? ? match[0] : nil
67
- end
68
-
69
66
  def relative_path?
70
- normalized.nil? # must be a relative path if nil and we haven't failed
67
+ raw.match(/\.\./).present?
71
68
  end
72
69
 
73
70
  def major
74
- return if normalized.nil?
75
- normalized.match(/(\d+)\./)[1]
71
+ return if relative_path?
72
+ raw.match(/(\d+)\./)[1]
76
73
  end
77
74
 
78
75
  private
@@ -0,0 +1,20 @@
1
+ require_relative "version"
2
+
3
+ class VersionSyntaxConverter
4
+ def rubygem_to_npm(rubygem_version = ReactOnRails::VERSION)
5
+ regex_match = rubygem_version.match(/(\d+\.\d+\.\d+)[.\-]?(.+)?/)
6
+ if regex_match[2]
7
+ return "#{regex_match[1]}-#{regex_match[2]}"
8
+ else
9
+ return "#{regex_match[1]}"
10
+ end
11
+ end
12
+
13
+ def npm_to_rubygem(npm_version)
14
+ match = npm_version
15
+ .tr("-", ".")
16
+ .strip
17
+ .match(/(\d.*)/)
18
+ match.present? ? match[0] : nil
19
+ end
20
+ end
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-on-rails",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "react-on-rails JavaScript for react_on_rails Ruby gem",
5
5
  "main": "node_package/lib/ReactOnRails.js",
6
6
  "directories": {
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: react_on_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Gordon
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-01-14 00:00:00.000000000 Z
11
+ date: 2016-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: connection_pool
@@ -378,6 +378,7 @@ files:
378
378
  - lib/react_on_rails/server_rendering_pool.rb
379
379
  - lib/react_on_rails/version.rb
380
380
  - lib/react_on_rails/version_checker.rb
381
+ - lib/react_on_rails/version_syntax_converter.rb
381
382
  - package.json
382
383
  - rakelib/docker.rake
383
384
  - rakelib/dummy_apps.rake