react_on_rails 6.4.1 → 6.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +11 -2
- data/README.md +2 -4
- data/docs/additional-reading/react-router.md +0 -65
- data/docs/api/javascript-api.md +1 -3
- data/lib/generators/react_on_rails/install_generator.rb +2 -2
- data/lib/react_on_rails/utils.rb +4 -0
- data/lib/react_on_rails/version.rb +1 -1
- data/package.json +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc9ce8dfafb075ba679a34c960037df7c61746ff
|
4
|
+
data.tar.gz: 35d775a65518d91e1b46733758cdf9883c52b6ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e6c98e563102e792da954e116ef75e7774c13698c970be417869d667364e0bfa604b4e815eb9e22f9e87540e897da7988bd3823ec98836c98846e763195081e
|
7
|
+
data.tar.gz: d675c0ad865f9edd283ba64344e2912cceac4ec50720c6f00c676a8e1d458ad5363cefa86f1f7adcac9847613215fae47701bb7e090b786cbf4bfa31710b7c97
|
data/CHANGELOG.md
CHANGED
@@ -6,10 +6,17 @@ Contributors: please follow the recommendations outlined at [keepachangelog.com]
|
|
6
6
|
## [Unreleased]
|
7
7
|
*Please add entries here for your pull requests.*
|
8
8
|
|
9
|
+
## [6.4.2] - 2017-1-17
|
10
|
+
### Fixed
|
11
|
+
- Added OS detection for install generator, system call for Windows and unit-tests for it. [#666](https://github.com/shakacode/react_on_rails/pull/666) by [GeorgeGorbanev](https://github.com/GeorgeGorbanev).
|
12
|
+
|
13
|
+
## [6.4.1] - 2017-1-17
|
14
|
+
No changes.
|
15
|
+
|
9
16
|
## [6.4.0] - 2017-1-12
|
10
17
|
|
11
18
|
### Possible Breaking Change
|
12
|
-
- Since foreman is no longer a dependency of the React on Rails gem, please run `gem install foreman`. If you are using rvm, you may wish to run `rvm @global do gem install foreman` to install foreman for all your gemsets.
|
19
|
+
- Since foreman is no longer a dependency of the React on Rails gem, please run `gem install foreman`. If you are using rvm, you may wish to run `rvm @global do gem install foreman` to install foreman for all your gemsets.
|
13
20
|
|
14
21
|
### Fixed
|
15
22
|
- Removed foreman as a dependency. [#678](https://github.com/shakacode/react_on_rails/pull/678) by [x2es](https://github.com/x2es).
|
@@ -428,7 +435,9 @@ Best done with Object destructing:
|
|
428
435
|
##### Fixed
|
429
436
|
- Fix several generator related issues.
|
430
437
|
|
431
|
-
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.4.
|
438
|
+
[Unreleased]: https://github.com/shakacode/react_on_rails/compare/6.4.2...master
|
439
|
+
[6.4.2]: https://github.com/shakacode/react_on_rails/compare/6.4.1...6.4.2
|
440
|
+
[6.4.1]: https://github.com/shakacode/react_on_rails/compare/6.4.0...6.4.1
|
432
441
|
[6.4.0]: https://github.com/shakacode/react_on_rails/compare/6.3.5...6.4.0
|
433
442
|
[6.3.5]: https://github.com/shakacode/react_on_rails/compare/6.3.4...6.3.5
|
434
443
|
[6.3.4]: https://github.com/shakacode/react_on_rails/compare/6.3.3...6.3.4
|
data/README.md
CHANGED
@@ -217,7 +217,7 @@ On production deployments that use asset precompilation, such as Heroku deployme
|
|
217
217
|
If you have used the provided generator, these bundles will automatically be added to your `.gitignore` to prevent extraneous noise from re-generated code in your pull requests. You will want to do this manually if you do not use the provided generator.
|
218
218
|
|
219
219
|
### Rails Context
|
220
|
-
When you use a "generator function" to create react components
|
220
|
+
When you use a "generator function" to create react components or you used shared redux stores, you get 2 params passed to your function:
|
221
221
|
|
222
222
|
1. Props that you pass in the view helper of either `react_component` or `redux_store`
|
223
223
|
2. Rails contextual information, such as the current pathname. You can customize this in your config file.
|
@@ -318,8 +318,6 @@ If you do want different code to run, you'd setup a separate webpack compilation
|
|
318
318
|
#### Generator Functions
|
319
319
|
Why would you create a function that returns a React component? For example, you may want the ability to use the passed-in props to initialize a redux store or setup react-router. Or you may want to return different components depending on what's in the props. ReactOnRails will automatically detect a registered generator function.
|
320
320
|
|
321
|
-
Another reason to user a generator function is that sometimes in server rendering, specifically with React Router, you need to return the result of calling ReactDOMServer.renderToString(element). You can do this by returning an object with the following shape: { renderedHtml, redirectLocation, error }.
|
322
|
-
|
323
321
|
#### Renderer Functions
|
324
322
|
A renderer function is a generator function that accepts three arguments: `(props, railsContext, domNodeId) => { ... }`. Instead of returning a React component, a renderer is responsible for calling `ReactDOM.render` to manually render a React component into the dom. Why would you want to call `ReactDOM.render` yourself? One possible use case is [code splitting](docs/additional-reading/code-splitting.md).
|
325
323
|
|
@@ -342,7 +340,7 @@ react_component(component_name,
|
|
342
340
|
html_options: {})
|
343
341
|
```
|
344
342
|
|
345
|
-
+ **component_name:** Can be a React component, created using a ES6 class, or `React.createClass`, a generator function that returns a React component
|
343
|
+
+ **component_name:** Can be a React component, created using a ES6 class, or `React.createClass`, a generator function that returns a React component, or a renderer function that manually renders a React component to the dom (client side only).
|
346
344
|
+ **options:**
|
347
345
|
+ **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.
|
348
346
|
+ **prerender:** enable server-side rendering of component. Set to false when debugging!
|
@@ -46,68 +46,3 @@ For a fleshed out integration of react_on_rails with react-router, check out [Re
|
|
46
46
|
* [react-webpack-rails-tutorial/client/app/bundles/comments/startup/ClientRouterApp.jsx](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/app/bundles/comments/startup/ClientRouterApp.jsx)
|
47
47
|
|
48
48
|
* [react-webpack-rails-tutorial/client/app/bundles/comments/startup/ServerRouterApp.jsx](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/app/bundles/comments/startup/ServerRouterApp.jsx)
|
49
|
-
|
50
|
-
|
51
|
-
# Server Rendering Using React Router V4
|
52
|
-
|
53
|
-
Your generator function may not return an object with the property `renderedHtml`. Thus, you call
|
54
|
-
renderToString() and return an object with this property.
|
55
|
-
|
56
|
-
This example **only applies to server rendering** and should be only used in the server side bundle.
|
57
|
-
|
58
|
-
From the [original example in the ReactRouter docs](https://react-router.now.sh/ServerRouter)
|
59
|
-
|
60
|
-
```javascript
|
61
|
-
import React from 'react'
|
62
|
-
import { renderToString } from 'react-dom/server'
|
63
|
-
import { ServerRouter, createServerRenderContext } from 'react-router'
|
64
|
-
|
65
|
-
const ReactRouterComponent = (props, railsContext) => {
|
66
|
-
|
67
|
-
// first create a context for <ServerRouter>, it's where we keep the
|
68
|
-
// results of rendering for the second pass if necessary
|
69
|
-
const context = createServerRenderContext()
|
70
|
-
const { location } = railsContext;
|
71
|
-
|
72
|
-
// render the first time
|
73
|
-
let markup = renderToString(
|
74
|
-
<ServerRouter
|
75
|
-
location={location}
|
76
|
-
context={context}
|
77
|
-
>
|
78
|
-
<App/>
|
79
|
-
</ServerRouter>
|
80
|
-
)
|
81
|
-
|
82
|
-
// get the result
|
83
|
-
const result = context.getResult()
|
84
|
-
|
85
|
-
// the result will tell you if it redirected, if so, we ignore
|
86
|
-
// the markup and send a proper redirect.
|
87
|
-
if (result.redirect) {
|
88
|
-
return {
|
89
|
-
redirectLocation: result.redirect.pathname
|
90
|
-
};
|
91
|
-
} else {
|
92
|
-
|
93
|
-
// the result will tell you if there were any misses, if so
|
94
|
-
// we can send a 404 and then do a second render pass with
|
95
|
-
// the context to clue the <Miss> components into rendering
|
96
|
-
// this time (on the client they know from componentDidMount)
|
97
|
-
if (result.missed) {
|
98
|
-
// React on Rails does not support the 404 status code for the browser.
|
99
|
-
// res.writeHead(404)
|
100
|
-
|
101
|
-
markup = renderToString(
|
102
|
-
<ServerRouter
|
103
|
-
location={location}
|
104
|
-
context={context}
|
105
|
-
>
|
106
|
-
<App/>
|
107
|
-
</ServerRouter>
|
108
|
-
)
|
109
|
-
}
|
110
|
-
return { renderedHtml: markup };
|
111
|
-
}
|
112
|
-
}
|
113
|
-
```
|
data/docs/api/javascript-api.md
CHANGED
@@ -4,9 +4,7 @@ The best source of docs is the main [ReactOnRails.js](../../node_package/src/Rea
|
|
4
4
|
```js
|
5
5
|
/**
|
6
6
|
* Main entry point to using the react-on-rails npm package. This is how Rails will be able to
|
7
|
-
* find you components for rendering.
|
8
|
-
* "generator function" to return a React component or an object with the following shape:
|
9
|
-
* { renderedHtml, redirectLocation, error }.
|
7
|
+
* find you components for rendering.
|
10
8
|
* @param components (key is component name, value is component)
|
11
9
|
*/
|
12
10
|
register(components)
|
@@ -64,7 +64,7 @@ module ReactOnRails
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def missing_npm?
|
67
|
-
return false unless `which npm`.blank?
|
67
|
+
return false unless ReactOnRails::Utils.running_on_windows? ? `where npm`.blank? : `which npm`.blank?
|
68
68
|
error = "npm is required. Please install it before continuing. "
|
69
69
|
error << "https://www.npmjs.com/"
|
70
70
|
GeneratorMessages.add_error(error)
|
@@ -72,7 +72,7 @@ module ReactOnRails
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def missing_node?
|
75
|
-
return false unless `which node`.blank?
|
75
|
+
return false unless ReactOnRails::Utils.running_on_windows? ? `where node`.blank? : `which node`.blank?
|
76
76
|
error = "** nodejs is required. Please install it before continuing. "
|
77
77
|
error << "https://nodejs.org/en/"
|
78
78
|
GeneratorMessages.add_error(error)
|
data/lib/react_on_rails/utils.rb
CHANGED
@@ -20,6 +20,10 @@ module ReactOnRails
|
|
20
20
|
ReactOnRails.configuration.server_bundle_js_file)
|
21
21
|
end
|
22
22
|
|
23
|
+
def self.running_on_windows?
|
24
|
+
(/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
|
25
|
+
end
|
26
|
+
|
23
27
|
module Required
|
24
28
|
def required(arg_name)
|
25
29
|
raise ArgumentError, "#{arg_name} is required"
|
data/package.json
CHANGED