react_on_rails 2.0.0.beta.1 → 2.0.0.beta.2

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 (119) hide show
  1. checksums.yaml +4 -4
  2. data/.coveralls.yml +1 -0
  3. data/.dockerignore +2 -0
  4. data/.eslintignore +7 -0
  5. data/.eslintrc +19 -0
  6. data/.gitignore +28 -0
  7. data/.jscsrc +27 -0
  8. data/.npmignore +20 -0
  9. data/.rspec +2 -0
  10. data/.rubocop.yml +70 -0
  11. data/.scss-lint.yml +205 -0
  12. data/.travis.yml +43 -0
  13. data/CHANGELOG.md +34 -0
  14. data/Dockerfile_tests +12 -0
  15. data/Gemfile +40 -0
  16. data/README.md +365 -0
  17. data/Rakefile +5 -0
  18. data/app/helpers/react_on_rails_helper.rb +215 -0
  19. data/docker-compose.yml +11 -0
  20. data/docs/LICENSE +21 -0
  21. data/docs/additional_reading/heroku_deployment.md +23 -0
  22. data/docs/additional_reading/manual_installation.md +118 -0
  23. data/docs/additional_reading/node_dependencies_and_npm.md +29 -0
  24. data/docs/additional_reading/optional_configuration.md +33 -0
  25. data/docs/additional_reading/react-and-redux.md +36 -0
  26. data/docs/additional_reading/react_router.md +45 -0
  27. data/docs/additional_reading/server_rendering_tips.md +11 -0
  28. data/docs/additional_reading/tips.md +10 -0
  29. data/docs/additional_reading/webpack.md +46 -0
  30. data/docs/code_of_conduct.md +13 -0
  31. data/docs/coding-style/linters.md +64 -0
  32. data/docs/coding-style/style.md +42 -0
  33. data/docs/contributing.md +157 -0
  34. data/docs/generator_testing.md +20 -0
  35. data/docs/releasing.md +29 -0
  36. data/lib/generators/USAGE +99 -0
  37. data/lib/generators/react_on_rails/base_generator.rb +191 -0
  38. data/lib/generators/react_on_rails/bootstrap_generator.rb +89 -0
  39. data/lib/generators/react_on_rails/dev_tests_generator.rb +39 -0
  40. data/lib/generators/react_on_rails/generator_helper.rb +50 -0
  41. data/lib/generators/react_on_rails/heroku_deployment_generator.rb +30 -0
  42. data/lib/generators/react_on_rails/install_generator.rb +99 -0
  43. data/lib/generators/react_on_rails/js_linters_generator.rb +19 -0
  44. data/lib/generators/react_on_rails/react_no_redux_generator.rb +40 -0
  45. data/lib/generators/react_on_rails/react_with_redux_generator.rb +51 -0
  46. data/lib/generators/react_on_rails/ruby_linters_generator.rb +33 -0
  47. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +4 -0
  48. data/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md +16 -0
  49. data/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb +5 -0
  50. data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +4 -0
  51. data/lib/generators/react_on_rails/templates/base/base/client/.babelrc +3 -0
  52. data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +3 -0
  53. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/clientRegistration.jsx.tt +5 -0
  54. data/lib/generators/react_on_rails/templates/base/base/client/index.jade +15 -0
  55. data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +104 -0
  56. data/lib/generators/react_on_rails/templates/base/base/client/server.js +64 -0
  57. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js.tt +62 -0
  58. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js.tt +69 -0
  59. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js +42 -0
  60. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +26 -0
  61. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt +26 -0
  62. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/linters.rake.tt +88 -0
  63. data/lib/generators/react_on_rails/templates/base/base/package.json +31 -0
  64. data/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx +4 -0
  65. data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +39 -0
  66. data/lib/generators/react_on_rails/templates/bootstrap/app/assets/stylesheets/_bootstrap-custom.scss +63 -0
  67. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_post-bootstrap.scss +10 -0
  68. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_pre-bootstrap.scss +8 -0
  69. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_react-on-rails-sass-helper.scss +19 -0
  70. data/lib/generators/react_on_rails/templates/bootstrap/client/bootstrap-sass.config.js +89 -0
  71. data/lib/generators/react_on_rails/templates/dev_tests/.rspec +2 -0
  72. data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +25 -0
  73. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +57 -0
  74. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +21 -0
  75. data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +95 -0
  76. data/lib/generators/react_on_rails/templates/heroku_deployment/.buildpacks +2 -0
  77. data/lib/generators/react_on_rails/templates/heroku_deployment/Procfile +1 -0
  78. data/lib/generators/react_on_rails/templates/heroku_deployment/config/puma.rb +15 -0
  79. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintignore +1 -0
  80. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintrc +48 -0
  81. data/lib/generators/react_on_rails/templates/js_linters/client/.jscsrc +18 -0
  82. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +39 -0
  83. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +33 -0
  84. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +8 -0
  85. data/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +8 -0
  86. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx +8 -0
  87. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +48 -0
  88. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx +8 -0
  89. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +43 -0
  90. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx +19 -0
  91. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx +14 -0
  92. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +19 -0
  93. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +35 -0
  94. data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +20 -0
  95. data/lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +19 -0
  96. data/lib/generators/react_on_rails/templates/ruby_linters/.rubocop.yml +26 -0
  97. data/lib/generators/react_on_rails/templates/ruby_linters/.scss-lint.yml +205 -0
  98. data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/brakeman.rake +17 -0
  99. data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/ci.rake +33 -0
  100. data/lib/generators/react_on_rails/templates/ruby_linters/ruby-lint.yml +20 -0
  101. data/lib/react_on_rails.rb +6 -0
  102. data/lib/react_on_rails/configuration.rb +60 -0
  103. data/lib/react_on_rails/engine.rb +7 -0
  104. data/lib/react_on_rails/prerender_error.rb +31 -0
  105. data/lib/react_on_rails/server_rendering_pool.rb +110 -0
  106. data/lib/react_on_rails/version.rb +3 -0
  107. data/package.json +76 -0
  108. data/rakelib/docker.rake +33 -0
  109. data/rakelib/dummy_apps.rake +20 -0
  110. data/rakelib/example_type.rb +160 -0
  111. data/rakelib/examples.rake +103 -0
  112. data/rakelib/examples_config.yml +19 -0
  113. data/rakelib/lint.rake +37 -0
  114. data/rakelib/node_package.rake +11 -0
  115. data/rakelib/run_rspec.rake +65 -0
  116. data/rakelib/task_helpers.rb +44 -0
  117. data/react_on_rails.gemspec +31 -0
  118. data/ruby-lint.yml +24 -0
  119. metadata +119 -2
@@ -0,0 +1,36 @@
1
+ # Communication between React Components and Redux Reducers
2
+
3
+ ## Communication Between Components
4
+ See https://facebook.github.io/react/tips/communicate-between-components.html
5
+
6
+ # Redux Reducers
7
+ Documentation of generated Redux code for reducers.
8
+
9
+ ## Example
10
+ The `helloWorld/reducers/index.jsx` example that results from running the generator with the Redux option may be slightly confusing because of its simplicity. For clarity, what follows is a more fleshed-out example of what a reducer might look like:
11
+
12
+ ```javascript
13
+ import usersReducer from './usersReducer';
14
+ import blogPostsReducer from './blogPostsReducer';
15
+ import commentsReducer from './commentsReducer';
16
+ // ...
17
+
18
+ import { $$initialState as $$usersState } from './usersReducer';
19
+ import { $$initialState as $$blogPostsState } from './blogPostsReducer';
20
+ import { $$initialState as $$commentsState } from './commentsReducer';
21
+ // ...
22
+
23
+ export default {
24
+ $$usersStore: usersReducer,
25
+ $$blogPostsStore: blogPostsReducer,
26
+ $$commentsStore: commentsReducer,
27
+ // ...
28
+ };
29
+
30
+ export const initalStates = {
31
+ $$usersState,
32
+ $$blogPostsState,
33
+ $$commentsState,
34
+ // ...
35
+ };
36
+ ```
@@ -0,0 +1,45 @@
1
+ # Using React Router
2
+ React on Rails supports the use of React Router. Client-side code doesn't need any special configuration for the React on Rails gem. Implement React Router how you normally would.
3
+
4
+ However, when attempting to use server-rendering, it is necessary to take steps that prevent rendering when there is a router error or redirect. In these cases, the client code should return an object containing the `error` and a `redirectLocation` instead of the React component. The `react_component` helper method in your Rails view will automatically detect that there was an error/redirect and handle it accordingly.
5
+
6
+ If you are working with the HelloWorldApp created by the react_on_rails generator, then the code below corresponds to the module in `client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx`.
7
+
8
+ ```js
9
+ const RouterApp = (props, location) => {
10
+ const store = createStore(props);
11
+
12
+ let error;
13
+ let redirectLocation;
14
+ let routeProps;
15
+
16
+ // See https://github.com/rackt/react-router/blob/master/docs/guides/advanced/ServerRendering.md
17
+ match({ routes, location }, (_error, _redirectLocation, _routeProps) => {
18
+ error = _error;
19
+ redirectLocation = _redirectLocation;
20
+ routeProps = _routeProps;
21
+ });
22
+
23
+ // This tell react_on_rails to skip server rendering any HTML. Note, client rendering
24
+ // will handle the redirect. What's key is that we don't try to render.
25
+ // Critical to return the Object properties to match this { error, redirectLocation }
26
+ if (error || redirectLocation) {
27
+ return { error, redirectLocation };
28
+ }
29
+
30
+ // Important that you don't do this if you are redirecting or have an error.
31
+ return (
32
+ <Provider store={store}>
33
+ <RoutingContext {...routeProps} />
34
+ </Provider>
35
+ );
36
+ };
37
+ ```
38
+
39
+ For a fleshed out integration of react_on_rails with react-router, check out [React Webpack Rails Tutorial Code](https://github.com/shakacode/react-webpack-rails-tutorial), specifically the files:
40
+
41
+ * [react-webpack-rails-tutorial/client/app/bundles/comments/routes/routes.jsx](https://github.com/shakacode/react-webpack-rails-tutorial/blob/master/client/app/bundles/comments/routes/routes.jsx)
42
+
43
+ * [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)
44
+
45
+ * [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)
@@ -0,0 +1,11 @@
1
+ # Server Rendering Tips
2
+
3
+ - Your code can't reference `document`. Server side JS execution does not have access to `document`, so jQuery and some
4
+ other libs won't work in this environment. You can debug this by putting in `console.log`
5
+ statements in your code.
6
+ - You can conditionally avoid running code that references document by passing in a boolean prop to your top level react
7
+ component. Since the passed in props Hash from the view helper applies to client and server side code, the best way to
8
+ do this is to use a generator function.
9
+ - If you're serious about server rendering, it's worth the effort to have different entry points for client and server rendering. It's worth the extra complexity.
10
+
11
+ 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.
@@ -0,0 +1,10 @@
1
+ # Tips
2
+ + **DO NOT RUN `rails s`** and instead run
3
+
4
+ `foreman start -f Procfile.dev`
5
+
6
+ to automatically start the webpack file watchers that will regenerate your JavaScript. Note, RSpec does not automatically rebuild the bundle files, so you could get incorrect results from your tests if you change the client code and do not rebuild the bundles. The same problem occurs when pulling down changes from GitHub and running tests without first rebuilding the bundles.
7
+ + The default for rendering right now is `prerender: false`. **NOTE:** Server side rendering does not work for some components that use an async setup for server rendering. You can configure the default for prerender in your config.
8
+ + 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 helper invocation to true (or change the defaults). When that is done, the function is invoked with a single parameter of "props", and that function should return a React element.
9
+ + Be sure you can first render your react component **client only** before you try to debug server rendering!
10
+ + 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.
@@ -0,0 +1,46 @@
1
+ # Entry Points and Globally Exposing Objects
2
+
3
+ You should ensure you configure the entry points correctly for webpack.
4
+
5
+ ## When using React 0.14 and greater
6
+
7
+ You need both include `react-dom/server` and `react` as values for `entry`, like this:
8
+
9
+ ```
10
+ entry: {
11
+
12
+ // See use of 'vendor' in the CommonsChunkPlugin inclusion below.
13
+ vendor: [
14
+ 'babel-core/polyfill',
15
+ 'jquery',
16
+ 'jquery-ujs',
17
+ 'react',
18
+ 'react-dom',
19
+ ],
20
+ ```
21
+
22
+ and you need to expose them:
23
+
24
+ ```
25
+ // React is necessary for the client rendering:
26
+ {test: require.resolve('react'), loader: 'expose?React'},
27
+ {test: require.resolve('react-dom'), loader: 'expose?ReactDOM'},
28
+ {test: require.resolve('jquery'), loader: 'expose?jQuery'},
29
+ {test: require.resolve('jquery'), loader: 'expose?$'},
30
+ ```
31
+
32
+ `webpack.server.config.js` is similar, but substitute:
33
+
34
+ ```
35
+ entry: ['./yourCode', 'react-dom/server', 'react'],
36
+ ```
37
+
38
+ and use this line rather than `{test: require.resolve('react-dom'), loader: 'expose?ReactDOM'},`:
39
+
40
+ ```
41
+ {test: require.resolve('react-dom/server'), loader: 'expose?ReactDOMServer'},
42
+ ```
43
+
44
+ ## When you use React 0.13
45
+
46
+ You don't need to put in react-dom.
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
@@ -0,0 +1,64 @@
1
+ # Linters
2
+ These linters support the [ShakaCode Style Guidelines](./style.md)
3
+
4
+ ## Autofix!
5
+
6
+ If you haven't tried the autofix options for `jscs` and `rubocop`, you're seriously missing out!
7
+
8
+ 1. Be **SURE** you have a clean git status, as you'll want to review what the autofix does to your code!
9
+ 2. **Rubocop:** Be sure to be in the right directory where you have Ruby files, probably the top level of your Rails project.
10
+ ```
11
+ rubocop -a
12
+ ```
13
+
14
+ 3. **JSCS:**: Be sure to be in the right directory where you have JS files.
15
+ ```
16
+ jscs -x .
17
+ ```
18
+
19
+ Autofixing is a **HUGE** time saver!
20
+
21
+ ## ESLint
22
+
23
+ ### Configuring Rules
24
+
25
+ Rules are configured with a 0, 1 or 2. Setting a rule to 0 is turning it off, setting it to 1 triggers a warning if that rule is violated, and setting it to 2 triggers an error.
26
+
27
+ Rules can also take a few additional options. In this case, the rule can be set to an array, the first item of which is the 0/1/2 flag and the rest are options.
28
+
29
+ See file [.eslintrc](../../client/.eslintrc) for examples of configuration
30
+
31
+ ### Specify/Override rules in code
32
+
33
+ Rules can also be specified in the code file to be linted, as JavaScript comments. This can be useful when the rule is a one-off or is a override to a project-wide rule.
34
+
35
+ For example, if your file assumes a few globals and you have the no-undef rule set in the .eslintrc file, you might want to relax the rule in the current file.
36
+
37
+ ```
38
+ /* global $, window, angular */
39
+ // rest of code
40
+ ```
41
+
42
+ It's also useful to disable ESLint for particular lines or blocks of lines.
43
+
44
+ ```
45
+ console.log('console.log not allowed'); // eslint-disable-line
46
+
47
+ alert('alert not allowed'); // eslint-disable-line no-alert
48
+
49
+ /* eslint-disable no-console, no-alert */
50
+ console.log('more console.log');
51
+ alert('more alert');
52
+ /* eslint-enable no-console, no-alert */
53
+ ```
54
+
55
+ You can disable all rules for a line or block, or only specific rules, as shown above.
56
+
57
+ ### Useful Reference Links
58
+
59
+ * [Configuring ESLint](http://eslint.org/docs/user-guide/configuring.html#configuring-rules)
60
+ * [ESLint quick start](http://untilfalse.com/eslint-quick-start/)
61
+ * [RuboCop][https://github.com/bbatsov/rubocop]
62
+ * [ESLint][http://eslint.org/]
63
+ * [JSCS][https://github.com/jscs-dev/node-jscs]
64
+
@@ -0,0 +1,42 @@
1
+ # Code Style
2
+ This document describes the coding style of [ShakaCode](http://www.shakacode.com). Yes, it's opinionated, as all style guidelines should be. We shall put as little as possible into this guide and instead rely on:
3
+
4
+ * Use of linters with our standard linter configuration.
5
+ * References to existing style guidelines that support the linter configuration.
6
+ * Anything additional goes next.
7
+
8
+ ## Client Side JavaScript and React
9
+ * Use [Redux](https://github.com/rackt/redux) for your flux store.
10
+ * Use [Lodash](https://lodash.com/) rather than Underscore.
11
+ * Place all JavaScript for the client app in `/client`
12
+ * Organize your app into high level domains which map to JavaScript bundles. These are like mini-apps that live within your entire app. Create directories named like `/client/app/<bundle>` and configure Webpack to generate different corresponding bundles.
13
+ * Carefully organize your React components into [Smart and Dumb Components](https://medium.com/@dan_abramov/smart-and-dumb-components-7ca2f9a7c7d0#.ygdkh1l7b):
14
+ 1. "dumb" components that live in the `/client/app/<bundle>/components/` directories. These components should take props, including values and callbacks, and should not talk directly to Redux or any AJAX endpoints.
15
+ 2. "smart" components that live in the `/client/app/<bundle>/containers/` directory. These components will talk to the Redux store and AJAX endpoints.
16
+ * Place common code shared across bundles in `/client/app/libs` and configure Webpack to generate a common bundle for this one.
17
+ * Prefix Immutable.js variable names and properties with `$$`. By doing this, you will clearly know that you are dealing with an Immutable.js object and not a standard JavaScript Object or Array.
18
+ * Use ES6 classes rather than `React.createClass`.
19
+ * Bind callbacks passed to react components with `_.bindAll` in the constructor unless you need to bind additional parameters. In that case, you can call `_.bind` within the rendering.
20
+
21
+ ## Style Guides to Follow
22
+ Follow these style guidelines per the linter configuration. Basically, lint your code and if you have questions about the suggested fixes, look here:
23
+
24
+ ### Ruby Coding Standards
25
+ * [RailsOnMaui Ruby Coding Standards](https://github.com/justin808/ruby)
26
+ * [Ruby Documentation](http://guides.rubyonrails.org/api_documentation_guidelines.html)
27
+
28
+ ### JavaScript Coding Standards
29
+ * [AirBnb Javascript](https://github.com/airbnb/javascript)
30
+ * [JSDoc](http://usejsdoc.org/)
31
+
32
+ ### Git coding Standards
33
+ * [Git Coding Standards](http://chlg.co/1GV2m9p)
34
+
35
+ ### Sass Coding Standards
36
+ * [Sass Guidelines](http://sass-guidelin.es/) by [Hugo Giraudel](http://hugogiraudel.com/)
37
+ * [Github Front End Guidelines](http://primercss.io/guidelines/)
38
+
39
+ # Git Usage
40
+ * Follow a github-flow model where you branch off of master for features.
41
+ * Before merging a branch to master, rebase it on top of master, by using command like `git fetch; git checkout my-branch; git rebase -i origin/master`. Clean up your commit message at this point. Be super careful to communicate with anybody else working on this branch and do not do this when others have uncommitted changes. Ideally, your merge of your feature back to master should be one nice commit.
42
+ * Run hosted CI and code coverage.
@@ -0,0 +1,157 @@
1
+ # Tips for Contributors
2
+ *See [Releasing](../releasing.md) for instructions on releasing.*
3
+
4
+ # IDE/IDE SETUP
5
+ It's critical to configure your IDE/editor to ignore certain directories. Otherwise your IDE might slow to a crawl!
6
+
7
+ * /coverage
8
+ * /examples
9
+ * /node_package/lib
10
+ * /node_modules
11
+ * /spec/dummy/app/assets/javascripts/generated
12
+ * /spec/dummy/log
13
+ * /spec/dummy/node_modules
14
+ * /spec/dummy/tmp
15
+ * /spec/react_on_rails/dummy-for-generators
16
+
17
+ # Configuring your test app to use your local fork
18
+
19
+ ## Ruby Gem
20
+ If you want to test the gem with an application before you release a new version of the gem, you can specify the path to your local version via your test app's Gemfile:
21
+
22
+ ```ruby
23
+ gem "react_on_rails", path: "../path-to-react-on-rails"
24
+ ```
25
+
26
+ Note that you will need to bundle install after making this change, but also that **you will need to restart your Rails application if you make any changes to the gem**.
27
+
28
+ ## NPM for react-on-rails
29
+ First, be **sure** to build the NPM package
30
+
31
+ npm i
32
+ npm run build
33
+
34
+ Use either npm-link (described below), or use a relative path in your `package.json`, like this:
35
+
36
+ ```js
37
+ "react-on-rails": "../path-to-react-on-rails".
38
+ ```
39
+
40
+ If you use a relative path, be sure to run `npm i` whenever you rebuild the node package.
41
+
42
+
43
+ # Development Setup for Gem and Node Package Contributors
44
+
45
+ ## Checklist before Committing
46
+ 1. `rake`: runs all linters and specs (you need Docker setup, see below)
47
+ 2. Did you need any more tests for your change?
48
+ 3. Did you document your change? Update the README.md?
49
+
50
+ ## Dev Initial Setup
51
+
52
+ ### Prereqs
53
+ After checking out the repo, making sure you have rvm and nvm setup (setup ruby and node), cd to `spec/dummy` and run `bin/setup` to install ruby dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
54
+
55
+ ### Npm link
56
+
57
+ By the following steps, the node package code of react-on-rails is directly coming from `node_package/lib`
58
+
59
+ ```sh
60
+ cd <top level>
61
+ npm link
62
+ cd spec/dummy/client
63
+ npm link react-on-rails
64
+ ```
65
+
66
+ *Side note: It's critical to use the alias section of the webpack config to avoid the double inclusion error:*
67
+
68
+ ```js
69
+ resolve: {
70
+ alias: {
71
+ react: path.resolve('./node_modules/react'),
72
+ },
73
+ },
74
+ ```
75
+
76
+ ### Install npm dependencies and build the npm package for react-on-rails
77
+
78
+ ```sh
79
+ cd <top level>
80
+ npm i
81
+ npm run build
82
+ cd spec/dummy
83
+ npm i
84
+ ```
85
+
86
+ ### Run npm JS tests
87
+
88
+ ```sh
89
+ cd <top level>
90
+ npm test
91
+ ```
92
+
93
+ ### Run spec/dummy tests
94
+
95
+ ```sh
96
+ cd spec/dummy
97
+ npm run test
98
+ ```
99
+
100
+ ### Run most tests and linting
101
+
102
+ ```
103
+ cd <top level>
104
+ node_package/scripts/ci
105
+ ```
106
+
107
+
108
+ ### Starting the Dummy App
109
+ To run the test app, it's **CRITICAL** to not just run `rails s`. You have to run `foreman start`. If you don't do this, then `webpack` will not generate a new bundle, and you will be seriously confused when you change JavaScript and the app does not change. If you change the webpack configs, then you need to restart foreman. If you change the JS code for react-on-rails, you need to run `node_package/scripts/build`. Since the react-on-rails package should be sym linked, you don't have to `npm i react-on-rails` after every change.
110
+
111
+ ### RSpec Testing
112
+ Run `rake` for testing the gem and `spec/dummy`. Otherwise, the `rspec` command only works for testing within the sample apps, like `spec/dummy`.
113
+
114
+ If you run `rspec` at the top level, you'll see this message: `require': cannot load such file -- rails_helper (LoadError)`
115
+
116
+ After running a test, you can view the coverage results SimpleCov reports by opening `coverage/index.html`.
117
+
118
+ ### Debugging
119
+ Start the sample app like this for some debug printing:
120
+
121
+ ```bash
122
+ TRACE_REACT_ON_RAILS=true && foreman start
123
+ ```
124
+
125
+ ### Install Generator
126
+ In your Rails app add this gem with a path to your fork.
127
+
128
+ ```
129
+ gem 'react_on_rails', path: '../relative/path/to/react_on_rails'
130
+ ```
131
+
132
+ The main installer can be run with ```rails generate react_on_rails:install```
133
+
134
+ ### Testing the Generator
135
+ The generators are covered by generator tests using Rails's generator testing helpers, but it never hurts to do a sanity check and explore the API. See [generator_testing_script.md](generator_testing_script.md) for a script on how to run the generator on a fresh project.
136
+
137
+ ### Linting
138
+ All linting is performed from the docker container for CI. You will need docker and docker-compose installed locally to lint code changes via the lint container. You can lint locally by running `node_package/scripts/lint`
139
+
140
+ * [Install Docker Toolbox for Mac](https://www.docker.com/toolbox)
141
+ * [Install Docker Compose for Linux](https://docs.docker.com/compose/install/)
142
+
143
+ Once you have docker and docker-compose running locally, run `docker-compose build lint`. This will build the `reactonrails_lint` docker image and docker-compose `lint` container. The initial build is slow, but after the install, startup is very quick.
144
+
145
+ ### Linting Commands
146
+ Run `rake -D docker` to see all docker linting commands for rake. `rake docker:lint` will run all linters. For individual rake linting commands please refer to `rake -D docker` for the list.
147
+
148
+ You can run specific linting for directories or files by using `docker-compose run lint rubocop (file path or directory)`, etc.
149
+
150
+ `docker-compose run lint bash` sets you up to run from the container command line.
151
+
152
+ ### Docker CI - Test and Linting
153
+ Docker CI and Tests containers have a xvfd server automatically started for headless browser testing with selenium and Firefox.
154
+
155
+ Run `docker-compose build ci` to build the CI container. Run `docker-compose run ci` to start all rspec tests and linting. `docker-compose run --entrypoint=/bin/bash` will override the default CI action and place you inside the CI container in a bash session. This is what is run on Travis-CI.
156
+
157
+ Run `docker-compose build tests` to build the tests container. Run `docker-compose run tests` to start all rspec tests.
@@ -0,0 +1,20 @@
1
+ # Generator Testing
2
+ We create several applications that are examples of running the generator (see lib/generators/react_on_rails/install_generator.rb) with various different options. We can then run tests with these apps just like we would any Rails app and thus ensure that our generator makes apps that actually function properly.
3
+
4
+ Special rake tasks in rakelib/examples.rake handle creating the example apps and running a special hidden generator (lib/generators/react_on_rails/dev_tests_generator.rb) that installs the tests we want to run for each app. These tests can be run manually like any Rails app, or they can be run via the `rake run_rspec:examples` command. There are also commands for running each app individually, i.e., `rake run_rspec:example_basic`.
5
+
6
+ ## Travis and Gemfiles
7
+ We are currently using Travis for CI. Because of the way Travis works, it is not possible to `bundle install` multiple Gemfiles. Therefore, we have placed all dependencies for generated apps in the gem's main Gemfile. If you generate an app that has a new gem dependency in its Gemfile, you need to add that dependency to the main Gemfile or it will not work in CI.
8
+
9
+ ## Configuring what Apps are Generated
10
+ You can specify additional apps to generate and test by adding to the rakelib/examples_config.yml file. The necessary build and test tasks will automatically be created for you dynamically at runtime.
11
+
12
+ ## More on the Rake Tasks
13
+ In order to maximize efficiency, we took several steps to improve the performance of the rake tasks that utilize somewhat advanced rake functionality such as task dependencies, `file` tasks, task synthesizing, and concurrent tasks with `multitask`.
14
+
15
+ For example, re-generating the app, running `npm install`, and re-generating the webpack bundles are all only done when they need to be done. Rake will also run certain tasks, including those that generate multiple applications, concurrently. When running `npm install`, this may produce strange-looking output due to the way the npm's console progress bar works. This is normal.
16
+
17
+ For more insight, see:
18
+
19
+ - [Avdi Grimm's series of articles on Rake](http://devblog.avdi.org/2014/04/30/learn-advanced-rake-in-7-episodes/)
20
+ - [Martin Fowler's rake article](http://martinfowler.com/articles/rake.html)