react_webpack_rails 0.4.1 → 0.5.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +18 -0
- data/CHANGELOG.md +23 -1
- data/README.md +1 -1
- data/Rakefile +57 -12
- data/docs/api.md +0 -60
- data/docs/install_generator.md +0 -1
- data/js/src/index.js +0 -8
- data/js/src/integrations-manager.js +0 -2
- data/js/src/nodes.js +1 -1
- data/js/src/version.js +1 -1
- data/js/test/integrations-manager.spec.js +1 -5
- data/js/test/nodes.spec.js +4 -4
- data/lib/assets/javascripts/react_integration.js.erb +9 -47
- data/lib/generators/react_webpack_rails/install/server_side_generator.rb +1 -0
- data/lib/generators/react_webpack_rails/install_generator.rb +0 -10
- data/lib/generators/react_webpack_rails/templates/forever/development.json +7 -6
- data/lib/generators/react_webpack_rails/templates/forever/production.json +5 -4
- data/lib/generators/react_webpack_rails/templates/packages/core.json +18 -18
- data/lib/generators/react_webpack_rails/templates/packages/hot-reload.json +1 -1
- data/lib/generators/react_webpack_rails/templates/packages/js-specs.json +8 -8
- data/lib/generators/react_webpack_rails/templates/packages/redux.json +3 -3
- data/lib/generators/react_webpack_rails/templates/packages/server-side.json +1 -1
- data/lib/react_webpack_rails/version.rb +1 -1
- data/lib/react_webpack_rails/view_helpers.rb +12 -5
- data/package.json +11 -11
- metadata +2 -6
- data/js/src/integrations/react-router.js +0 -60
- data/js/test/integrations/react-router.spec.js +0 -133
- data/lib/generators/react_webpack_rails/install/react_router_generator.rb +0 -21
- data/lib/generators/react_webpack_rails/templates/packages/react-router.json +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3dedadf24fa2870a3a88a55a64aa0eb3621da825
|
4
|
+
data.tar.gz: dbf9547a683c1796873a5fd36f5b6def0f04a537
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52b54c004400fbfbc56901524e73e5dbc9bfecfad0fe436da5e7d8830f03b0bbdea2c53cf24c560866245704152449205c16bcd5d415f5b4b0c561be3cdb5a4c
|
7
|
+
data.tar.gz: 5fe97c37924eb22bbda98aef4603980658917fc10a0027f3a5554c5982c7448231a352b058ba135615aac290c04c0d3523d4f54376b86a166ab7fe280bdaf32d
|
data/.travis.yml
CHANGED
@@ -2,17 +2,32 @@ branches:
|
|
2
2
|
except:
|
3
3
|
- docs
|
4
4
|
|
5
|
+
sudo: required
|
6
|
+
dist: trusty
|
5
7
|
language: ruby
|
8
|
+
addons:
|
9
|
+
# From some tests it seems you can only have one firefox addon.
|
10
|
+
# Adding two results in the last one defined being the one installed.
|
11
|
+
apt:
|
12
|
+
sources:
|
13
|
+
- google-chrome
|
14
|
+
packages:
|
15
|
+
- google-chrome-stable
|
16
|
+
- google-chrome-beta
|
6
17
|
|
7
18
|
cache:
|
8
19
|
bundler: true
|
9
20
|
directories:
|
10
21
|
- spec/rails3_dummy_app/node_modules
|
11
22
|
- spec/rails4_dummy_app/node_modules
|
23
|
+
- spec/rails5_dummy_app/node_modules
|
12
24
|
- node_modules
|
13
25
|
|
14
26
|
matrix:
|
15
27
|
include:
|
28
|
+
- rvm: 2.2.4
|
29
|
+
gemfile: spec/rails5_dummy_app/Gemfile
|
30
|
+
env: TEST_SUITE=rails5
|
16
31
|
- rvm: 2.2.4
|
17
32
|
gemfile: spec/rails4_dummy_app/Gemfile
|
18
33
|
env: TEST_SUITE=rails4
|
@@ -25,6 +40,9 @@ matrix:
|
|
25
40
|
- rvm: 2.2.4
|
26
41
|
env: TEST_SUITE=node
|
27
42
|
|
43
|
+
before_install:
|
44
|
+
- sudo apt-get update -qq
|
45
|
+
|
28
46
|
before_script:
|
29
47
|
- npm install -g npm@^2.0
|
30
48
|
- npm install -g webpack@^1.12.1
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,30 @@
|
|
1
|
+
## 0.5.0
|
2
|
+
* fixed forever setup - solving problems with running node server,
|
3
|
+
* renamed `react_element` -> `rwr_element`,
|
4
|
+
* dropped deprecated react_router integration,
|
5
|
+
* npm dependencies bump,
|
6
|
+
* support Rails 5:
|
7
|
+
* added Turbolinks 5 compatibility,
|
8
|
+
* added Rails 5 dummy app for testing.
|
9
|
+
|
10
|
+
|
11
|
+
#### migration 0.4.1 -> 0.5.0
|
12
|
+
in both: `forever/development.json` & `forever/production.json` replace
|
13
|
+
```
|
14
|
+
"sourceDir": "./app/react",
|
15
|
+
```
|
16
|
+
with:
|
17
|
+
```
|
18
|
+
"workingDir": "./",
|
19
|
+
"sourceDir": "app/react",
|
20
|
+
```
|
21
|
+
|
22
|
+
|
1
23
|
## 0.4.1
|
2
24
|
* Update install generator - set NODE_ENV for production.
|
3
25
|
|
4
26
|
#### migration 0.4.0 -> 0.4.1
|
5
|
-
* replace `webpack/
|
27
|
+
* replace `webpack/production.config.js` with:
|
6
28
|
|
7
29
|
```js
|
8
30
|
const Webpack = require('webpack');
|
data/README.md
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
This gem provides easy and convenient way to build modern JavaScript stack on top of Rails applications using [Webpack](http://webpack.github.io/) and [React](https://facebook.github.io/react/).
|
6
6
|
|
7
7
|
### Development branch!
|
8
|
-
See [0.
|
8
|
+
See [0.4-stable](https://github.com/netguru/react_webpack_rails/tree/0.4-stable) for latest release.
|
9
9
|
|
10
10
|
## Features
|
11
11
|
* [Install Generator](https://github.com/netguru/react_webpack_rails/blob/master/docs/install_generator.md) for quick [Webpack](http://webpack.github.io/) setup.
|
data/Rakefile
CHANGED
@@ -1,33 +1,55 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rspec/core/rake_task'
|
3
3
|
|
4
4
|
namespace :test do
|
5
5
|
desc 'Run all tests'
|
6
|
-
task all: [:node, :gem, :rails3, :rails4] do
|
6
|
+
task all: [:node, :gem, :rails3, :rails4, :rails5] do
|
7
7
|
puts 'Finished all tests, yay!'
|
8
8
|
end
|
9
9
|
|
10
10
|
desc 'Run node package tests'
|
11
11
|
task :node do
|
12
|
-
sh %
|
12
|
+
sh %(npm test)
|
13
13
|
end
|
14
14
|
|
15
15
|
desc 'Run gem tests'
|
16
16
|
task :gem do
|
17
|
-
sh %
|
17
|
+
sh %(bundle exec rspec spec/react_webpack_rails_spec.rb spec/react_webpack_rails)
|
18
18
|
end
|
19
19
|
|
20
20
|
desc 'Run rspec for rails3 application'
|
21
21
|
task :rails3 do
|
22
22
|
Bundler.with_clean_env do
|
23
|
-
sh %
|
23
|
+
sh %(
|
24
|
+
cd spec/rails3_dummy_app &&
|
25
|
+
npm run build &&
|
26
|
+
bundle exec rspec &&
|
27
|
+
npm test
|
28
|
+
)
|
24
29
|
end
|
25
30
|
end
|
26
31
|
|
27
32
|
desc 'Run rspec for rails4 application'
|
28
33
|
task :rails4 do
|
29
34
|
Bundler.with_clean_env do
|
30
|
-
sh %
|
35
|
+
sh %(
|
36
|
+
cd spec/rails4_dummy_app &&
|
37
|
+
npm run build &&
|
38
|
+
bundle exec rspec &&
|
39
|
+
npm test
|
40
|
+
)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Run rspec for rails5 application'
|
45
|
+
task :rails5 do
|
46
|
+
Bundler.with_clean_env do
|
47
|
+
sh %(
|
48
|
+
cd spec/rails5_dummy_app &&
|
49
|
+
npm run build &&
|
50
|
+
bundle exec rspec &&
|
51
|
+
npm test
|
52
|
+
)
|
31
53
|
end
|
32
54
|
end
|
33
55
|
end
|
@@ -36,27 +58,50 @@ task default: 'test:all'
|
|
36
58
|
|
37
59
|
namespace :setup do
|
38
60
|
desc 'Prepare every environment'
|
39
|
-
task all: [:node, :gem, :rails3, :rails4] do
|
61
|
+
task all: [:node, :gem, :rails3, :rails4, :rails5] do
|
40
62
|
puts 'Prepared all, yay!'
|
41
63
|
end
|
42
64
|
|
43
65
|
desc 'Prepare node module dependencies'
|
44
66
|
task :node do
|
45
|
-
sh %
|
67
|
+
sh %(npm install)
|
46
68
|
end
|
47
69
|
|
48
70
|
desc 'Prepare gem dependencies'
|
49
71
|
task :gem do
|
50
|
-
sh %
|
72
|
+
sh %(bundle install)
|
51
73
|
end
|
52
74
|
|
53
75
|
desc 'Prepare rails3 test app dependencies'
|
54
76
|
task :rails3 do
|
55
|
-
sh %
|
77
|
+
sh %(
|
78
|
+
npm install &&
|
79
|
+
cd spec/rails3_dummy_app &&
|
80
|
+
rm -rf node_modules/react-webpack-rails &&
|
81
|
+
npm install &&
|
82
|
+
bundle install
|
83
|
+
)
|
56
84
|
end
|
57
85
|
|
58
86
|
desc 'Prepare rails4 test app dependencies'
|
59
87
|
task :rails4 do
|
60
|
-
sh %
|
88
|
+
sh %(
|
89
|
+
npm install &&
|
90
|
+
cd spec/rails4_dummy_app &&
|
91
|
+
rm -rf node_modules/react-webpack-rails &&
|
92
|
+
npm install &&
|
93
|
+
bundle install
|
94
|
+
)
|
95
|
+
end
|
96
|
+
|
97
|
+
desc 'Prepare rails5 test app dependencies'
|
98
|
+
task :rails5 do
|
99
|
+
sh %(
|
100
|
+
npm install &&
|
101
|
+
cd spec/rails5_dummy_app &&
|
102
|
+
rm -rf node_modules/react-webpack-rails &&
|
103
|
+
npm install &&
|
104
|
+
bundle install
|
105
|
+
)
|
61
106
|
end
|
62
107
|
end
|
data/docs/api.md
CHANGED
@@ -108,63 +108,3 @@
|
|
108
108
|
```ruby
|
109
109
|
render react_component: 'MyComponentName', props: MySerializer.new(my_data), tag: :ul, server_side: true
|
110
110
|
```
|
111
|
-
|
112
|
-
|
113
|
-
## ReactRouter
|
114
|
-
* #### registerRouter [js]
|
115
|
-
```js
|
116
|
-
registerRouter(String routerName, class|function component)
|
117
|
-
```
|
118
|
-
|
119
|
-
Register router so it's globally accessible.
|
120
|
-
|
121
|
-
##### example:
|
122
|
-
|
123
|
-
```js
|
124
|
-
import MyComponent from 'my-component';
|
125
|
-
|
126
|
-
registerComponent('MyComponentName', MyComponent);
|
127
|
-
```
|
128
|
-
|
129
|
-
**note:** Registered components are accessible in globally exposed `RWR.reactRouter` under `routers` property.
|
130
|
-
|
131
|
-
* #### getRouter [js]
|
132
|
-
|
133
|
-
```js
|
134
|
-
getRouter(String routerName)
|
135
|
-
```
|
136
|
-
|
137
|
-
Shortcut for accessing registered router.
|
138
|
-
|
139
|
-
##### example:
|
140
|
-
|
141
|
-
```js
|
142
|
-
getRouter('MyRouterName');
|
143
|
-
```
|
144
|
-
|
145
|
-
* #### renderRouter [js]
|
146
|
-
|
147
|
-
```js
|
148
|
-
renderRouter(String routerName, DOMElement container)
|
149
|
-
```
|
150
|
-
|
151
|
-
Wrapper over `React.render`. Search and render given router into specified DOM element.
|
152
|
-
|
153
|
-
##### example:
|
154
|
-
|
155
|
-
```js
|
156
|
-
var element = document.getElementById('my-element');
|
157
|
-
renderRouter('MyRouterName', element);
|
158
|
-
```
|
159
|
-
|
160
|
-
* #### react_router [ruby]
|
161
|
-
|
162
|
-
```ruby
|
163
|
-
react_router(String router_name)
|
164
|
-
```
|
165
|
-
|
166
|
-
##### example:
|
167
|
-
|
168
|
-
```ruby
|
169
|
-
<%= react_router('MyRouterName') %>
|
170
|
-
```
|
data/docs/install_generator.md
CHANGED
@@ -50,7 +50,6 @@ And modify:
|
|
50
50
|
* `--no-hot-reload` - skip hot_reload generator
|
51
51
|
* `--no-server-side` - skip server_side generator
|
52
52
|
* `--no-karma-setup` - skip karma_setup generator
|
53
|
-
* `--react-router` - run react_rotuer generator [DEPRECIATED since v0.3.0 - use [rwr-react_router](https://github.com/netguru/rwr-react_router) instead]
|
54
53
|
* `--redux` - install and setup [`rwr-redux`](https://github.com/netguru/rwr-redux) gem
|
55
54
|
|
56
55
|
*Detailed description of generators coming soon...*
|
data/js/src/index.js
CHANGED
@@ -2,15 +2,12 @@ import env from './env';
|
|
2
2
|
import nodes from './nodes';
|
3
3
|
import integrationsManager from './integrations-manager';
|
4
4
|
import react from './integrations/react';
|
5
|
-
import reactRouter from './integrations/react-router';
|
6
5
|
import version from './version';
|
7
6
|
|
8
7
|
export { react as react };
|
9
8
|
export { nodes as nodes };
|
10
9
|
export { integrationsManager as integrationsManager };
|
11
10
|
export { env as env };
|
12
|
-
export { reactRouter as reactRouter };
|
13
|
-
|
14
11
|
|
15
12
|
class RWR {
|
16
13
|
constructor() {
|
@@ -22,11 +19,6 @@ class RWR {
|
|
22
19
|
this.renderComponent = react.renderComponent;
|
23
20
|
this.unmountComponent = react.unmountComponent;
|
24
21
|
|
25
|
-
this.renderRouter = reactRouter.renderRouter;
|
26
|
-
this.registerRouter = reactRouter.registerRouter;
|
27
|
-
this.unmountRouter = reactRouter.unmountRouter;
|
28
|
-
this.getRouter = reactRouter.getRouter;
|
29
|
-
|
30
22
|
this.mountNodes = nodes.mountNodes;
|
31
23
|
this.unmountNodes = nodes.unmountNodes;
|
32
24
|
}
|
@@ -1,11 +1,9 @@
|
|
1
1
|
import reactIntegration from './integrations/react';
|
2
|
-
import reactRouterIntegration from './integrations/react-router';
|
3
2
|
|
4
3
|
class IntegrationsManager {
|
5
4
|
constructor() {
|
6
5
|
this.integrations = {
|
7
6
|
'react-component': reactIntegration.integrationWrapper,
|
8
|
-
'react-router': reactRouterIntegration.integrationWrapper,
|
9
7
|
};
|
10
8
|
}
|
11
9
|
|
data/js/src/nodes.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import IntegrationsManager from './integrations-manager';
|
2
2
|
|
3
|
-
const ELEMENT_ATTR = 'data-
|
3
|
+
const ELEMENT_ATTR = 'data-rwr-element';
|
4
4
|
const PAYLOAD_ATTR = 'data-payload';
|
5
5
|
const INTEGRATION_NAME_ATTR = 'data-integration-name';
|
6
6
|
const OPTIONS_ATTR = 'data-options';
|
data/js/src/version.js
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export default '0.
|
1
|
+
export default '0.5.0';
|
@@ -1,6 +1,5 @@
|
|
1
1
|
import expect from 'expect';
|
2
2
|
import reactIntegration from '../src/integrations/react';
|
3
|
-
import reactRouterIntegration from '../src/integrations/react-router';
|
4
3
|
import subject from '../src/integrations-manager';
|
5
4
|
|
6
5
|
describe('IntegrationsManager', function () {
|
@@ -9,10 +8,7 @@ describe('IntegrationsManager', function () {
|
|
9
8
|
expect(subject.integrations['react-component']).toEqual(
|
10
9
|
reactIntegration.integrationWrapper
|
11
10
|
);
|
12
|
-
expect(subject.integrations
|
13
|
-
reactRouterIntegration.integrationWrapper
|
14
|
-
);
|
15
|
-
expect(Object.keys(subject.integrations).length).toEqual(2);
|
11
|
+
expect(Object.keys(subject.integrations).length).toEqual(1);
|
16
12
|
});
|
17
13
|
});
|
18
14
|
|
data/js/test/nodes.spec.js
CHANGED
@@ -56,12 +56,12 @@ describe('Nodes', function () {
|
|
56
56
|
};
|
57
57
|
});
|
58
58
|
|
59
|
-
it('uses "data-
|
59
|
+
it('uses "data-rwr-element" as default selector', function () {
|
60
60
|
const documentSpy = spyOn(document, 'querySelectorAll');
|
61
61
|
mountNodes();
|
62
62
|
|
63
63
|
expect(documentSpy.calls.length).toEqual(1);
|
64
|
-
expect(documentSpy).toHaveBeenCalledWith('[data-
|
64
|
+
expect(documentSpy).toHaveBeenCalledWith('[data-rwr-element]');
|
65
65
|
});
|
66
66
|
|
67
67
|
it('mounts nodes', function () {
|
@@ -99,12 +99,12 @@ describe('Nodes', function () {
|
|
99
99
|
};
|
100
100
|
});
|
101
101
|
|
102
|
-
it('uses "data-
|
102
|
+
it('uses "data-rwr-element" as default selector', function () {
|
103
103
|
const documentSpy = spyOn(document, 'querySelectorAll');
|
104
104
|
unmountNodes();
|
105
105
|
|
106
106
|
expect(documentSpy.calls.length).toEqual(1);
|
107
|
-
expect(documentSpy).toHaveBeenCalledWith('[data-
|
107
|
+
expect(documentSpy).toHaveBeenCalledWith('[data-rwr-element]');
|
108
108
|
});
|
109
109
|
|
110
110
|
it('unmounts nodes', function () {
|
@@ -3,51 +3,6 @@ var __RWR_ENV__ = {
|
|
3
3
|
config: <%=JSON(Rails.application.config.react.shared)%>
|
4
4
|
};
|
5
5
|
|
6
|
-
function deprecatedError(helperName) {
|
7
|
-
var lines = [
|
8
|
-
helperName + ' was removed.',
|
9
|
-
'use RWR.' + helperName + ' instead.',
|
10
|
-
'check react_webpack_rails changelog for details.'
|
11
|
-
]
|
12
|
-
console.error(lines.join("\n"));
|
13
|
-
}
|
14
|
-
|
15
|
-
function registerComponent() {
|
16
|
-
deprecatedError('registerComponent');
|
17
|
-
}
|
18
|
-
|
19
|
-
function getComponent() {
|
20
|
-
deprecatedError('getComponent');
|
21
|
-
}
|
22
|
-
|
23
|
-
function createComponent() {
|
24
|
-
deprecatedError('createComponent');
|
25
|
-
}
|
26
|
-
|
27
|
-
function renderComponent() {
|
28
|
-
deprecatedError('renderComponent');
|
29
|
-
}
|
30
|
-
|
31
|
-
function unmountComponent() {
|
32
|
-
deprecatedError('unmountComponent');
|
33
|
-
}
|
34
|
-
|
35
|
-
function renderRouter() {
|
36
|
-
deprecatedError('renderRouter');
|
37
|
-
}
|
38
|
-
|
39
|
-
function registerRouter() {
|
40
|
-
deprecatedError('registerRouter');
|
41
|
-
}
|
42
|
-
|
43
|
-
function unmountRouter() {
|
44
|
-
deprecatedError('unmountRouter');
|
45
|
-
}
|
46
|
-
|
47
|
-
function getRouter() {
|
48
|
-
deprecatedError('getRouter');
|
49
|
-
}
|
50
|
-
|
51
6
|
var RWRhandlers = {
|
52
7
|
_mountNodes: function _mountNodes() {
|
53
8
|
RWR.mountNodes();
|
@@ -63,14 +18,21 @@ var RWRhandlers = {
|
|
63
18
|
|
64
19
|
handleTurbolinksEvents: function handleTurbolinksEvents() {
|
65
20
|
var unmountEvent;
|
21
|
+
var mountEvent;
|
66
22
|
|
67
23
|
if (Turbolinks.EVENTS) {
|
24
|
+
mountEvent = Turbolinks.EVENTS.CHANGE;
|
68
25
|
unmountEvent = Turbolinks.EVENTS.BEFORE_UNLOAD;
|
69
|
-
} else {
|
26
|
+
} else if (typeof Turbolinks.controller !== "undefined") {
|
27
|
+
mountEvent = 'turbolinks:load';
|
28
|
+
unmountEvent = 'turbolinks:before-cache';
|
29
|
+
}
|
30
|
+
else {
|
31
|
+
mountEvent = 'page:change';
|
70
32
|
unmountEvent = 'page:receive';
|
71
33
|
Turbolinks.pagesCached(0);
|
72
34
|
}
|
73
|
-
RWRhandlers._handleEvent(
|
35
|
+
RWRhandlers._handleEvent(mountEvent, RWRhandlers._mountNodes);
|
74
36
|
RWRhandlers._handleEvent(unmountEvent, RWRhandlers._unmountNodes);
|
75
37
|
},
|
76
38
|
|
@@ -19,10 +19,6 @@ module ReactWebpackRails
|
|
19
19
|
type: :boolean,
|
20
20
|
default: true,
|
21
21
|
desc: 'Run karma_setup generator'
|
22
|
-
class_option :react_router,
|
23
|
-
type: :boolean,
|
24
|
-
default: false,
|
25
|
-
desc: 'Run react_router generator'
|
26
22
|
class_option :redux,
|
27
23
|
type: :boolean,
|
28
24
|
default: false,
|
@@ -54,12 +50,6 @@ module ReactWebpackRails
|
|
54
50
|
generate example_generator
|
55
51
|
end
|
56
52
|
|
57
|
-
def generate_react_router
|
58
|
-
return unless options.react_router
|
59
|
-
deprecation_warning
|
60
|
-
generate 'react_webpack_rails:install:react_router --tmp_package'
|
61
|
-
end
|
62
|
-
|
63
53
|
def generate_redux
|
64
54
|
return unless options.redux
|
65
55
|
generate 'react_webpack_rails:install:redux --tmp_package'
|
@@ -1,8 +1,9 @@
|
|
1
1
|
{
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
"uid": "rwr-node-server",
|
3
|
+
"append": true,
|
4
|
+
"script": "node_server.js",
|
5
|
+
"workingDir": "./",
|
6
|
+
"sourceDir": "app/react",
|
7
|
+
"watch": true,
|
8
|
+
"watchDirectory": "app/react"
|
8
9
|
}
|
@@ -1,27 +1,27 @@
|
|
1
1
|
{
|
2
2
|
"private": true,
|
3
3
|
"devDependencies": {
|
4
|
-
"babel-eslint": "^
|
5
|
-
"eslint": "^
|
6
|
-
"eslint-plugin-react": "^
|
7
|
-
"webpack-notifier": "^1.
|
4
|
+
"babel-eslint": "^6.1.0",
|
5
|
+
"eslint": "^2.13.0",
|
6
|
+
"eslint-plugin-react": "^5.2.0",
|
7
|
+
"webpack-notifier": "^1.3.0"
|
8
8
|
},
|
9
9
|
"dependencies": {
|
10
|
-
"babel-core": "^6.
|
11
|
-
"babel-loader": "^6.2.
|
12
|
-
"babel-preset-es2015": "^6.
|
13
|
-
"babel-preset-react": "^6.
|
14
|
-
"babel-preset-stage-1": "^6.
|
15
|
-
"css-loader": "^0.23.
|
16
|
-
"extract-text-webpack-plugin": "^0.
|
17
|
-
"node-sass": "^3.
|
18
|
-
"react": "^15.0
|
19
|
-
"react-addons-test-utils": "^15.0
|
20
|
-
"react-dom": "^15.0
|
21
|
-
"react-webpack-rails": "^0.
|
22
|
-
"sass-loader": "^
|
10
|
+
"babel-core": "^6.10.0",
|
11
|
+
"babel-loader": "^6.2.0",
|
12
|
+
"babel-preset-es2015": "^6.9.0",
|
13
|
+
"babel-preset-react": "^6.11.0",
|
14
|
+
"babel-preset-stage-1": "^6.5.0",
|
15
|
+
"css-loader": "^0.23.0",
|
16
|
+
"extract-text-webpack-plugin": "^1.0.0",
|
17
|
+
"node-sass": "^3.8.0",
|
18
|
+
"react": "^15.1.0",
|
19
|
+
"react-addons-test-utils": "^15.1.0",
|
20
|
+
"react-dom": "^15.1.0",
|
21
|
+
"react-webpack-rails": "^0.5.0",
|
22
|
+
"sass-loader": "^4.0.0",
|
23
23
|
"style-loader": "^0.13.1",
|
24
|
-
"webpack": "^1.
|
24
|
+
"webpack": "^1.13.0"
|
25
25
|
},
|
26
26
|
"scripts": {
|
27
27
|
"start": "webpack -w --config webpack/dev.config.js",
|
@@ -1,14 +1,14 @@
|
|
1
1
|
{
|
2
2
|
"devDependencies": {
|
3
|
-
"expect": "^1.
|
4
|
-
"karma": "^
|
5
|
-
"karma-chrome-launcher": "^0.
|
6
|
-
"karma-mocha": "^
|
7
|
-
"karma-sinon": "^1.0.
|
8
|
-
"karma-sourcemap-loader": "^0.3.
|
3
|
+
"expect": "^1.20.0",
|
4
|
+
"karma": "^1.1.0",
|
5
|
+
"karma-chrome-launcher": "^1.0.0",
|
6
|
+
"karma-mocha": "^1.1.0",
|
7
|
+
"karma-sinon": "^1.0.0",
|
8
|
+
"karma-sourcemap-loader": "^0.3.7",
|
9
9
|
"karma-webpack": "^1.7.0",
|
10
|
-
"mocha": "^2.
|
11
|
-
"sinon": "^1.17.
|
10
|
+
"mocha": "^2.5.0",
|
11
|
+
"sinon": "^1.17.0"
|
12
12
|
},
|
13
13
|
"scripts": {
|
14
14
|
"test": "karma start"
|
@@ -2,33 +2,40 @@ require_relative 'services/camelize_keys'
|
|
2
2
|
|
3
3
|
module ReactWebpackRails
|
4
4
|
module ViewHelpers
|
5
|
-
def
|
5
|
+
def rwr_element(integration_name, payload = {}, html_options = {}, &block)
|
6
6
|
data = {
|
7
7
|
integration_name: integration_name,
|
8
8
|
payload: payload,
|
9
|
-
|
9
|
+
rwr_element: true
|
10
10
|
}
|
11
11
|
html_options = html_options.merge(data: data)
|
12
12
|
html_tag = html_options.delete(:tag) || :div
|
13
13
|
content_tag(html_tag, '', html_options, &block)
|
14
14
|
end
|
15
15
|
|
16
|
+
def react_element(integration_name, payload = {}, html_options = {}, &block)
|
17
|
+
message = 'since v0.5.0: react_element is depricated. Use rwr_element instead'
|
18
|
+
ActiveSupport::Deprecation.warn message
|
19
|
+
|
20
|
+
rwr_element(integration_name, payload, html_options, &block)
|
21
|
+
end
|
22
|
+
|
16
23
|
def react_component(name, raw_props = {}, options = {})
|
17
24
|
props = raw_props.as_json
|
18
25
|
props = Services::CamelizeKeys.call(props) if Rails.application.config.react.camelize_props
|
19
26
|
if server_side(options.delete(:server_side))
|
20
27
|
result = NodeIntegrationRunner.new('react-component', props: props, name: name).run
|
21
|
-
|
28
|
+
rwr_element('react-component', { props: props, name: name }, options) do
|
22
29
|
result.html_safe
|
23
30
|
end
|
24
31
|
else
|
25
|
-
|
32
|
+
rwr_element('react-component', { props: props, name: name }, options)
|
26
33
|
end
|
27
34
|
end
|
28
35
|
|
29
36
|
def react_router(name)
|
30
37
|
deprecation_warning
|
31
|
-
|
38
|
+
rwr_element('react-router', name: name)
|
32
39
|
end
|
33
40
|
|
34
41
|
private
|
data/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-webpack-rails",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.5.0",
|
4
4
|
"description": "Js part of react_webpack_rails - webpack based React & Rails integration.",
|
5
5
|
"main": "js/lib/index.js",
|
6
6
|
"files": [
|
@@ -37,15 +37,15 @@
|
|
37
37
|
"react-dom": "^15.0.1"
|
38
38
|
},
|
39
39
|
"devDependencies": {
|
40
|
-
"babel-cli": "^6.
|
41
|
-
"babel-core": "^6.
|
42
|
-
"babel-preset-es2015": "^6.
|
43
|
-
"babel-preset-react": "^6.
|
44
|
-
"eslint": "^
|
45
|
-
"eslint-config-airbnb": "^
|
46
|
-
"eslint-plugin-react": "^
|
47
|
-
"expect": "^1.
|
48
|
-
"history": "^
|
49
|
-
"mocha": "^2.
|
40
|
+
"babel-cli": "^6.10.0",
|
41
|
+
"babel-core": "^6.10.0",
|
42
|
+
"babel-preset-es2015": "^6.9.0",
|
43
|
+
"babel-preset-react": "^6.11.0",
|
44
|
+
"eslint": "^2.13.0",
|
45
|
+
"eslint-config-airbnb": "^9.0.0",
|
46
|
+
"eslint-plugin-react": "^5.2.0",
|
47
|
+
"expect": "^1.20.0",
|
48
|
+
"history": "^3.0.0",
|
49
|
+
"mocha": "^2.5.0"
|
50
50
|
}
|
51
51
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react_webpack_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rafał Gawlik
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -97,13 +97,11 @@ files:
|
|
97
97
|
- js/src/env.js
|
98
98
|
- js/src/index.js
|
99
99
|
- js/src/integrations-manager.js
|
100
|
-
- js/src/integrations/react-router.js
|
101
100
|
- js/src/integrations/react.js
|
102
101
|
- js/src/nodes.js
|
103
102
|
- js/src/version.js
|
104
103
|
- js/test/env.spec.js
|
105
104
|
- js/test/integrations-manager.spec.js
|
106
|
-
- js/test/integrations/react-router.spec.js
|
107
105
|
- js/test/integrations/react.spec.js
|
108
106
|
- js/test/nodes.spec.js
|
109
107
|
- lib/assets/javascripts/react_integration.js.erb
|
@@ -111,7 +109,6 @@ files:
|
|
111
109
|
- lib/generators/react_webpack_rails/install/example_generator.rb
|
112
110
|
- lib/generators/react_webpack_rails/install/hot_reload_generator.rb
|
113
111
|
- lib/generators/react_webpack_rails/install/karma_setup_generator.rb
|
114
|
-
- lib/generators/react_webpack_rails/install/react_router_generator.rb
|
115
112
|
- lib/generators/react_webpack_rails/install/redux_generator.rb
|
116
113
|
- lib/generators/react_webpack_rails/install/server_side_generator.rb
|
117
114
|
- lib/generators/react_webpack_rails/install_generator.rb
|
@@ -127,7 +124,6 @@ files:
|
|
127
124
|
- lib/generators/react_webpack_rails/templates/packages/core.json
|
128
125
|
- lib/generators/react_webpack_rails/templates/packages/hot-reload.json
|
129
126
|
- lib/generators/react_webpack_rails/templates/packages/js-specs.json
|
130
|
-
- lib/generators/react_webpack_rails/templates/packages/react-router.json
|
131
127
|
- lib/generators/react_webpack_rails/templates/packages/redux.json
|
132
128
|
- lib/generators/react_webpack_rails/templates/packages/server-side.json
|
133
129
|
- lib/generators/react_webpack_rails/templates/partial/_react_hot_assets.html.erb
|
@@ -1,60 +0,0 @@
|
|
1
|
-
import ReactDOM from 'react-dom';
|
2
|
-
|
3
|
-
function deprecationWarning() {
|
4
|
-
if (typeof console !== 'undefined' && console.warn) {
|
5
|
-
const msg = [
|
6
|
-
'Deprecation warning - since v0.3.0: current integration with react-router was extracted and moved to external plugin.',
|
7
|
-
'Use https://github.com/netguru/rwr-react_router instead.',
|
8
|
-
];
|
9
|
-
|
10
|
-
console.warn(msg.join('\n'));
|
11
|
-
}
|
12
|
-
}
|
13
|
-
|
14
|
-
class ReactRouterIntegration {
|
15
|
-
constructor() {
|
16
|
-
this.routers = {};
|
17
|
-
this.enabled = false;
|
18
|
-
this.registerRouter = this.registerRouter.bind(this);
|
19
|
-
this.getRouter = this.getRouter.bind(this);
|
20
|
-
this.renderRouter = this.renderRouter.bind(this);
|
21
|
-
}
|
22
|
-
|
23
|
-
registerRouter(name, route) {
|
24
|
-
deprecationWarning();
|
25
|
-
this.routers[name] = route;
|
26
|
-
}
|
27
|
-
|
28
|
-
getRouter(name) {
|
29
|
-
return this.routers[name];
|
30
|
-
}
|
31
|
-
|
32
|
-
renderRouter(name, node) {
|
33
|
-
if (this.enabled === true) {
|
34
|
-
throw new Error(
|
35
|
-
`Error when rendering ${name}\n\trenderRouter: can't render more than one router.`
|
36
|
-
);
|
37
|
-
}
|
38
|
-
this.enabled = true;
|
39
|
-
ReactDOM.render(this.getRouter(name), node);
|
40
|
-
}
|
41
|
-
|
42
|
-
unmountRouter(node) {
|
43
|
-
ReactDOM.unmountComponentAtNode(node);
|
44
|
-
this.enabled = false;
|
45
|
-
}
|
46
|
-
|
47
|
-
get integrationWrapper() {
|
48
|
-
return {
|
49
|
-
mount: function _mount(node, payload) {
|
50
|
-
this.renderRouter(payload.name, node);
|
51
|
-
}.bind(this),
|
52
|
-
|
53
|
-
unmount: function _unmount(node) {
|
54
|
-
this.unmountRouter(node);
|
55
|
-
}.bind(this),
|
56
|
-
};
|
57
|
-
}
|
58
|
-
}
|
59
|
-
|
60
|
-
export default new ReactRouterIntegration;
|
@@ -1,133 +0,0 @@
|
|
1
|
-
import expect, { spyOn } from 'expect';
|
2
|
-
import ReactDOM from 'react-dom';
|
3
|
-
import subject from '../../src/integrations/react-router';
|
4
|
-
|
5
|
-
const HelloRouter = {};
|
6
|
-
|
7
|
-
describe('ReactIntegration', function () {
|
8
|
-
afterEach(function () {
|
9
|
-
subject.routers = {};
|
10
|
-
subject.enabled = false;
|
11
|
-
});
|
12
|
-
|
13
|
-
describe('.constructor', function () {
|
14
|
-
it('intializes empty components dictionary', function () {
|
15
|
-
expect(subject.routers).toEqual({});
|
16
|
-
});
|
17
|
-
|
18
|
-
it('by default sets router presence flag to false', function () {
|
19
|
-
expect(subject.enabled).toBe(false);
|
20
|
-
});
|
21
|
-
});
|
22
|
-
|
23
|
-
describe('#registerRouter', function () {
|
24
|
-
it('adds router to the routers storage', function () {
|
25
|
-
subject.registerRouter('HelloRouter', HelloRouter);
|
26
|
-
expect(subject.routers.HelloRouter).toBe(HelloRouter);
|
27
|
-
});
|
28
|
-
});
|
29
|
-
|
30
|
-
describe('#getRouter', function () {
|
31
|
-
it('returns route by name', function () {
|
32
|
-
subject.registerRouter('HelloRouter', HelloRouter);
|
33
|
-
expect(subject.getRouter('HelloRouter')).toBe(HelloRouter);
|
34
|
-
});
|
35
|
-
|
36
|
-
it('returns undefined if route is not found', function () {
|
37
|
-
expect(subject.getRouter('HelloRouter')).toBe(undefined);
|
38
|
-
});
|
39
|
-
});
|
40
|
-
|
41
|
-
describe('#renderRouter', function () {
|
42
|
-
beforeEach(function () {
|
43
|
-
subject.registerRouter('HelloRouter', HelloRouter);
|
44
|
-
});
|
45
|
-
|
46
|
-
context('when router is present', function () {
|
47
|
-
it('throws an error', function () {
|
48
|
-
expect(function () {
|
49
|
-
subject.renderRouter('HelloRouter', { node: 'someNode' });
|
50
|
-
})
|
51
|
-
.withContext(subject.enabled = true)
|
52
|
-
.toThrow(/Error when rendering HelloRouter/);
|
53
|
-
});
|
54
|
-
});
|
55
|
-
|
56
|
-
context('when router does not exist', function () {
|
57
|
-
let ReactDOMSpy;
|
58
|
-
const node = { nodeType: 1, nodeName: 'DIV' };
|
59
|
-
beforeEach(function () {
|
60
|
-
ReactDOMSpy = spyOn(ReactDOM, 'render');
|
61
|
-
});
|
62
|
-
|
63
|
-
afterEach(function () {
|
64
|
-
expect.restoreSpies();
|
65
|
-
});
|
66
|
-
|
67
|
-
it('sets router presence flag to true', function () {
|
68
|
-
subject.renderRouter('HelloRouter', node);
|
69
|
-
|
70
|
-
expect(subject.enabled).toBe(true);
|
71
|
-
});
|
72
|
-
|
73
|
-
it('calls ReactDOM renderer once', function () {
|
74
|
-
subject.renderRouter('HelloRouter', { nodeType: 1, nodeName: 'DIV' });
|
75
|
-
|
76
|
-
expect(ReactDOMSpy.calls.length).toEqual(1);
|
77
|
-
expect(ReactDOMSpy).toHaveBeenCalledWith(HelloRouter, { nodeType: 1, nodeName: 'DIV' });
|
78
|
-
});
|
79
|
-
});
|
80
|
-
});
|
81
|
-
|
82
|
-
describe('#unmountRouter', function () {
|
83
|
-
let ReactDOMSpy;
|
84
|
-
beforeEach(function () {
|
85
|
-
ReactDOMSpy = spyOn(ReactDOM, 'unmountComponentAtNode');
|
86
|
-
});
|
87
|
-
|
88
|
-
afterEach(function () {
|
89
|
-
expect.restoreSpies();
|
90
|
-
});
|
91
|
-
|
92
|
-
it('unmounts router component at specified node', function () {
|
93
|
-
subject.unmountRouter({ node: 'someNode' });
|
94
|
-
|
95
|
-
expect(ReactDOMSpy.calls.length).toEqual(1);
|
96
|
-
expect(ReactDOMSpy).toHaveBeenCalledWith({ node: 'someNode' });
|
97
|
-
});
|
98
|
-
|
99
|
-
it('allows to add new router', function () {
|
100
|
-
subject.unmountRouter({ node: 'someNode' });
|
101
|
-
expect(subject.enabled).toBe(false);
|
102
|
-
});
|
103
|
-
});
|
104
|
-
|
105
|
-
describe('#integrationWrapper', function () {
|
106
|
-
const node = { nodeType: 1, nodeName: 'DIV' };
|
107
|
-
|
108
|
-
describe('function mount', function () {
|
109
|
-
it('calls renderComponent', function () {
|
110
|
-
const mountSpy = spyOn(subject, 'renderRouter');
|
111
|
-
|
112
|
-
const payload = { name: 'routerName' };
|
113
|
-
subject.integrationWrapper.mount(node, payload);
|
114
|
-
|
115
|
-
expect(mountSpy.calls.length).toEqual(1);
|
116
|
-
expect(mountSpy).toHaveBeenCalledWith(
|
117
|
-
'routerName',
|
118
|
-
{ nodeType: 1, nodeName: 'DIV' }
|
119
|
-
);
|
120
|
-
});
|
121
|
-
});
|
122
|
-
|
123
|
-
describe('function unmount', function () {
|
124
|
-
it('calls unmountComponent', function () {
|
125
|
-
const unmountSpy = spyOn(subject, 'unmountRouter');
|
126
|
-
subject.integrationWrapper.unmount(node);
|
127
|
-
|
128
|
-
expect(unmountSpy.calls.length).toEqual(1);
|
129
|
-
expect(unmountSpy).toHaveBeenCalledWith({ nodeType: 1, nodeName: 'DIV' });
|
130
|
-
});
|
131
|
-
});
|
132
|
-
});
|
133
|
-
});
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module ReactWebpackRails
|
2
|
-
module Install
|
3
|
-
require 'generators/react_webpack_rails/merge_helpers'
|
4
|
-
|
5
|
-
class ReactRouterGenerator < Rails::Generators::Base
|
6
|
-
include MergeHelpers
|
7
|
-
desc 'Add react-router setup'
|
8
|
-
source_root File.expand_path('../../templates', __FILE__)
|
9
|
-
|
10
|
-
class_option :tmp_package,
|
11
|
-
type: :boolean,
|
12
|
-
default: false,
|
13
|
-
desc: 'Force update tmp/package.json instead package.json'
|
14
|
-
|
15
|
-
def package
|
16
|
-
merge_options = options.tmp_package ? { package_file: 'tmp/package.json', force: true } : {}
|
17
|
-
merge_into_package 'packages/react-router.json', merge_options
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|