react_on_rails 1.2.2 → 2.0.0.beta.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (123) hide show
  1. checksums.yaml +4 -4
  2. metadata +5 -126
  3. data/.babelrc +0 -3
  4. data/.coveralls.yml +0 -1
  5. data/.dockerignore +0 -2
  6. data/.eslintignore +0 -5
  7. data/.eslintrc +0 -48
  8. data/.gitignore +0 -26
  9. data/.jscsrc +0 -26
  10. data/.rspec +0 -2
  11. data/.rubocop.yml +0 -70
  12. data/.scss-lint.yml +0 -205
  13. data/.travis.yml +0 -41
  14. data/CHANGELOG.md +0 -42
  15. data/Dockerfile_tests +0 -12
  16. data/Gemfile +0 -38
  17. data/README.md +0 -363
  18. data/Rakefile +0 -5
  19. data/app/assets/javascripts/react_on_rails.js +0 -241
  20. data/app/helpers/react_on_rails_helper.rb +0 -224
  21. data/docker-compose.yml +0 -11
  22. data/docs/LICENSE +0 -21
  23. data/docs/additional_reading/heroku_deployment.md +0 -23
  24. data/docs/additional_reading/manual_installation.md +0 -142
  25. data/docs/additional_reading/node_dependencies_and_npm.md +0 -29
  26. data/docs/additional_reading/optional_configuration.md +0 -34
  27. data/docs/additional_reading/react-and-redux.md +0 -36
  28. data/docs/additional_reading/react_router.md +0 -45
  29. data/docs/additional_reading/server_rendering_tips.md +0 -16
  30. data/docs/additional_reading/tips.md +0 -10
  31. data/docs/additional_reading/webpack.md +0 -46
  32. data/docs/code_of_conduct.md +0 -13
  33. data/docs/coding-style/linters.md +0 -64
  34. data/docs/coding-style/style.md +0 -42
  35. data/docs/contributing.md +0 -62
  36. data/docs/generator_testing.md +0 -20
  37. data/docs/install_and_releasing.md +0 -24
  38. data/docs/sample_generated_js/README.md +0 -4
  39. data/docs/sample_generated_js/client-generated.js +0 -12
  40. data/docs/sample_generated_js/server-generated.js +0 -25
  41. data/lib/generators/USAGE +0 -99
  42. data/lib/generators/react_on_rails/base_generator.rb +0 -198
  43. data/lib/generators/react_on_rails/bootstrap_generator.rb +0 -91
  44. data/lib/generators/react_on_rails/dev_tests_generator.rb +0 -30
  45. data/lib/generators/react_on_rails/generator_errors.rb +0 -15
  46. data/lib/generators/react_on_rails/generator_helper.rb +0 -58
  47. data/lib/generators/react_on_rails/heroku_deployment_generator.rb +0 -30
  48. data/lib/generators/react_on_rails/install_generator.rb +0 -111
  49. data/lib/generators/react_on_rails/js_linters_generator.rb +0 -19
  50. data/lib/generators/react_on_rails/react_no_redux_generator.rb +0 -41
  51. data/lib/generators/react_on_rails/react_with_redux_generator.rb +0 -52
  52. data/lib/generators/react_on_rails/ruby_linters_generator.rb +0 -33
  53. data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +0 -4
  54. data/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md +0 -16
  55. data/lib/generators/react_on_rails/templates/base/base/app/controllers/hello_world_controller.rb +0 -5
  56. data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +0 -5
  57. data/lib/generators/react_on_rails/templates/base/base/client/.babelrc +0 -3
  58. data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +0 -3
  59. data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/startup/globals.jsx.tt +0 -5
  60. data/lib/generators/react_on_rails/templates/base/base/client/index.jade +0 -15
  61. data/lib/generators/react_on_rails/templates/base/base/client/npm-shrinkwrap.json +0 -2907
  62. data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +0 -98
  63. data/lib/generators/react_on_rails/templates/base/base/client/server.js +0 -64
  64. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js.tt +0 -67
  65. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.hot.config.js.tt +0 -67
  66. data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js +0 -41
  67. data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb +0 -28
  68. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt +0 -26
  69. data/lib/generators/react_on_rails/templates/base/base/lib/tasks/linters.rake.tt +0 -88
  70. data/lib/generators/react_on_rails/templates/base/base/package.json +0 -31
  71. data/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverGlobals.jsx +0 -3
  72. data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +0 -40
  73. data/lib/generators/react_on_rails/templates/bootstrap/app/assets/stylesheets/_bootstrap-custom.scss +0 -63
  74. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_post-bootstrap.scss +0 -10
  75. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_pre-bootstrap.scss +0 -8
  76. data/lib/generators/react_on_rails/templates/bootstrap/client/assets/stylesheets/_react-on-rails-sass-helper.scss +0 -19
  77. data/lib/generators/react_on_rails/templates/bootstrap/client/bootstrap-sass.config.js +0 -89
  78. data/lib/generators/react_on_rails/templates/dev_tests/.rspec +0 -2
  79. data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +0 -25
  80. data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +0 -57
  81. data/lib/generators/react_on_rails/templates/dev_tests/spec/simplecov_helper.rb +0 -21
  82. data/lib/generators/react_on_rails/templates/dev_tests/spec/spec_helper.rb +0 -95
  83. data/lib/generators/react_on_rails/templates/heroku_deployment/.buildpacks +0 -2
  84. data/lib/generators/react_on_rails/templates/heroku_deployment/Procfile +0 -1
  85. data/lib/generators/react_on_rails/templates/heroku_deployment/config/puma.rb +0 -15
  86. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintignore +0 -1
  87. data/lib/generators/react_on_rails/templates/js_linters/client/.eslintrc +0 -48
  88. data/lib/generators/react_on_rails/templates/js_linters/client/.jscsrc +0 -18
  89. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +0 -39
  90. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +0 -33
  91. data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +0 -12
  92. data/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +0 -11
  93. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/actions/helloWorldActionCreators.jsx +0 -8
  94. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx +0 -48
  95. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx +0 -8
  96. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +0 -43
  97. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx +0 -21
  98. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/reducers/index.jsx +0 -14
  99. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +0 -21
  100. data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +0 -35
  101. data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +0 -20
  102. data/lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +0 -21
  103. data/lib/generators/react_on_rails/templates/ruby_linters/.rubocop.yml +0 -26
  104. data/lib/generators/react_on_rails/templates/ruby_linters/.scss-lint.yml +0 -205
  105. data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/brakeman.rake +0 -17
  106. data/lib/generators/react_on_rails/templates/ruby_linters/lib/tasks/ci.rake +0 -33
  107. data/lib/generators/react_on_rails/templates/ruby_linters/ruby-lint.yml +0 -20
  108. data/lib/react_on_rails.rb +0 -6
  109. data/lib/react_on_rails/configuration.rb +0 -53
  110. data/lib/react_on_rails/engine.rb +0 -7
  111. data/lib/react_on_rails/prerender_error.rb +0 -31
  112. data/lib/react_on_rails/server_rendering_pool.rb +0 -111
  113. data/lib/react_on_rails/version.rb +0 -3
  114. data/rakelib/docker.rake +0 -33
  115. data/rakelib/dummy_apps.rake +0 -29
  116. data/rakelib/example_type.rb +0 -160
  117. data/rakelib/examples.rake +0 -103
  118. data/rakelib/examples_config.yml +0 -19
  119. data/rakelib/lint.rake +0 -37
  120. data/rakelib/run_rspec.rake +0 -65
  121. data/rakelib/task_helpers.rb +0 -44
  122. data/react_on_rails.gemspec +0 -31
  123. data/ruby-lint.yml +0 -24
@@ -1,42 +0,0 @@
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.
@@ -1,62 +0,0 @@
1
- # Tips for Contributors
2
-
3
- ## Development Setup for Gem Contributors
4
-
5
- ### Checklist before Committing
6
- 1. `rake ci`: runs all linters and specs (you need Docker setup, see below)
7
- 2. Did you need any more tests for your change?
8
- 3. Did you document your change? Update the README.md?
9
-
10
- ### Initial Setup
11
- 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 dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
12
-
13
- ### Starting the Dummy App
14
- 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.
15
-
16
- ### RSpec Testing
17
- Run `rake` for testing the gem and `spec/dummy` and `spec/dummy-react-013`. Otherwise, the `rspec` command only works for testing within the sample apps, like `spec/dummy`.
18
-
19
- If you run `rspec` at the top level, you'll see this message: `require': cannot load such file -- rails_helper (LoadError)`
20
-
21
- After running a test, you can view the coverage results SimpleCov reports by opening `coverage/index.html`.
22
-
23
- ### Debugging
24
- Start the sample app like this for some debug printing:
25
-
26
- ```bash
27
- TRACE_REACT_ON_RAILS=true && foreman start
28
- ```
29
-
30
- ### Install Generator
31
- In your Rails app add this gem with a path to your fork.
32
-
33
- ```
34
- gem 'react_on_rails', path: '/your_fork'
35
- ```
36
-
37
- The main installer can be run with ```rails generate react_on_rails:install```
38
-
39
- ### Testing the Generator
40
- 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.
41
-
42
- ### Linting
43
- All linting is performed from the docker container. You will need docker and docker-compose installed locally to lint code changes via the lint container.
44
-
45
- * [Install Docker Toolbox for Mac](https://www.docker.com/toolbox)
46
- * [Install Docker Compose for Linux](https://docs.docker.com/compose/install/)
47
-
48
- 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.
49
-
50
- ### Linting Commands
51
- 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.
52
-
53
- You can run specific linting for directories or files by using `docker-compose run lint rubocop (file path or directory)`, etc.
54
-
55
- `docker-compose run lint bash` sets you up to run from the container command line.
56
-
57
- ### Docker CI - Test and Linting
58
- Docker CI and Tests containers have a xvfd server automatically started for headless browser testing with selenium and Firefox.
59
-
60
- 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.
61
-
62
- Run `docker-compose build tests` to build the tests container. Run `docker-compose run tests` to start all rspec tests.
@@ -1,20 +0,0 @@
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)
@@ -1,24 +0,0 @@
1
- ### Install and Release
2
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
3
-
4
- ## Updating New Versions of the Gem
5
- See https://github.com/svenfuchs/gem-release
6
-
7
- ```bash
8
- gem bump
9
- cd spec/dummy
10
- bundle
11
- git commit -am "Updated Gemfile.lock"
12
- cd ../..
13
- gem tag
14
- gem release
15
- ```
16
-
17
- ## Testing the Gem before Release from a Rails App
18
- 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:
19
-
20
- ```ruby
21
- gem "react_on_rails", path: "../path-to-react-on-rails"
22
- ```
23
-
24
- 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**.
@@ -1,4 +0,0 @@
1
- Files in this directory show what JS is generated for client and server rendering.
2
-
3
- * [client-generated.js](./client-generated.js)
4
- * [server-generated.js](./server-generated.js)
@@ -1,12 +0,0 @@
1
- (function() {
2
- window.__helloWorldData0__ = {"helloWorldData":{"name":"Mr. Server Side Rendering"}};
3
- ReactOnRails.clientRenderReactComponent({
4
- componentName: 'HelloWorld',
5
- domId: 'HelloWorld-react-component-0',
6
- propsVarName: '__helloWorldData0__',
7
- props: window.__helloWorldData0__,
8
- trace: true,
9
- generatorFunction: false,
10
- expectTurboLinks: true
11
- });
12
- })();
@@ -1,25 +0,0 @@
1
- (function() {
2
- var htmlResult = '';
3
- var consoleReplayScript = '';
4
- var hasErrors = false;
5
-
6
- try {
7
- htmlResult =
8
- (function() {
9
- return this.HelloString.world();
10
- })();
11
- } catch(e) {
12
- htmlResult = ReactOnRails.handleError({e: e, componentName: null,
13
- jsCode: 'this.HelloString.world()', serverSide: true});
14
- hasErrors = true;
15
- }
16
-
17
- consoleReplayScript = ReactOnRails.buildConsoleReplay();
18
-
19
- return JSON.stringify({
20
- html: htmlResult,
21
- consoleReplayScript: consoleReplayScript,
22
- hasErrors: hasErrors
23
- });
24
-
25
- })()
@@ -1,99 +0,0 @@
1
- Description:
2
-
3
- The react_on_rails:install generator combined with the example pull requests of
4
- generator runs will get you up and running efficiently. There's a fair bit of
5
- setup involved when ~with~ integrating Webpack with Rails. Defaults for options
6
- are such that the default is for the flag to be off. For example, the default for
7
- `-R` is that redux is off, and the default of -b means that skip-bootstrap is off.
8
-
9
- * Redux
10
-
11
- Passing the --redux generator option causes the generated Hello World example
12
- to integrate the Redux state container framework. The necessary node modules
13
- will be automatically included for you.
14
-
15
- The generator uses the organizational `paradigm of "bundles"`. These are like
16
- application domains and are used for grouping your code into webpack bundles
17
- in case you decide to create different bundles for deployment. This is also
18
- useful for separating out logical parts of your application. We recommend that
19
- that each bundle will have it's own Redux store. If you have code that you
20
- want to reuse across bundles, such as middleware or common utilities, place them
21
- under `/client/app/lib`. You can then import them in your client code:
22
- `import MyModule from 'lib/MyModule'`; since we have configured webpack to
23
- automatically resolve the word lib to point to this folder.
24
-
25
- * Using Images and Fonts
26
-
27
- The generator has amended the folders created in `client/assets/` to Rails's
28
- asset path. We recommend that if you have any existing assets that you want
29
- to use with your client code, you should move them to these folders and use
30
- webpack as normal. This allows webpack's development server to have access
31
- to your assets, as it will not be able to see any assets in the default Rails
32
- directories which are above the `/client` directory.
33
-
34
- Alternatively, if you have many existing assets and don't wish to move them,
35
- you could consider creating symlinks from `client/assets` that point to your
36
- Rails assets folders inside of `app/assets/`. The assets there will then be
37
- visible to both Rails and webpack.
38
-
39
- * Bootstrap Integration
40
-
41
- React on Rails ships with Twitter Bootstrap already integrated into the build.
42
- Note that the generator removes require_tree in both the application.js and
43
- application.css.scss files. This is to ensure the correct load order for the
44
- bootstrap integration, and is usually a good idea in general. You will therefore
45
- need to explicitly require your files.
46
-
47
- How the Bootstrap library is loaded depends upon whether one is using the Rails
48
- server or the HMR development server.
49
-
50
- 1. Bootstrap via Rails Server
51
-
52
- The Rails server loads bootstrap-sprockets, provided
53
- by the bootstrap-sass ruby gem (added automatically to your Gemfile by
54
- the generator), via the `app/assets/stylesheets/_bootstrap-custom.scss`
55
- partial.
56
-
57
- This allows for using Bootstrap in your regular Rails stylesheets. If you
58
- wish to customize any of the Bootstrap variables, you can do so via the
59
- `client/assets/stylesheets/_pre-bootstrap.scss` partial.
60
-
61
- 2. Bootstrap via Webpack Dev Server
62
-
63
- The webpack dev server does not go through Rails but instead loads bootstrap
64
- via the `bootstrap-sass-loader` webpack loader. You can configure the loader
65
- via the `client/bootstrap-sass-config.js` file.
66
-
67
- 3. Keeping Custom Bootstrap Configurations Synced
68
-
69
- Because the webpack dev server and Rails each load Bootstrap via a different
70
- file (explained in the two sections immediately above), any changes to
71
- the way components are loaded in one file must also be made to the other
72
- file in order to keep styling consistent between the two. For example,
73
- if an import is excluded in _bootstrap-custom.scss, the same import should
74
- be excluded in `bootstrap-sass-config.js` so that styling in the Rails
75
- server and the webpack dev server will be the same.
76
-
77
- 4. Skip Bootstrap Integration
78
-
79
- Bootstrap integration is enabled by default, but can be disabled by passing
80
- the --skip-bootstrap flag (alias -b). When you don't need Bootstrap in your
81
- existing project, just skip it as needed.
82
-
83
- * JavaScript Linters
84
-
85
- JavaScript linters are enabled by default, but can be disabled by passing the
86
- --skip-js-linters flag (alias j), and those that run in Node have been add to
87
- `client/package.json` under devDependencies.
88
-
89
- * Ruby Linters
90
-
91
- Ruby linters are disabled by default, but can be enabled by passing the
92
- `--ruby-linters` flag when generating. These linters have been added to your
93
- Gemfile in addition to the the appropriate Rake tasks.
94
-
95
- We really love using all the linters! Give them a try.
96
-
97
- More Details:
98
-
99
- `https://github.com/shakacode/react_on_rails#generator`
@@ -1,198 +0,0 @@
1
- require "rails/generators"
2
- require File.expand_path("../generator_helper", __FILE__)
3
- require File.expand_path("../generator_errors", __FILE__)
4
-
5
- include GeneratorHelper
6
- include GeneratorErrors
7
-
8
- module ReactOnRails
9
- module Generators
10
- class BaseGenerator < Rails::Generators::Base # rubocop:disable Metrics/ClassLength
11
- Rails::Generators.hide_namespace(namespace)
12
- source_root(File.expand_path("../templates", __FILE__))
13
-
14
- # --redux
15
- class_option :redux,
16
- type: :boolean,
17
- default: false,
18
- desc: "Install Redux gems and Redux version of Hello World Example",
19
- aliases: "-R"
20
- # --server-rendering
21
- class_option :server_rendering,
22
- type: :boolean,
23
- default: false,
24
- desc: "Configure for server-side rendering of webpack JavaScript",
25
- aliases: "-S"
26
- # --skip-js-linters
27
- class_option :skip_js_linters,
28
- type: :boolean,
29
- default: false,
30
- desc: "Skip installing JavaScript linting files",
31
- aliases: "-j"
32
- # --ruby-linters
33
- class_option :ruby_linters,
34
- type: :boolean,
35
- default: false,
36
- desc: "Install ruby linting files, tasks, and configs",
37
- aliases: "-L"
38
-
39
- # --skip-bootstrap
40
- class_option :skip_bootstrap,
41
- type: :boolean,
42
- default: false,
43
- desc: "Skip integrating Bootstrap and don't initialize files and regarding configs",
44
- aliases: "-b"
45
-
46
- def add_hello_world_route
47
- route "get 'hello_world', to: 'hello_world#index'"
48
- end
49
-
50
- def create_client_assets_directories
51
- empty_directory("client/assets")
52
- empty_directory("client/assets/stylesheets")
53
- empty_directory_with_keep_file("client/assets/fonts")
54
- empty_directory_with_keep_file("client/assets/images")
55
- end
56
-
57
- def update_git_ignore
58
- data = <<-DATA.strip_heredoc
59
- # React on Rails
60
- npm-debug.log
61
- node_modules
62
-
63
- # Generated js bundles
64
- /app/assets/javascripts/generated/*
65
- DATA
66
-
67
- if dest_file_exists?(".gitignore")
68
- append_to_file(".gitignore", data)
69
- else
70
- GeneratorErrors.add_error(return_setup_file_error(".gitignore", data))
71
- end
72
- end
73
-
74
- def update_application_js
75
- data = <<-DATA.strip_heredoc
76
- // DO NOT REQUIRE jQuery or jQuery-ujs in this file!
77
- // DO NOT REQUIRE TREE!
78
-
79
- // CRITICAL that generated/vendor-bundle must be BEFORE bootstrap-sprockets and turbolinks
80
- // since it is exposing jQuery and jQuery-ujs
81
- //= require react_on_rails
82
-
83
- //= require generated/vendor-bundle
84
- //= require generated/app-bundle
85
-
86
- DATA
87
-
88
- app_js_path = "app/assets/javascripts/application.js"
89
- found_app_js = dest_file_exists?(app_js_path) || dest_file_exists?(app_js_path + ".coffee")
90
- if found_app_js
91
- prepend_to_file(found_app_js, data)
92
- else
93
- create_file(app_js_path, data)
94
- end
95
- end
96
-
97
- def strip_application_js_of_incompatible_sprockets_statements
98
- application_js = File.join(destination_root, "app/assets/javascripts/application.js")
99
- gsub_file(application_js, "//= require jquery_ujs", "// require jquery_ujs")
100
- gsub_file(application_js, %r{//= require jquery$}, "// require jquery")
101
- gsub_file(application_js, %r{//= require_tree \.$}, "// require_tree .")
102
- end
103
-
104
- def strip_application_js_of_double_blank_lines
105
- application_js = File.join(destination_root, "app/assets/javascripts/application.js")
106
- gsub_file(application_js, /^\n^\n/, "\n")
107
- end
108
-
109
- def create_react_directories
110
- dirs = %w(components containers startup)
111
- dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
112
- end
113
-
114
- def copy_base_files
115
- base_path = "base/base/"
116
- %w(app/controllers/hello_world_controller.rb
117
- config/initializers/react_on_rails.rb
118
- client/.babelrc
119
- client/index.jade
120
- client/server.js
121
- client/webpack.client.rails.config.js
122
- REACT_ON_RAILS.md
123
- client/REACT_ON_RAILS_CLIENT_README.md
124
- package.json).each { |file| copy_file(base_path + file, file) }
125
- end
126
-
127
- def template_base_files
128
- base_path = "base/base/"
129
- %w(Procfile.dev
130
- app/views/hello_world/index.html.erb
131
- client/webpack.client.base.config.js
132
- client/webpack.client.hot.config.js
133
- client/package.json).each { |file| template(base_path + file + ".tt", file) }
134
- end
135
-
136
- def add_base_gems_to_gemfile
137
- return unless options.server_rendering?
138
- append_to_file("Gemfile", "\ngem 'therubyracer', platforms: :ruby\n")
139
- end
140
-
141
- def template_client_globals_file
142
- filename = options.server_rendering? ? "clientGlobals.jsx" : "globals.jsx"
143
- location = "client/app/bundles/HelloWorld/startup"
144
- template("base/base/#{location}/globals.jsx.tt", "#{location}/#{filename}")
145
- end
146
-
147
- def install_server_rendering_files_if_enabled
148
- return unless options.server_rendering?
149
- base_path = "base/server_rendering/"
150
- %w(client/webpack.server.rails.config.js
151
- client/app/bundles/HelloWorld/startup/serverGlobals.jsx).each do |file|
152
- copy_file(base_path + file, file)
153
- end
154
- end
155
-
156
- def template_linter_files_if_appropriate
157
- return if !options.ruby_linters? && options.skip_js_linters?
158
- template("base/base/lib/tasks/linters.rake.tt", "lib/tasks/linters.rake")
159
- end
160
-
161
- def template_assets_rake_file
162
- template("base/base/lib/tasks/assets.rake.tt", "lib/tasks/assets.rake")
163
- end
164
-
165
- def append_to_assets_initializer
166
- data = <<-DATA.strip_heredoc
167
- # Add client/assets/ folders to asset pipeline's search path.
168
- # If you do not want to move existing images and fonts from your Rails app
169
- # you could also consider creating symlinks there that point to the original
170
- # rails directories. In that case, you would not add these paths here.
171
- Rails.application.config.assets.paths << Rails.root.join("client", "assets", "stylesheets")
172
- Rails.application.config.assets.paths << Rails.root.join("client", "assets", "images")
173
- Rails.application.config.assets.paths << Rails.root.join("client", "assets", "fonts")
174
- Rails.application.config.assets.precompile += %w( generated/server-bundle.js )
175
- DATA
176
- assets_intializer = File.join(destination_root, "config/initializers/assets.rb")
177
- if File.exist?(assets_intializer)
178
- append_to_file(assets_intializer, data)
179
- else
180
- create_file(assets_intializer, data)
181
- end
182
- end
183
-
184
- # rename to application.scss from application.css or application.css.scss
185
- def force_application_scss_naming_if_necessary
186
- base_path = "app/assets/stylesheets/"
187
- application_css = "#{base_path}application.css"
188
- application_css_scss = "#{base_path}application.css.scss"
189
-
190
- bad_name = dest_file_exists?(application_css) || dest_file_exists?(application_css_scss)
191
- return unless bad_name
192
-
193
- new_name = File.join(destination_root, "#{base_path}application.scss")
194
- File.rename(bad_name, new_name)
195
- end
196
- end
197
- end
198
- end