react_on_rails 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +182 -56
  3. data/{LICENSE → docs/LICENSE} +0 -0
  4. data/docs/{gen-notes/reducers.md → additional_reading/generated_client_code.md} +5 -1
  5. data/docs/additional_reading/heroku_deployment.md +21 -0
  6. data/docs/{manual_configuration.md → additional_reading/manual_installation.md} +4 -63
  7. data/docs/{node_dependencies_and_npm.md → additional_reading/node_dependencies_and_npm.md} +0 -0
  8. data/docs/additional_reading/optional_configuration.md +34 -0
  9. data/docs/additional_reading/server_rendering_tips.md +16 -0
  10. data/docs/additional_reading/tips.md +10 -0
  11. data/{CODE_OF_CONDUCT.md → docs/code_of_conduct.md} +0 -0
  12. data/docs/{Contributing.md → contributing.md} +0 -0
  13. data/lib/generators/react_on_rails/base_generator.rb +35 -4
  14. data/lib/generators/react_on_rails/bootstrap_generator.rb +27 -7
  15. data/lib/generators/react_on_rails/generator_helper.rb +4 -2
  16. data/lib/generators/react_on_rails/install_generator.rb +13 -19
  17. data/lib/generators/react_on_rails/js_linters_generator.rb +19 -0
  18. data/lib/generators/react_on_rails/react_no_redux_generator.rb +7 -3
  19. data/lib/generators/react_on_rails/react_with_redux_generator.rb +6 -15
  20. data/lib/generators/react_on_rails/ruby_linters_generator.rb +33 -0
  21. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/globals.jsx.tt +5 -0
  22. data/lib/generators/react_on_rails/templates/{redux → base}/base/client/package.json.tt +23 -10
  23. data/lib/generators/react_on_rails/templates/base/base/client/server.js +8 -2
  24. data/lib/generators/react_on_rails/templates/base/base/client/{webpack.client.base.config.js → webpack.client.base.config.js.tt} +2 -1
  25. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +1 -3
  26. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake +1 -3
  27. data/lib/generators/react_on_rails/templates/{linters/lib/tasks/linters.rake → base/base/lib/tasks/linters.rake.tt} +36 -29
  28. data/lib/generators/react_on_rails/templates/{linters → js_linters}/client/.eslintignore +0 -0
  29. data/lib/generators/react_on_rails/templates/{linters → js_linters}/client/.eslintrc +0 -0
  30. data/lib/generators/react_on_rails/templates/{linters → js_linters}/client/.jscsrc +0 -0
  31. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +12 -0
  32. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx +2 -2
  33. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/{HelloWorldAppClient.jsx → HelloWorldAppClient.jsx.tt} +3 -2
  34. data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +1 -5
  35. data/lib/generators/react_on_rails/templates/ruby_linters/.rubocop.yml +26 -0
  36. data/lib/generators/react_on_rails/templates/ruby_linters/.scss-lint.yml +205 -0
  37. data/lib/generators/react_on_rails/templates/{linters → ruby_linters}/lib/tasks/brakeman.rake +0 -0
  38. data/lib/generators/react_on_rails/templates/{linters → ruby_linters}/lib/tasks/ci.rake +0 -0
  39. data/lib/generators/react_on_rails/templates/ruby_linters/ruby-lint.yml +20 -0
  40. data/lib/react_on_rails/version.rb +1 -1
  41. metadata +29 -24
  42. data/docs/gen-notes/react_syntax.md +0 -3
  43. data/docs/linters.md +0 -25
  44. data/lib/generators/react_on_rails/linters_generator.rb +0 -38
  45. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientGlobals.jsx +0 -4
  46. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx +0 -11
  47. data/lib/generators/react_on_rails/templates/no_redux/base/client/package.json.tt +0 -75
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3cafbd0b068b4be809103e6f043761aa5ca9dff1
4
- data.tar.gz: 4466dd647b9846dc792d8e3926a6819caf40f989
3
+ metadata.gz: c4ccd3d1c479a04e020fc78586ee67d7a576f30c
4
+ data.tar.gz: b460a6963c951e32e0553968c1e2bc0240c3e34a
5
5
  SHA512:
6
- metadata.gz: 827b09823116f3d03ddf43d2343f2cfa45aa18793011d4174ec3517c4777c49a331c35b4f4d6533e8b73040d9a18befa3f452a33e973925c08d3abf3e6c9b568
7
- data.tar.gz: d529ec20ac5c921231b64b0fe06201a78ff7671c2c27197ee3b93f735b5cccf810262550027f760135d776d0c4d8ba04066ca6a382a949ea5b1eeb61fd447e9e
6
+ metadata.gz: 9cee01638202876298db6523b2f194ee8d51f7aa225a3962d5d33d198a751e873cc1fc6d80466276de6826f15c792d2ada4c88168a04b80c3b2dd13ec3d30807
7
+ data.tar.gz: e59ecec3df7a937202157385a848a0d4394e179a488f7defb1bd303a16adcc5a4bb35e1193c4e602b2a14a5991807f4557b5cf4a447c7b2736aa3779dd53745b
data/README.md CHANGED
@@ -3,42 +3,91 @@
3
3
  # React on Rails
4
4
  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. 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
5
 
6
- Like the [react-rails](https://github.com/reactjs/react-rails) gem, React on Rails is capable of server-side rendering with fragment caching and is compatible with [turbolinks](https://github.com/rails/turbolinks). Unlike react-rails, which depends heavily on sprockets and jquery-ujs, React on Rails uses [webpack](http://webpack.github.io/) and does not depend on jQuery. While the initial setup is slightly more involved, it allows for advanced functionality such as:
7
-
8
- + [Redux](https://github.com/rackt/redux)
9
- + [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)
10
- + [Webpack optimization functionality](https://github.com/webpack/docs/wiki/optimization)
11
- + **(Coming Soon)** [React Router](https://github.com/rackt/react-router)
6
+ 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).
12
7
 
13
- See the [react-webpack-rails-tutorial](https://github.com/justin808/react-webpack-rails-tutorial/) for an example of a live implementation and code.
14
-
15
- ### Including your React Component in your Rails Views
8
+ ## Including your React Component in your Rails Views
16
9
  Please see [Getting Started](#getting-started) for how to set up your Rails project for React on Rails if you have not already done so.
17
10
 
18
- + *Normal Mode (JavaScript is rendered on client):*
11
+ + *Normal Mode (React component will be rendered on client):*
19
12
 
20
13
  ```erb
21
14
  <%= react_component("HelloWorldApp", @some_props) %>
22
15
  ```
23
- + *Server-Side Rendering:*
16
+ + *Server-Side Rendering (React component is first rendered into HTML on the server):*
24
17
 
25
18
  ```erb
26
19
  <%= react_component("HelloWorldApp", @some_props, prerender: true) %>
27
20
  ```
28
21
 
29
- + The `component_name` parameter here would be a string matching the name you used when globally exposing your React component.
30
- + `@some_props` can be either a hash or JSON string or {} if you have no props. This will make the data available in your component:
22
+ + 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 set `window.HelloWorldApp = HelloWorldApp` in your JavaScript. 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.
23
+ + `@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:
31
24
 
25
+ ```ruby
26
+ # Rails View
27
+ <%= react_component("HelloWorldApp", { name: "Stranger" })
28
+ ```
32
29
  ```javascript
33
- this.props.name
30
+ // inside your React component
31
+ this.props.name // "Stranger"
34
32
  ```
35
33
 
36
- ### Client-Side Rendering vs. Server-Side Rendering
37
- In most cases, you should use the provided helper method to render the React component from your Rails views with `prerender: false` (default behavior). In some cases, such as when SEO is vital or many users will not have JavaScript enabled, you can pass the `--server-rendering` option to the generator to configure your application for server-side rendering. Your JavaScript can then be first rendered on the server and passed to the client as HTML.
34
+ ## Documentation
35
+
36
+ + [Features](#features)
37
+ + [Why Webpack?](#why-webpack)
38
+ + [Getting Started](#getting-started)
39
+ + [How it Works](#how-it-works)
40
+ - [Client-Side Rendering vs. Server-Side Rendering](#client-side-rendering-vs-server-side-rendering)
41
+ - [Building the Bundles](#building-the-bundles)
42
+ - [Globally Exposing Your React Components](#globally-exposing-your-react-components)
43
+ - [Rails View Helpers In-Depth](#rails-view-helpers-in-depth)
44
+ + [Generator](#generator)
45
+ - [Understanding the Organization of the Generated Client Code](#understanding-the-organization-of-the-generated-client-code)
46
+ - [Redux](#redux)
47
+ - [Using Images and Fonts](#using-images-and-fonts)
48
+ - [Bootstrap Integration](#bootstrap-integration)
49
+ + [Bootstrap via Rails Server](#bootstrap-via-rails-server)
50
+ + [Bootstrap via Webpack HMR Dev Server](#bootstrap-via-webpack-hmr-dev-server)
51
+ + [Keeping Custom Bootstrap Configurations Synced](#keeping-custom-bootstrap-configurations-synced)
52
+ - [Linters](#linters)
53
+ + [JavaScript Linters](#javascript-linters)
54
+ + [Ruby Linters](#ruby-linters)
55
+ + [Running the Linters](#running-the-linters)
56
+ + [Developing with the Webpack Dev Server](#developing-with-the-webpack-dev-server)
57
+ + [Adding Additional Routes for the Dev Server](#adding-additional-routes-for-the-dev-server)
58
+ + [Additional Reading](#additional-reading)
59
+ + [Contributing](#contributing)
60
+ + [License](#license)
61
+ + [Authors](#authors)
62
+ + [About ShakaCode](#about-shakacode)
63
+
64
+ ---
65
+
66
+ ## Features
67
+ Like the [react-rails](https://github.com/reactjs/react-rails) gem, React on Rails is capable of server-side rendering with fragment caching and is compatible with [turbolinks](https://github.com/rails/turbolinks). Unlike react-rails, which depends heavily on sprockets and jquery-ujs, React on Rails uses [webpack](http://webpack.github.io/) and does not depend on jQuery. While the initial setup is slightly more involved, it allows for advanced functionality such as:
38
68
 
39
- In the following screenshot you can see the actual HTML rendered for a side-by-side comparison of a React component left as JavaScript for the client to render followed by the same component rendered on the server to HTML along with any console error messages generated:
69
+ + [Redux](https://github.com/rackt/redux)
70
+ + [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)
71
+ + [Webpack optimization functionality](https://github.com/webpack/docs/wiki/optimization)
72
+ + _*(Coming Soon)*_ [React Router](https://github.com/rackt/react-router)
73
+ + *([Gem *Pull Request*](https://github.com/shakacode/react_on_rails/pull/68))*
74
+ + *([Tutorial Pull Request](https://github.com/shakacode/react-webpack-rails-tutorial/pull/128))*
40
75
 
41
- ![Comparison of a normal React Component with its server-rendered version](https://cloud.githubusercontent.com/assets/1118459/10157268/41435186-6624-11e5-9341-6fc4cf35ee90.png)
76
+ See the [react-webpack-rails-tutorial](https://github.com/justin808/react-webpack-rails-tutorial/) for an example of a live implementation and code.
77
+
78
+ ## Why Webpack?
79
+
80
+ Webpack is used for 2 purposes:
81
+
82
+ 1. Generate several JavaScript "bundles" for inclusion in `application.js`.
83
+ 2. Providing the Webpack Dev Server for quick prototyping of components without needing to refresh your browser to see updates.
84
+
85
+ This usage of webpack fits neatly and simply into the existing Rails sprockets system and you can include React components on a Rails view with a simple helper.
86
+
87
+ Compare this to some alternative approaches for SPAs (Single Page Apps) that utilize Webpack and Rails. They will use a separate node server to distribute web pages, JavaScript assets, CSS, etc., and will still use Rails as an API server. A good example of this is our ShakaCode team member Alex's article [
88
+ Universal React with Rails: Part I](https://medium.com/@alexfedoseev/isomorphic-react-with-rails-part-i-440754e82a59).
89
+
90
+ We're definitely not doing that. With react_on_rails, webpack is mainly generating a nice JavaScript file for inclusion into `application.js`. We're going to KISS. And that's all relative given how much there is to get right in an enterprise class web application.
42
91
 
43
92
  ## Getting Started
44
93
  1. Add the following to your Gemfile and bundle install:
@@ -73,25 +122,80 @@ The generator installs your webpack files in the `client` folder. Foreman uses w
73
122
 
74
123
  Inside your Rails views, you can now use the `react_component` helper method provided by React on Rails.
75
124
 
125
+ ### Client-Side Rendering vs. Server-Side Rendering
126
+ In most cases, you should use the `prerender: false` (default behavior) with the provided helper method to render the React component from your Rails views. In some cases, such as when SEO is vital or many users will not have JavaScript enabled, you can enable server-rendering by passing `prerender: true` to your helper, or you can simply change the default in `config/initializers/react_on_rails`. Your JavaScript can then be first rendered on the server and passed to the client as HTML.
127
+
128
+ Note that **server-rendering requires globally exposing your components by setting them to `global`, not `window`** (as is the case with client-rendering). If using the generator, you can pass the `--server-rendering` option to configure your application for server-side rendering.
129
+
130
+ In the following screenshot you can see the 3 parts of react_on_rails rendering:
131
+
132
+ 1. Inline JavaScript to "client-side" render the React component.
133
+ 2. The wrapper div `<div id="HelloWorld-react-component-0">` enclosing the server-rendered HTML for the React component
134
+ 3. Additional JavaScript to console log any messages, such as server rendering errors.
135
+
136
+ **Note**: If server rendering is not used (prerender: false), then the major difference is that the HTML rendered contains *only* the outer div: `<div id="HelloWorld-react-component-0"/>`
137
+
138
+ ![Comparison of a normal React Component with its server-rendered version](https://cloud.githubusercontent.com/assets/1118459/10157268/41435186-6624-11e5-9341-6fc4cf35ee90.png)
139
+
76
140
  ### Building the Bundles
77
- Each time you change your client code, you will need to re-generate the bundles. The included Foreman `Procfile.dev` will take care of this for you by watching your JavaScript code files for changes. Simply run `foreman start -f Procfile.dev`.
141
+ Each time you change your client code, you will need to re-generate the bundles (the webpack-created JavaScript files included in application.js). The included Foreman `Procfile.dev` will take care of this for you by watching your JavaScript code files for changes. Simply run `foreman start -f Procfile.dev`.
142
+
143
+ On Heroku deploys, the `lib/assets.rake` file takes care of running webpack during deployment. If you have used the provided generator, these bundles will automatically be added to your `.gitignore` in order 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.
78
144
 
79
145
  ### Globally Exposing Your React Components
80
146
  Place your JavaScript code inside of the provided `client/app` folder. Use modules just as you would when using webpack alone. The difference here is that instead of mounting React components directly to an element using `React.render`, you **expose your components globally and then mount them with helpers inside of your Rails views**.
81
147
 
82
148
  + *Normal Mode (JavaScript is Rendered on client):*
83
-
149
+
150
+ If you are not server rendering, `clientGlobals.jsx` will have
151
+
84
152
  ```javascript
85
- window.HelloWorld = HelloWorldAppClient;
153
+ window.HelloWorldApp = HelloWorldApp;
86
154
  ```
87
155
  + *Server-Side Rendering:*
88
156
 
157
+ If you are server rendering, `globals.jsx` will have:
158
+
159
+ ```javascript
160
+ window.HelloWorldApp = HelloWorldAppClient;
161
+ ```
162
+
163
+ `serverGlobals.jsx` will have:
164
+
89
165
  ```javascript
90
- global.HelloWorld = HelloWorldAppServer;
166
+ global.HelloWorldApp = HelloWorldAppServer;
91
167
  ```
168
+
169
+ In general, you want different initialization for your server rendered components.
92
170
 
171
+ ### Rails View Helpers In-Depth
172
+ Once the bundled files have been generated in your `app/assets/javascripts/generated` folder and you have exposed your components globally, you will want to run your code in your Rails views using the included helper method.
173
+
174
+ This is how you actually render the React components you exposed to `window` inside of `clientGlobals` (and `global` inside of `serverGlobals` if you are server rendering).
175
+
176
+ #### react_component
177
+ `react_component(component_name, props = {}, options = {})`
178
+
179
+ + **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.
180
+ + **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.
181
+ + **options:**
182
+ + **generator_function:** default is false, set to true if you want to use a generator function rather than a React Component. Why would you do this? 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.
183
+ + **prerender:** enable server-side rendering of component. Set to false when debugging!
184
+ + **trace:** set to true to print additional debugging information in the browser. Defaults to true for development, off otherwise.
185
+ + **replay_console:** Default is true. False will disable echoing server-rendering logs to the browser. While this can make troubleshooting server rendering difficult, so long as you have the default configuration of logging_on_server set to true, you'll still see the errors on the server.
186
+ + Any other options are passed to the content tag, including the id
187
+
188
+ #### server_render_js
189
+ `server_render_js(js_expression, options = {})`
190
+
191
+ + js_expression, like 2 + 3, and not a block of js code. If you have more than one line that needs to be executed, wrap it in an [IIFE](https://en.wikipedia.org/wiki/Immediately-invoked_function_expression). JS exceptions will be caught and console messages handled properly
192
+ + Currently the only option you may pass is `replay_console` (boolean)
193
+
194
+ This is a helper method that takes any JavaScript expression and returns the output from evaluating it. If you have more than one line that needs to be executed, wrap it in an IIFE. JS exceptions will be caught and console messages handled properly.
195
+
196
+ ## Generator
197
+ 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.
93
198
 
94
- ## Generator Options
95
199
  Run `rails generate react_on_rails:install --help` for descriptions of all available options:
96
200
 
97
201
  ```
@@ -99,9 +203,10 @@ Usage:
99
203
  rails generate react_on_rails:install [options]
100
204
 
101
205
  Options:
102
- -R, [--redux], [--no-redux] # Setup Redux files
103
- -S, [--server-rendering], [--no-server-rendering] # Configure for server-side rendering of webpack JavaScript
104
- -L, [--skip-linters], [--no-skip-linters] # Don't install linter files
206
+ -R, [--redux], [--no-redux] # Install Redux gems and Redux version of Hello World Example
207
+ -S, [--server-rendering], [--no-server-rendering] # Add necessary files and configurations for server-side rendering
208
+ -j, [--skip-js-linters], [--no-skip-js-linters] # Skip installing JavaScript linting files
209
+ -L, [--ruby-linters], [--no-ruby-linters] # Install ruby linting files, tasks, and configs
105
210
 
106
211
  Runtime options:
107
212
  -f, [--force] # Overwrite files that already exist
@@ -113,7 +218,7 @@ Description:
113
218
  Create react on rails files for install generator.
114
219
  ```
115
220
 
116
- We have a repo showing the results of running the generator with various combinations of options, each combination on its own branch: [Generator Results](https://github.com/shakacode/react_on_rails-generator-results-pre-0/pulls).
221
+ 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-1-0-0/pulls). Each pull request shows a git "diff" that highlights the changes that the generator has made.
117
222
 
118
223
  ### Understanding the Organization of the Generated Client Code
119
224
  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.
@@ -126,11 +231,13 @@ Inside of the generated "HelloWorld" domain you will find the following folders:
126
231
 
127
232
  You may also notice the `app/lib` folder. This is for any code that is common between bundles and therefore needs to be shared (for example, middleware).
128
233
 
129
- #### Additional Redux Folders
130
- If you have used the `--redux` generator option, you will notice the familiar additional redux folders in addition to the aforementioned folders. In this organization paradigm, each bundle has its own store. We do not set a global store and then use partial stores based off of that. Again, this is for bundle code modularity and isolation. Note that if you want to reuse redux reducers across domains, then you will want to put the shared reducers under `/client/app/lib`.
234
+ ### Redux
235
+ If you have used the `--redux` generator option, you will notice the familiar additional redux folders in addition to the aforementioned folders. The Hello World example has also been modified to use Redux.
236
+
237
+ Note the organizational paradigm of "bundles". These are like application domains and are used for grouping your code into webpack bundles, in case you decide to create different bundles for deployment. This is also useful for separating out logical parts of your application. The concept is that each bundle will have it's own Redux store. If you have code that you want to reuse across bundles, including components and reducers, place them under `/client/app/lib`.
131
238
 
132
239
  ### Using Images and Fonts
133
- The generator has amended the folders created in `client/assets/` to Rails's asset path. We would that if you have any existing assets that you want to use with your client code that you should move them to these folders and use webpack as normal.
240
+ The generator has amended the folders created in `client/assets/` to Rails's asset path. We recommend that if you have any existing assets that you want to use with your client code, you should move them to these folders and use webpack as normal. This allows webpack's development server to have access to your assets, as it will not be able to see any assets in the default Rails directories which are above the `/client` directory.
134
241
 
135
242
  Alternatively, if you have many existing assets and don't wish to move them, you could consider creating symlinks from client/assets that point to your Rails assets folders inside of `app/assets/`. The assets there will then be visible to both Rails and webpack.
136
243
 
@@ -144,32 +251,48 @@ In the former case, the Rails server loads `bootstrap-sprockets`, provided by th
144
251
 
145
252
  This allows for using Bootstrap in your regular Rails stylesheets. If you wish to customize any of the Bootstrap variables, you can do so via the `client/assets/stylesheets/_pre-bootstrap.scss` partial.
146
253
 
147
- #### Bootstrap via Webpack HMR Dev Server
254
+ #### Bootstrap via Webpack Dev Server
148
255
  When using the webpack dev server, which does not go through Rails, bootstrap is loaded via the [bootstrap-sass-loader](https://github.com/shakacode/bootstrap-sass-loader) which uses the `client/bootstrap-sass-config.js` file.
149
256
 
150
257
  #### Keeping Custom Bootstrap Configurations Synced
151
- Because the HMR dev server and Rails each load Bootstrap via a different file (explained in the two sections immediately above), any changes to the way components are loaded in one file must also be made to the other file in order to keep styling consistent between the two. For example, if an import is excluded in `_bootstrap-custom.scss`, the same import should be excluded in `bootstrap-sass-config.js` so that styling in the Rails server and the webpack dev server will be the same.
258
+ Because the webpack dev server and Rails each load Bootstrap via a different file (explained in the two sections immediately above), any changes to the way components are loaded in one file must also be made to the other file in order to keep styling consistent between the two. For example, if an import is excluded in `_bootstrap-custom.scss`, the same import should be excluded in `bootstrap-sass-config.js` so that styling in the Rails server and the webpack dev server will be the same.
152
259
 
153
- ## Rails View Helpers In-Depth
154
- Once the bundled files have been generated in your `app/assets/javascripts/generated` folder and you have exposed your components globally, you will want to run your code in your Rails views using the included helper method.
260
+ ### Linters
261
+ The React on Rails generator can add linters and their recommended accompanying configurations to your project. There are two classes of linters: ruby linters and JavaScript linters.
155
262
 
156
- This is how you actually render the React components you exposed to `window` inside of `clientGlobals` (and `global` inside of `serverGlobals` if you are server rendering).
263
+ ##### JavaScript Linters
264
+ JavaScript linters are **enabled by default**, but can be disabled by passing the `--skip-js-linters` flag (alias `j`) , and those that run in Node have been add to `client/package.json` under `devDependencies`.
157
265
 
158
- `react_component(component_name, props = {}, options = {})`
159
- + **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.
160
- + **props:** Ruby Hash which contains the properties to pass to the react object
161
- + **options:**
162
- + **generator_function:** default is false, set to true if you want to use a generator function rather than a React Component.
163
- + **prerender:** enable server-side rendering of component. Set to false when debugging!
164
- + **trace:** set to true to print additional debugging information in the browser. Defaults to true for development, off otherwise.
165
- + **replay_console:** Default is true. False will disable echoing server-rendering logs to the browser. While this can make troubleshooting server rendering difficult, so long as you have the default configuration of logging_on_server set to true, you'll still see the errors on the server.
166
- + Any other options are passed to the content tag, including the id
266
+ ##### Ruby Linters
267
+ Ruby linters are **disabled by default**, but can be enabled by passing the `--ruby-linters` flag when generating. These linters have been added to your Gemfile in addition to the the appropriate Rake tasks.
167
268
 
168
- `def server_render_js(js_expression, options = {})`
269
+ We really love using all the linters! Give them a try.
169
270
 
170
- This is a helper method that takes any JavaScript expression and returns the output from evaluating it. If you have more than one line that needs to be executed, wrap it in an IIFE. JS exceptions will be caught and console messages handled properly.
271
+ #### Running the Linters
272
+ To run the linters (runs all linters you have installed, even if you installed both Ruby and Node):
273
+
274
+ ```bash
275
+ rake lint
276
+ ```
171
277
 
172
- ## Developing with Webpack Dev Server
278
+ Run this command to see all the linters available
279
+
280
+ ```bash
281
+ rake -T lint
282
+ ```
283
+
284
+ **Here's the list:**
285
+ ```bash
286
+ rake lint # Runs all linters
287
+ rake lint:eslint # eslint
288
+ rake lint:js # JS Linting
289
+ rake lint:jscs # jscs
290
+ rake lint:rubocop[fix] # Run Rubocop lint in shell
291
+ rake lint:ruby # Run ruby-lint as shell
292
+ rake lint:scss # See docs for task 'scss_lint'
293
+ ```
294
+
295
+ ## Developing with the Webpack Dev Server
173
296
  One of the benefits of using webpack is access to [webpack's dev server](https://webpack.github.io/docs/webpack-dev-server.html) and its [hot module replacement](https://webpack.github.io/docs/hot-module-replacement-with-webpack.html) functionality.
174
297
 
175
298
  The webpack dev server with HMR will apply changes from the code (or styles!) to the browser as soon as you save whatever file you're working on. You won't need to reload the page, and your data will still be there. Start foreman as normal (it boots up the Rails server *and* the webpack HMR dev server at the same time).
@@ -185,19 +308,22 @@ Note that **React-related error messages are typically significantly more helpfu
185
308
  ### Adding Additional Routes for the Dev Server
186
309
  As you add more routes to your front-end application, you will need to make the corresponding API for the dev server in `client/server.js`. See our example `server.js` from our [tutorial](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/server.js).
187
310
 
188
- ## Additional Documentation:
189
-
190
- + [Linters](docs/linters.md)
191
- + [Manual Configuration](docs/manual_configuration.md)
192
- + [Node Dependencies and NPM](docs/node_dependencies_and_npm.md)
311
+ ## Additional Reading
312
+ + [Generated Client Code](docs/additional_reading/generated_client_code.md)
313
+ + [Heroku Deployment](docs/additional_reading/heroku_deployment.md)
314
+ + [Manual Installation](docs/additional_reading/manual_installation.md)
315
+ + [Node Dependencies and NPM](docs/additional_reading/node_dependencies_and_npm.md)
316
+ + [Optional Configuration](docs/additional_reading/optional_configuration.md)
317
+ + [Server Rendering Tips](docs/additional_reading/server_rendering_tips.md)
318
+ + [Tips](docs/additional_reading/tips.md)
193
319
 
194
320
  ## Contributing
195
- Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to our version of the [Contributor Covenant](contributor-covenant.org) code of conduct (see [CODE OF CONDUCT](CODE_OF_CONDUCT.md)).
321
+ Bug reports and pull requests are welcome. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to our version of the [Contributor Covenant](contributor-covenant.org) code of conduct (see [CODE OF CONDUCT](docs/code_of_conduct.md)).
196
322
 
197
- See [Contributing](docs/Contributing.md) to get started.
323
+ See [Contributing](docs/contributing.md) to get started.
198
324
 
199
325
  ## License
200
- The gem is available as open source under the terms of the [MIT License](LICENSE).
326
+ The gem is available as open source under the terms of the [MIT License](docs/LICENSE).
201
327
 
202
328
  ## Authors
203
329
  [The Shaka Code team!](http://www.shakacode.com/about/)
@@ -214,7 +340,7 @@ And based on the work of the [react-rails gem](https://github.com/reactjs/react-
214
340
 
215
341
  ## About [ShakaCode](http://www.shakacode.com/)
216
342
 
217
- Visit [our forums!](http://forum.shakacode.com)
343
+ Visit [our forums!](http://forum.shakacode.com). We've got a [category dedicated to react_on_rails](http://forum.shakacode.com/c/rails/reactonrails).
218
344
 
219
345
  If you're looking for consulting on a project using React and Rails, email us ([contact@shakacode.com](mailto: contact@shakacode.com))! You can also join our slack room for some free advice.
220
346
 
File without changes
@@ -1,4 +1,8 @@
1
- # Reducers
1
+ # React Syntax
2
+ ## Communication Between Components
3
+ See https://facebook.github.io/react/tips/communicate-between-components.html
4
+
5
+ # Redux Reducers
2
6
  Documentation of generated Redux code for reducers.
3
7
 
4
8
  ## Example
@@ -0,0 +1,21 @@
1
+ # Heroku Deployment
2
+ The generator has created the necessary files and gems for deployment to Heroku. If you have installed manually, you will need to provide these files yourself:
3
+
4
+ + `Procfile`: used by Heroku and Foreman to start the server
5
+ + `.buildpacks`: used to install Ruby and Node environments
6
+ + `12factor` gem: required by Heroku
7
+ + `lib/tasks/assets.rake`: rake task that generates your JavaScript bundles for production.
8
+
9
+ ## How to Deploy
10
+
11
+ React on Rails requires both a ruby environment (for Rails) and a Node environment (for Webpack), so you will need to have Heroku use multiple buildpacks. Currently, we would suggest using [DDollar's Heroku Buildpack Multi](https://github.com/ddollar/heroku-buildpack-multi).
12
+
13
+ Assuming you have downloaded and installed the Heroku command-line utility and have initialized the app, you will need to tell Heroku to use Heroku Buildpack Multi via the command-line:
14
+
15
+ ```
16
+ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi
17
+ ```
18
+
19
+ Heroku will now be able to use the multiple buildpacks specified in `.buildpacks`.
20
+
21
+ Note, an alternative approach is to use the [Heroku Toolbelt to set buildpacks](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app).
@@ -1,4 +1,4 @@
1
- ## Manual Installation
1
+ # Manual Installation
2
2
  Follow these steps if you choose to forgo the generator:
3
3
 
4
4
  1. Globally expose React in your webpack config like [this](https://github.com/shakacode/react-webpack-rails-tutorial/blob/537c985dc82faee333d80509343ca32a3965f9dd/client/webpack.client.base.config.js#L31):
@@ -55,7 +55,7 @@ See the next section for a sample webpack.server.rails.config.js.
55
55
  { test: require.resolve('react-dom/server'), loader: 'expose?ReactDOMServer' }, // not in client one, only server
56
56
  ```
57
57
 
58
- #### Sample webpack.server.rails.config.js (ONLY for server rendering)
58
+ ### Sample webpack.server.rails.config.js (ONLY for server rendering)
59
59
  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).
60
60
 
61
61
  ```javascript
@@ -91,7 +91,7 @@ module.exports = {
91
91
  };
92
92
  ```
93
93
 
94
- ### What Happens?
94
+ ## What Happens?
95
95
 
96
96
  Here's what the browser will render with a call to the `react_component` helper.
97
97
  ![2015-09-28_20-24-35](https://cloud.githubusercontent.com/assets/1118459/10157268/41435186-6624-11e5-9341-6fc4cf35ee90.png)
@@ -112,7 +112,7 @@ Here's what the browser will render with a call to the `react_component` helper.
112
112
  * **replay_console**: <true/false> Default is true. False will disable echoing server rendering logs, which can make troubleshooting server rendering difficult.
113
113
  * Any other options are passed to the content tag, including the id.
114
114
 
115
- ## JavaScript
115
+ # JavaScript
116
116
 
117
117
  1. Configure your webpack configuration to create the file used for server rendering if you plan to do server rendering.
118
118
  2. Follow the examples in `spec/dummy/client/app/startup/clientGlobals.jsx` to expose your react components for client side rendering.
@@ -128,65 +128,6 @@ Here's what the browser will render with a call to the `react_component` helper.
128
128
  global.HelloWorld = HelloWorld;
129
129
  ```
130
130
 
131
- ## Server Rendering Tips
132
-
133
- - Your code can't reference `document`. Server side JS execution does not have access to `document`, so jQuery and some
134
- other libs won't work in this environment. You can debug this by putting in `console.log`
135
- statements in your code.
136
- - You can conditionally avoid running code that references document by passing in a boolean prop to your top level react
137
- component. Since the passed in props Hash from the view helper applies to client and server side code, the best way to
138
- do this is to use a generator function.
139
-
140
- You might do something like this in some file for your top level component:
141
- ```javascript
142
- global.App = () => <MyComponent serverSide={true} />;
143
- ```
144
-
145
- The point is that you have separate files for top level client or server side, and you pass some extra option indicating that rendering is happening server sie.
146
-
147
- ## Optional Configuration
148
-
149
- Create a file `config/react_on_rails.rb` to override any defaults. If you don't specify this file,
150
- the default options are below.
151
-
152
- The `server_bundle_js_file` must correspond to the bundle you want to use for server rendering.
153
-
154
- ```ruby
155
- # Shown below are the defaults for configuration
156
- ReactOnRails.configure do |config|
157
- # Client bundles are configured in application.js
158
- # Server bundle is a single file for all server rendering of components.
159
- # Set the server_bundle_js_file to "" if you know that you will not be server rendering.
160
- config.server_bundle_js_file = "app/assets/javascripts/generated/server.js" # This is the default
161
-
162
- # Below options can be overriden by passing to the helper method.
163
- config.prerender = false # default is false
164
- config.generator_function = false # default is false, meaning that you expose ReactComponents directly
165
- config.trace = Rails.env.development? # default is true for development, off otherwise
166
-
167
- # For server rendering. This can be set to false so that server side messages are discarded.
168
- config.replay_console = true # Default is true. Be cautious about turning this off.
169
- config.logging_on_server = true # Default is true. Logs server rendering messags to Rails.logger.info
170
-
171
- # Settings for the pool of renderers:
172
- config.server_renderer_pool_size ||= 1 # ExecJS doesn't allow more than one on MRI
173
- config.server_renderer_timeout ||= 20 # seconds
174
- end
175
- ```
176
-
177
- You can configure your pool of JS virtual machines and specify where it should load code:
178
-
179
- - On MRI, use `therubyracer` for the best performance (see [discussion](https://github.com/reactjs/react-rails/pull/290))
180
- - On MRI, you'll get a deadlock with `pool_size` > 1
181
- - If you're using JRuby, you can increase `pool_size` to have real multi-threaded rendering.
182
-
183
- ## Tips
184
- + **DO NOT RUN `rails s`** and instead run `foreman start -f Procfile.dev`
185
- + The default for rendering right now is `prerender: false`. **NOTE:** Server side rendering does not work for some components, namely react-router, that use an async setup for server rendering. You can configure the default for prerender in your config.
186
- + You can expose either a React component or a function that returns a React component. If you wish to create a React component via a function, rather than simply props, then you need to set the property "generator" on that function to true. When that is done, the function is invoked with a single parameter of "props", and that function should return a React element.
187
- + Be sure you can first render your react component client only before you try to debug server rendering!
188
- + Open up the HTML source and take a look at the generated HTML and the JavaScript to see what's going on under the covers. Note that when server rendering is turned on, then you'll see the server rendered react components. When server rendering is turned off, then you'll only see the `div` element where the in-line JavaScript will render the component. You might also notice how the props you pass (a Ruby Hash) becomes in-line JavaScript on the HTML page.
189
-
190
131
  ## React 0.13 vs. React 0.14
191
132
  The main difference for using react_on_rails is that you need to add additional lines in the webpack config files:
192
133