react_on_rails 5.2.0 → 6.0.0.beta.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +1 -0
- data/CHANGELOG.md +31 -0
- data/PROJECTS.md +11 -2
- data/README.md +33 -203
- data/app/helpers/react_on_rails_helper.rb +32 -49
- data/docs/additional-reading/heroku-deployment.md +2 -35
- data/docs/additional-reading/node-server-rendering.md +30 -0
- data/docs/additional-reading/rails-assets.md +19 -0
- data/docs/additional-reading/rspec-configuration.md +38 -4
- data/docs/additional-reading/webpack-dev-server.md +16 -0
- data/docs/additional-reading/webpack.md +0 -10
- data/docs/api/javascript-api.md +37 -0
- data/docs/api/ruby-api-hot-reload-view-helpers.md +42 -0
- data/docs/api/ruby-api.md +3 -0
- data/docs/basics/generator.md +49 -0
- data/docs/{additional-reading → basics}/installation-overview.md +0 -0
- data/docs/basics/migrating-from-react-rails.md +17 -0
- data/docs/contributor-info/contributing.md +11 -0
- data/docs/{coding-style → contributor-info}/linters.md +0 -0
- data/lib/generators/USAGE +3 -95
- data/lib/generators/react_on_rails/base_generator.rb +10 -43
- data/lib/generators/react_on_rails/dev_tests_generator.rb +17 -1
- data/lib/generators/react_on_rails/install_generator.rb +0 -6
- data/lib/generators/react_on_rails/react_no_redux_generator.rb +3 -17
- data/lib/generators/react_on_rails/react_with_redux_generator.rb +4 -21
- data/lib/generators/react_on_rails/templates/base/base/Procfile.dev.tt +2 -2
- data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt +3 -4
- data/lib/generators/react_on_rails/templates/base/base/client/app/bundles/HelloWorld/components/HelloWorldWidget.jsx.tt +1 -11
- data/lib/generators/react_on_rails/templates/base/base/client/node/package.json +10 -0
- data/lib/generators/react_on_rails/templates/base/base/client/node/server.js +82 -0
- data/lib/generators/react_on_rails/templates/base/base/client/package.json.tt +3 -20
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.config.js +58 -0
- data/lib/generators/react_on_rails/templates/base/base/config/initializers/react_on_rails.rb.tt +60 -26
- data/lib/generators/react_on_rails/templates/base/base/lib/tasks/assets.rake.tt +1 -4
- data/lib/generators/react_on_rails/templates/base/base/lib/tasks/load_test.rake +8 -0
- data/lib/generators/react_on_rails/templates/base/base/package.json.tt +0 -12
- data/lib/generators/react_on_rails/templates/dev_tests/spec/features/hello_world_spec.rb +1 -1
- data/lib/generators/react_on_rails/templates/dev_tests/spec/rails_helper.rb +1 -0
- data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/containers/HelloWorld.jsx +1 -7
- data/lib/generators/react_on_rails/templates/{base/base/client/app/bundles/HelloWorld/startup/clientRegistration.jsx.tt → no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldApp.jsx.tt} +7 -1
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/startup/{HelloWorldAppClient.jsx.tt → HelloWorldApp.jsx.tt} +5 -1
- data/lib/generators/react_on_rails/templates/redux/base/client/app/bundles/HelloWorld/store/helloWorldStore.jsx +1 -5
- data/lib/react_on_rails.rb +2 -1
- data/lib/react_on_rails/configuration.rb +17 -5
- data/lib/react_on_rails/react_component/options.rb +76 -0
- data/lib/react_on_rails/server_rendering_pool.rb +9 -151
- data/lib/react_on_rails/server_rendering_pool/exec.rb +166 -0
- data/lib/react_on_rails/server_rendering_pool/node.rb +77 -0
- data/lib/react_on_rails/test_helper.rb +1 -6
- data/lib/react_on_rails/test_helper/ensure_assets_compiled.rb +4 -77
- data/lib/react_on_rails/test_helper/node_process_launcher.rb +12 -0
- data/lib/react_on_rails/test_helper/webpack_assets_compiler.rb +4 -28
- data/lib/react_on_rails/version.rb +1 -1
- data/lib/tasks/assets.rake +115 -0
- data/package.json +2 -1
- data/rakelib/example_type.rb +3 -10
- data/rakelib/examples_config.yml +2 -2
- data/react_on_rails.gemspec +1 -0
- metadata +41 -20
- data/lib/generators/react_on_rails/templates/base/base/REACT_ON_RAILS.md +0 -16
- data/lib/generators/react_on_rails/templates/base/base/client/REACT_ON_RAILS_CLIENT_README.md +0 -3
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.base.config.js +0 -65
- data/lib/generators/react_on_rails/templates/base/base/client/webpack.client.rails.config.js +0 -53
- data/lib/generators/react_on_rails/templates/base/server_rendering/client/app/bundles/HelloWorld/startup/serverRegistration.jsx +0 -4
- data/lib/generators/react_on_rails/templates/base/server_rendering/client/webpack.server.rails.config.js +0 -39
- data/lib/generators/react_on_rails/templates/no_redux/base/client/app/bundles/HelloWorld/startup/HelloWorldAppClient.jsx.tt +0 -6
- data/lib/generators/react_on_rails/templates/no_redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +0 -6
- data/lib/generators/react_on_rails/templates/redux/base/client/app/lib/middlewares/loggerMiddleware.js +0 -21
- data/lib/generators/react_on_rails/templates/redux/server_rendering/client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx +0 -19
- data/lib/react_on_rails/test_helper/webpack_process_checker.rb +0 -54
File without changes
|
@@ -0,0 +1,17 @@
|
|
1
|
+
## Migrate From react-rails
|
2
|
+
If you are using [react-rails](https://github.com/reactjs/react-rails) in your project, it is pretty simple to migrate to [react_on_rails](https://github.com/shakacode/react_on_rails).
|
3
|
+
|
4
|
+
- Remove the 'react-rails' gem from your Gemfile.
|
5
|
+
|
6
|
+
- Remove the generated lines for react-rails in your application.js file.
|
7
|
+
|
8
|
+
```
|
9
|
+
//= require react
|
10
|
+
//= require react_ujs
|
11
|
+
//= require components
|
12
|
+
```
|
13
|
+
|
14
|
+
- Follow our getting started guide: https://github.com/shakacode/react_on_rails#getting-started.
|
15
|
+
|
16
|
+
Note: If you have components from react-rails you want to use, then you will need to port them into react_on_rails which uses webpack instead of the asset pipeline.
|
17
|
+
|
@@ -1,6 +1,17 @@
|
|
1
1
|
# Tips for Contributors
|
2
2
|
*See [Releasing](./releasing.md) for instructions on releasing.*
|
3
3
|
|
4
|
+
## Sumary
|
5
|
+
|
6
|
+
For non-doc fixes:
|
7
|
+
|
8
|
+
* Provide changelog entry in the [unreleased section of the CHANGELOG.md](https://github.com/shakacode/react_on_rails/blob/master/CHANGELOG.md#unreleased).
|
9
|
+
* Ensure CI passes and that you added a test that passes with the fix and fails without the fix.
|
10
|
+
* Squash all commits down to one with a nice commit message *ONLY* once final review is given. Make sure this single commit is rebased on top of master.
|
11
|
+
* Please address all code review comments.
|
12
|
+
* Ensure that docs are updated accordingly if a feature is added.
|
13
|
+
|
14
|
+
|
4
15
|
## To run tests:
|
5
16
|
* After updating code via git, to prepare all examples and run all tests:
|
6
17
|
|
File without changes
|
data/lib/generators/USAGE
CHANGED
@@ -1,10 +1,7 @@
|
|
1
1
|
Description:
|
2
2
|
|
3
|
-
The react_on_rails:install generator
|
4
|
-
|
5
|
-
setup involved when 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 is that skip-bootstrap is off.
|
3
|
+
The react_on_rails:install generator integrates webpack with rails with ease. You
|
4
|
+
can pass the redux option if you'd like to have redux setup for you automatically.
|
8
5
|
|
9
6
|
* Redux
|
10
7
|
|
@@ -12,88 +9,6 @@ are such that the default is for the flag to be off. For example, the default fo
|
|
12
9
|
to integrate the Redux state container framework. The necessary node modules
|
13
10
|
will be automatically included for you.
|
14
11
|
|
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 added 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
12
|
*******************************************************************************
|
98
13
|
|
99
14
|
After running the generator, you will want to:
|
@@ -102,14 +17,7 @@ After running the generator, you will want to:
|
|
102
17
|
|
103
18
|
Then you may run
|
104
19
|
|
105
|
-
|
106
|
-
|
107
|
-
And you will see several useful commands:
|
108
|
-
|
109
|
-
express-server
|
110
|
-
echo 'visit http://localhost:4000' && cd client && npm start
|
111
|
-
rails-server
|
112
|
-
echo 'visit http://localhost:3000/hello_world' && foreman start -f Procfile.dev
|
20
|
+
foreman start -f Procfile.dev
|
113
21
|
|
114
22
|
More Details:
|
115
23
|
|
@@ -4,7 +4,7 @@ require_relative "generator_helper"
|
|
4
4
|
|
5
5
|
module ReactOnRails
|
6
6
|
module Generators
|
7
|
-
class BaseGenerator < Rails::Generators::Base
|
7
|
+
class BaseGenerator < Rails::Generators::Base
|
8
8
|
include GeneratorHelper
|
9
9
|
Rails::Generators.hide_namespace(namespace)
|
10
10
|
source_root(File.expand_path("../templates", __FILE__))
|
@@ -15,12 +15,6 @@ module ReactOnRails
|
|
15
15
|
default: false,
|
16
16
|
desc: "Install Redux gems and Redux version of Hello World Example",
|
17
17
|
aliases: "-R"
|
18
|
-
# --server-rendering
|
19
|
-
class_option :server_rendering,
|
20
|
-
type: :boolean,
|
21
|
-
default: false,
|
22
|
-
desc: "Configure for server-side rendering of webpack JavaScript",
|
23
|
-
aliases: "-S"
|
24
18
|
|
25
19
|
def add_hello_world_route
|
26
20
|
route "get 'hello_world', to: 'hello_world#index'"
|
@@ -45,14 +39,7 @@ module ReactOnRails
|
|
45
39
|
|
46
40
|
def update_application_js
|
47
41
|
data = <<-DATA.strip_heredoc
|
48
|
-
|
49
|
-
// DO NOT REQUIRE TREE!
|
50
|
-
|
51
|
-
// CRITICAL that vendor-bundle must be BEFORE bootstrap-sprockets and turbolinks
|
52
|
-
// since it is exposing jQuery and jQuery-ujs
|
53
|
-
|
54
|
-
//= require vendor-bundle
|
55
|
-
//= require app-bundle
|
42
|
+
//= require webpack-bundle
|
56
43
|
|
57
44
|
DATA
|
58
45
|
|
@@ -65,13 +52,6 @@ module ReactOnRails
|
|
65
52
|
end
|
66
53
|
end
|
67
54
|
|
68
|
-
def strip_application_js_of_incompatible_sprockets_statements
|
69
|
-
application_js = File.join(destination_root, "app/assets/javascripts/application.js")
|
70
|
-
gsub_file(application_js, "//= require jquery_ujs", "// require jquery_ujs")
|
71
|
-
gsub_file(application_js, %r{//= require jquery$}, "// require jquery")
|
72
|
-
gsub_file(application_js, %r{//= require_tree \.$}, "// require_tree .")
|
73
|
-
end
|
74
|
-
|
75
55
|
def strip_application_js_of_double_blank_lines
|
76
56
|
application_js = File.join(destination_root, "app/assets/javascripts/application.js")
|
77
57
|
gsub_file(application_js, /^\n^\n/, "\n")
|
@@ -86,10 +66,7 @@ module ReactOnRails
|
|
86
66
|
base_path = "base/base/"
|
87
67
|
base_files = %w(app/controllers/hello_world_controller.rb
|
88
68
|
client/.babelrc
|
89
|
-
client/webpack.
|
90
|
-
client/webpack.client.rails.config.js
|
91
|
-
REACT_ON_RAILS.md
|
92
|
-
client/REACT_ON_RAILS_CLIENT_README.md)
|
69
|
+
client/webpack.config.js)
|
93
70
|
base_files.each { |file| copy_file(base_path + file, file) }
|
94
71
|
end
|
95
72
|
|
@@ -104,35 +81,25 @@ module ReactOnRails
|
|
104
81
|
end
|
105
82
|
|
106
83
|
def add_base_gems_to_gemfile
|
107
|
-
return unless options.server_rendering?
|
108
84
|
append_to_file("Gemfile", "\ngem 'therubyracer', platforms: :ruby\n")
|
109
85
|
end
|
110
86
|
|
111
|
-
def
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
end
|
116
|
-
|
117
|
-
def install_server_rendering_files_if_enabled
|
118
|
-
return unless options.server_rendering?
|
119
|
-
base_path = "base/server_rendering/"
|
120
|
-
%w(client/webpack.server.rails.config.js
|
121
|
-
client/app/bundles/HelloWorld/startup/serverRegistration.jsx).each do |file|
|
87
|
+
def install_node_files
|
88
|
+
base_path = "base/base/"
|
89
|
+
%w(client/node/package.json
|
90
|
+
client/node/server.js).each do |file|
|
122
91
|
copy_file(base_path + file, file)
|
123
92
|
end
|
124
93
|
end
|
125
94
|
|
126
|
-
def template_assets_rake_file
|
127
|
-
template("base/base/lib/tasks/assets.rake.tt", "lib/tasks/assets.rake")
|
128
|
-
end
|
129
|
-
|
130
95
|
ASSETS_RB_APPEND = <<-DATA.strip_heredoc
|
131
96
|
# Add client/assets/ folders to asset pipeline's search path.
|
132
97
|
# If you do not want to move existing images and fonts from your Rails app
|
133
98
|
# you could also consider creating symlinks there that point to the original
|
134
99
|
# rails directories. In that case, you would not add these paths here.
|
135
|
-
|
100
|
+
# If you have a different server bundle file than your client bundle, you'll
|
101
|
+
# need to add it here, like this:
|
102
|
+
# Rails.application.config.assets.precompile += %w( server-bundle.js )
|
136
103
|
|
137
104
|
# Add folder with webpack generated assets to assets.paths
|
138
105
|
Rails.application.config.assets.paths << Rails.root.join("app", "assets", "webpack")
|
@@ -8,6 +8,12 @@ module ReactOnRails
|
|
8
8
|
Rails::Generators.hide_namespace(namespace)
|
9
9
|
source_root(File.expand_path("../templates/dev_tests", __FILE__))
|
10
10
|
|
11
|
+
# --example-server-rendering
|
12
|
+
class_option :example_server_rendering,
|
13
|
+
type: :boolean,
|
14
|
+
default: false,
|
15
|
+
desc: "Setup prerender true for server rendered examples"
|
16
|
+
|
11
17
|
def copy_rspec_files
|
12
18
|
%w(spec/spec_helper.rb
|
13
19
|
spec/rails_helper.rb
|
@@ -40,7 +46,7 @@ module ReactOnRails
|
|
40
46
|
plugins: [
|
41
47
|
TEXT
|
42
48
|
sentinel = /^\s\s},\n\s\splugins: \[\n/
|
43
|
-
config = File.join(destination_root, "client", "webpack.
|
49
|
+
config = File.join(destination_root, "client", "webpack.config.js")
|
44
50
|
old_contents = File.read(config)
|
45
51
|
new_contents = old_contents.gsub(sentinel, text)
|
46
52
|
File.open(config, "w+") { |f| f.puts new_contents }
|
@@ -53,6 +59,16 @@ TEXT
|
|
53
59
|
gem("coveralls", require: false)
|
54
60
|
gem("poltergeist")
|
55
61
|
end
|
62
|
+
|
63
|
+
def gsub_prerender_if_server_rendering
|
64
|
+
return unless options.example_server_rendering
|
65
|
+
hello_world_index = File.join(destination_root, "app", "views", "hello_world", "index.html.erb")
|
66
|
+
hello_world_contents = File.read(hello_world_index)
|
67
|
+
new_hello_world_contents = hello_world_contents.gsub(/prerender: false/,
|
68
|
+
"prerender: true")
|
69
|
+
|
70
|
+
File.open(hello_world_index, "w+") { |f| f.puts new_hello_world_contents }
|
71
|
+
end
|
56
72
|
end
|
57
73
|
end
|
58
74
|
end
|
@@ -16,12 +16,6 @@ module ReactOnRails
|
|
16
16
|
default: false,
|
17
17
|
desc: "Install Redux gems and Redux version of Hello World Example. Default: false",
|
18
18
|
aliases: "-R"
|
19
|
-
# --server-rendering
|
20
|
-
class_option :server_rendering,
|
21
|
-
type: :boolean,
|
22
|
-
default: false,
|
23
|
-
desc: "Add necessary files and configurations for server-side rendering. Default: false",
|
24
|
-
aliases: "-S"
|
25
19
|
|
26
20
|
# --ignore-warnings
|
27
21
|
class_option :ignore_warnings,
|
@@ -8,30 +8,16 @@ module ReactOnRails
|
|
8
8
|
Rails::Generators.hide_namespace(namespace)
|
9
9
|
source_root(File.expand_path("../templates", __FILE__))
|
10
10
|
|
11
|
-
# --server-rendering
|
12
|
-
class_option :server_rendering,
|
13
|
-
type: :boolean,
|
14
|
-
default: false,
|
15
|
-
desc: "Configure for server-side rendering of webpack JavaScript",
|
16
|
-
aliases: "-S"
|
17
|
-
|
18
11
|
def copy_base_files
|
19
12
|
base_path = "no_redux/base/"
|
20
13
|
file = "client/app/bundles/HelloWorld/containers/HelloWorld.jsx"
|
21
14
|
copy_file(base_path + file, file)
|
22
15
|
end
|
23
16
|
|
24
|
-
def
|
25
|
-
|
26
|
-
base_path = "no_redux/server_rendering/"
|
27
|
-
file = "client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx"
|
28
|
-
copy_file(base_path + file, file)
|
29
|
-
end
|
30
|
-
|
31
|
-
def template_appropriate_version_of_hello_world_app_client
|
32
|
-
filename = "HelloWorldAppClient.jsx"
|
17
|
+
def template_appropriate_version_of_hello_world_app
|
18
|
+
filename = "HelloWorldApp.jsx"
|
33
19
|
location = "client/app/bundles/HelloWorld/startup"
|
34
|
-
template("no_redux/base/#{location}/
|
20
|
+
template("no_redux/base/#{location}/HelloWorldApp.jsx.tt", "#{location}/#{filename}")
|
35
21
|
end
|
36
22
|
end
|
37
23
|
end
|
@@ -6,18 +6,9 @@ module ReactOnRails
|
|
6
6
|
Rails::Generators.hide_namespace(namespace)
|
7
7
|
source_root(File.expand_path("../templates", __FILE__))
|
8
8
|
|
9
|
-
# --server-rendering
|
10
|
-
class_option :server_rendering,
|
11
|
-
type: :boolean,
|
12
|
-
default: false,
|
13
|
-
desc: "Configure for server-side rendering of webpack JavaScript",
|
14
|
-
aliases: "-S"
|
15
|
-
|
16
9
|
def create_redux_directories
|
17
10
|
dirs = %w(actions constants reducers store)
|
18
11
|
dirs.each { |name| empty_directory("client/app/bundles/HelloWorld/#{name}") }
|
19
|
-
|
20
|
-
empty_directory("client/app/lib/middlewares")
|
21
12
|
end
|
22
13
|
|
23
14
|
def copy_base_redux_files
|
@@ -27,23 +18,15 @@ module ReactOnRails
|
|
27
18
|
client/app/bundles/HelloWorld/constants/helloWorldConstants.jsx
|
28
19
|
client/app/bundles/HelloWorld/reducers/helloWorldReducer.jsx
|
29
20
|
client/app/bundles/HelloWorld/reducers/index.jsx
|
30
|
-
client/app/bundles/HelloWorld/store/helloWorldStore.jsx
|
31
|
-
client/app/lib/middlewares/loggerMiddleware.js).each do |file|
|
21
|
+
client/app/bundles/HelloWorld/store/helloWorldStore.jsx).each do |file|
|
32
22
|
copy_file(base_path + file, file)
|
33
23
|
end
|
34
24
|
end
|
35
25
|
|
36
|
-
def
|
37
|
-
|
38
|
-
base_path = "redux/server_rendering/"
|
39
|
-
file = "client/app/bundles/HelloWorld/startup/HelloWorldAppServer.jsx"
|
40
|
-
copy_file(base_path + file, file)
|
41
|
-
end
|
42
|
-
|
43
|
-
def template_appropriate_version_of_hello_world_app_client
|
44
|
-
filename = "HelloWorldAppClient.jsx"
|
26
|
+
def template_appropriate_version_of_hello_world_app
|
27
|
+
filename = "HelloWorldApp.jsx"
|
45
28
|
location = "client/app/bundles/HelloWorld/startup"
|
46
|
-
template("redux/base/#{location}/
|
29
|
+
template("redux/base/#{location}/HelloWorldApp.jsx.tt", "#{location}/#{filename}")
|
47
30
|
end
|
48
31
|
end
|
49
32
|
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
web: rails s
|
2
|
-
client: sh -c 'rm app/assets/webpack/* || true && cd client && npm run build:
|
3
|
-
|
2
|
+
client: sh -c 'rm app/assets/webpack/* || true && cd client && npm run build:development'
|
3
|
+
node: sh -c 'cd client/node && npm start'
|
data/lib/generators/react_on_rails/templates/base/base/app/views/hello_world/index.html.erb.tt
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
<h1 class="alert alert-info this-works"
|
2
|
-
<%%= react_component("HelloWorldApp",
|
3
|
-
|
4
|
-
prerender: <%= options.server_rendering? %>) %>
|
1
|
+
<h1 class="alert alert-info this-works">Hello World</h1>
|
2
|
+
<%%= react_component("HelloWorldApp", props: @hello_world_props, prerender: false) %>
|
3
|
+
|
@@ -2,7 +2,6 @@
|
|
2
2
|
// all your dump component names with Widget.
|
3
3
|
|
4
4
|
import React, { PropTypes } from 'react';
|
5
|
-
import _ from 'lodash';
|
6
5
|
|
7
6
|
// Simple example of a React "dumb" component
|
8
7
|
export default class HelloWorldWidget extends React.Component {
|
@@ -13,15 +12,6 @@ export default class HelloWorldWidget extends React.Component {
|
|
13
12
|
name: PropTypes.string.isRequired,
|
14
13
|
};
|
15
14
|
|
16
|
-
constructor(props, context) {
|
17
|
-
super(props, context);
|
18
|
-
|
19
|
-
// Uses lodash to bind all methods to the context of the object instance, otherwise
|
20
|
-
// the methods defined here would not refer to the component's class, not the component
|
21
|
-
// instance itself.
|
22
|
-
_.bindAll(this, 'handleChange');
|
23
|
-
}
|
24
|
-
|
25
15
|
// React will automatically provide us with the event `e`
|
26
16
|
handleChange(e) {
|
27
17
|
const name = e.target.value;
|
@@ -43,7 +33,7 @@ export default class HelloWorldWidget extends React.Component {
|
|
43
33
|
<input
|
44
34
|
type="text"
|
45
35
|
value={name}
|
46
|
-
onChange={this.handleChange}
|
36
|
+
onChange={e => this.handleChange(e)}
|
47
37
|
/>
|
48
38
|
</form>
|
49
39
|
</div>
|