react-rails 1.3.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +17 -17
- data/lib/react/rails.rb +1 -1
- data/lib/react/rails/component_mount.rb +1 -1
- data/lib/react/rails/controller_lifecycle.rb +24 -0
- data/lib/react/rails/controller_renderer.rb +2 -2
- data/lib/react/rails/railtie.rb +7 -2
- data/lib/react/rails/version.rb +1 -1
- data/lib/react/rails/view_helper.rb +3 -4
- metadata +3 -3
- data/lib/react/rails/render_middleware.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f334d2c029d0618856f87380e5f383c41dd1de3d
|
4
|
+
data.tar.gz: a99014219803125228a7c01f7b4fce09beab20a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 179cef5ad9262a265d2c985a54c4f54e064b87aa7078382080fd18dab01dd243dc63257eefdc41d945d71f2ab5fd896fecfd07c55d03ce66c71a376e51ab438a
|
7
|
+
data.tar.gz: deb80234836320e2cf829ea0b1de79a22473598054d4356af10c0255a36b275e73f247a4d115ec484ec462809ba51f722507d423ca39971ed83abcb8f921bcc1
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ rails g react:install
|
|
34
34
|
```
|
35
35
|
|
36
36
|
This will:
|
37
|
-
- create a `components.js` manifest file and a `app/assets/javascripts/components/` directory,
|
37
|
+
- create a `components.js` manifest file and a `app/assets/javascripts/components/` directory,
|
38
38
|
where you will put your components
|
39
39
|
- place the following in your `application.js`:
|
40
40
|
|
@@ -48,7 +48,7 @@ where you will put your components
|
|
48
48
|
|
49
49
|
### React.js builds
|
50
50
|
|
51
|
-
You can pick which React.js build (development, production, with or without [add-ons]((http://facebook.github.io/react/docs/addons.html)))
|
51
|
+
You can pick which React.js build (development, production, with or without [add-ons]((http://facebook.github.io/react/docs/addons.html)))
|
52
52
|
to serve in each environment by adding a config. Here are the defaults:
|
53
53
|
|
54
54
|
```ruby
|
@@ -71,10 +71,10 @@ MyApp::Application.configure do
|
|
71
71
|
end
|
72
72
|
```
|
73
73
|
|
74
|
-
After restarting your Rails server, `//= require react` will provide the build of React.js which
|
74
|
+
After restarting your Rails server, `//= require react` will provide the build of React.js which
|
75
75
|
was specified by the configurations.
|
76
76
|
|
77
|
-
`react-rails` offers a few other options for versions & builds of React.js.
|
77
|
+
`react-rails` offers a few other options for versions & builds of React.js.
|
78
78
|
See [VERSIONS.md](https://github.com/reactjs/react-rails/blob/master/VERSIONS.md) for more info about
|
79
79
|
using the `react-source` gem or dropping in your own copies of React.js.
|
80
80
|
|
@@ -121,7 +121,7 @@ config.react.jsx_transform_options = {
|
|
121
121
|
|
122
122
|
### Rendering & mounting
|
123
123
|
|
124
|
-
`react-rails` includes a view helper (`react_component`) and an unobtrusive JavaScript driver (`react_ujs`)
|
124
|
+
`react-rails` includes a view helper (`react_component`) and an unobtrusive JavaScript driver (`react_ujs`)
|
125
125
|
which work together to put React components on the page. You should require the UJS driver
|
126
126
|
in your manifest after `react` (and after `turbolinks` if you use [Turbolinks](https://github.com/rails/turbolinks)).
|
127
127
|
|
@@ -133,7 +133,7 @@ The __view helper__ puts a `div` on the page with the requested component class
|
|
133
133
|
<div data-react-class="HelloMessage" data-react-props="{"name":"John"}"></div>
|
134
134
|
```
|
135
135
|
|
136
|
-
On page load, the __`react_ujs` driver__ will scan the page and mount components using `data-react-class`
|
136
|
+
On page load, the __`react_ujs` driver__ will scan the page and mount components using `data-react-class`
|
137
137
|
and `data-react-props`.
|
138
138
|
|
139
139
|
If Turbolinks is present components are mounted on the `page:change` event, and unmounted on `page:before-unload`.
|
@@ -169,9 +169,9 @@ _(It will be also be mounted by the UJS on page load.)_
|
|
169
169
|
|
170
170
|
There are some requirements for this to work:
|
171
171
|
|
172
|
-
- `react-rails` must load your code. By convention it uses `components.js`, which was created
|
172
|
+
- `react-rails` must load your code. By convention it uses `components.js`, which was created
|
173
173
|
by the install task. This file must include your components _and_ their dependencies (eg, Underscore.js).
|
174
|
-
- Your components must be accessible in the global scope.
|
174
|
+
- Your components must be accessible in the global scope.
|
175
175
|
If you are using `.js.jsx.coffee` files then the wrapper function needs to be taken into account:
|
176
176
|
|
177
177
|
```coffee
|
@@ -180,7 +180,7 @@ If you are using `.js.jsx.coffee` files then the wrapper function needs to be ta
|
|
180
180
|
render: ->
|
181
181
|
`<ExampleComponent videos={this.props.videos} />`
|
182
182
|
```
|
183
|
-
- Your code can't reference `document`. Prerender processes don't have access to `document`,
|
183
|
+
- Your code can't reference `document`. Prerender processes don't have access to `document`,
|
184
184
|
so jQuery and some other libs won't work in this environment :(
|
185
185
|
|
186
186
|
You can configure your pool of JS virtual machines and specify where it should load code:
|
@@ -222,10 +222,10 @@ By default, your current layout will be used and the component, rather than a vi
|
|
222
222
|
|
223
223
|
### Component generator
|
224
224
|
|
225
|
-
`react-rails` ships with a Rails generator to help you get started with a simple component scaffold.
|
226
|
-
You can run it using `rails generate react:component ComponentName (--es6)`.
|
227
|
-
The generator takes an optional list of arguments for default propTypes,
|
228
|
-
which follow the conventions set in the [Reusable Components](http://facebook.github.io/react/docs/reusable-components.html)
|
225
|
+
`react-rails` ships with a Rails generator to help you get started with a simple component scaffold.
|
226
|
+
You can run it using `rails generate react:component ComponentName (--es6)`.
|
227
|
+
The generator takes an optional list of arguments for default propTypes,
|
228
|
+
which follow the conventions set in the [Reusable Components](http://facebook.github.io/react/docs/reusable-components.html)
|
229
229
|
section of the React documentation.
|
230
230
|
|
231
231
|
For example:
|
@@ -294,7 +294,7 @@ Note that the arguments for `oneOf` and `oneOfType` must be enclosed in single q
|
|
294
294
|
|
295
295
|
### Jbuilder & react-rails
|
296
296
|
|
297
|
-
If you use Jbuilder to pass a JSON string to `react_component`, make sure your JSON is a stringified hash,
|
297
|
+
If you use Jbuilder to pass a JSON string to `react_component`, make sure your JSON is a stringified hash,
|
298
298
|
not an array. This is not the Rails default -- you should add the root node yourself. For example:
|
299
299
|
|
300
300
|
```ruby
|
@@ -313,7 +313,7 @@ end
|
|
313
313
|
|
314
314
|
## CoffeeScript
|
315
315
|
|
316
|
-
It is possible to use JSX with CoffeeScript. To use CoffeeScript, create files with an extension `.js.jsx.coffee`.
|
316
|
+
It is possible to use JSX with CoffeeScript. To use CoffeeScript, create files with an extension `.js.jsx.coffee`.
|
317
317
|
We also need to embed JSX code inside backticks so that CoffeeScript ignores the syntax it doesn't understand.
|
318
318
|
Here's an example:
|
319
319
|
|
@@ -348,8 +348,8 @@ Any subclass of `ExecJSRenderer` may use those hooks (for example, `SprocketsRen
|
|
348
348
|
`react-rails` uses a "helper implementation" class to generate the output of the `react_component` helper. The helper is initialized once per request and used for each `react_component` call during that request. You can provide a custom helper class to `config.react.view_helper_implementation`. The class must implement:
|
349
349
|
|
350
350
|
- `#react_component(name, props = {}, options = {}, &block)` to return a string to inject into the Rails view
|
351
|
-
- `#setup(
|
352
|
-
- `#teardown(
|
351
|
+
- `#setup(controller_instance)`, called when the helper is initialized at the start of the request
|
352
|
+
- `#teardown(controller_instance)`, called at the end of the request
|
353
353
|
|
354
354
|
`react-rails` provides one implementation, `React::Rails::ComponentMount`.
|
355
355
|
|
data/lib/react/rails.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'react/rails/asset_variant'
|
2
2
|
require 'react/rails/engine'
|
3
3
|
require 'react/rails/railtie'
|
4
|
-
require 'react/rails/
|
4
|
+
require 'react/rails/controller_lifecycle'
|
5
5
|
require 'react/rails/version'
|
6
6
|
require 'react/rails/component_mount'
|
7
7
|
require 'react/rails/view_helper'
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module React
|
2
|
+
module Rails
|
3
|
+
module ControllerLifecycle
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
# use old names to support Rails 3
|
8
|
+
before_filter :setup_react_component_helper
|
9
|
+
after_filter :teardown_react_component_helper
|
10
|
+
attr_reader :__react_component_helper
|
11
|
+
end
|
12
|
+
|
13
|
+
def setup_react_component_helper
|
14
|
+
new_helper = React::Rails::ViewHelper.helper_implementation_class.new
|
15
|
+
new_helper.setup(self)
|
16
|
+
@__react_component_helper = new_helper
|
17
|
+
end
|
18
|
+
|
19
|
+
def teardown_react_component_helper
|
20
|
+
@__react_component_helper.teardown(self)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -5,9 +5,9 @@ class React::Rails::ControllerRenderer
|
|
5
5
|
|
6
6
|
attr_accessor :output_buffer
|
7
7
|
|
8
|
-
attr_reader :request
|
9
8
|
def initialize(options={})
|
10
|
-
|
9
|
+
controller = options[:controller]
|
10
|
+
@__react_component_helper = controller.__react_component_helper
|
11
11
|
end
|
12
12
|
|
13
13
|
def call(name, options, &block)
|
data/lib/react/rails/railtie.rb
CHANGED
@@ -24,13 +24,18 @@ module React
|
|
24
24
|
|
25
25
|
# Include the react-rails view helper lazily
|
26
26
|
initializer "react_rails.setup_view_helpers", group: :all do |app|
|
27
|
-
|
27
|
+
|
28
28
|
app.config.react.jsx_transformer_class ||= React::JSX::DEFAULT_TRANSFORMER
|
29
29
|
React::JSX.transformer_class = app.config.react.jsx_transformer_class
|
30
30
|
React::JSX.transform_options = app.config.react.jsx_transform_options
|
31
31
|
|
32
32
|
app.config.react.view_helper_implementation ||= React::Rails::ComponentMount
|
33
33
|
React::Rails::ViewHelper.helper_implementation_class = app.config.react.view_helper_implementation
|
34
|
+
|
35
|
+
ActiveSupport.on_load(:action_controller) do
|
36
|
+
include ::React::Rails::ControllerLifecycle
|
37
|
+
end
|
38
|
+
|
34
39
|
ActiveSupport.on_load(:action_view) do
|
35
40
|
include ::React::Rails::ViewHelper
|
36
41
|
end
|
@@ -38,7 +43,7 @@ module React
|
|
38
43
|
|
39
44
|
initializer "react_rails.add_component_renderer", group: :all do |app|
|
40
45
|
ActionController::Renderers.add :component do |component_name, options|
|
41
|
-
renderer = ::React::Rails::ControllerRenderer.new(
|
46
|
+
renderer = ::React::Rails::ControllerRenderer.new(controller: self)
|
42
47
|
html = renderer.call(component_name, options)
|
43
48
|
render_options = options.merge(inline: html)
|
44
49
|
render(render_options)
|
data/lib/react/rails/version.rb
CHANGED
@@ -3,15 +3,14 @@ module React
|
|
3
3
|
module ViewHelper
|
4
4
|
# This class will be used for inserting tags into HTML.
|
5
5
|
# It should implement:
|
6
|
-
# - #setup(
|
7
|
-
# - #teardown(
|
6
|
+
# - #setup(controller_instance)
|
7
|
+
# - #teardown(controller_instance)
|
8
8
|
# - #react_component(name, props, options &block)
|
9
9
|
# The default is {React::Rails::ComponentMount}
|
10
10
|
mattr_accessor :helper_implementation_class
|
11
11
|
|
12
12
|
def react_component(*args, &block)
|
13
|
-
|
14
|
-
helper_obj = request.env[impl_key]
|
13
|
+
helper_obj = @__react_component_helper
|
15
14
|
helper_obj.react_component(*args, &block)
|
16
15
|
end
|
17
16
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: react-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul O’Shannessy
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|
@@ -271,10 +271,10 @@ files:
|
|
271
271
|
- lib/react/jsx.rb
|
272
272
|
- lib/react/rails/asset_variant.rb
|
273
273
|
- lib/react/rails/component_mount.rb
|
274
|
+
- lib/react/rails/controller_lifecycle.rb
|
274
275
|
- lib/react/rails/controller_renderer.rb
|
275
276
|
- lib/react/rails/engine.rb
|
276
277
|
- lib/react/rails/railtie.rb
|
277
|
-
- lib/react/rails/render_middleware.rb
|
278
278
|
- lib/react/rails/version.rb
|
279
279
|
- lib/react/rails/view_helper.rb
|
280
280
|
- lib/react/rails.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module React
|
2
|
-
module Rails
|
3
|
-
class RenderMiddleware
|
4
|
-
HELPER_IMPLEMENTATION_KEY = "react_rails.view_helper_implementation"
|
5
|
-
def initialize(app)
|
6
|
-
@app = app
|
7
|
-
end
|
8
|
-
|
9
|
-
def call(env)
|
10
|
-
new_helper = React::Rails::ViewHelper.helper_implementation_class.new
|
11
|
-
new_helper.setup(env)
|
12
|
-
env[HELPER_IMPLEMENTATION_KEY] = new_helper
|
13
|
-
response = @app.call(env)
|
14
|
-
new_helper.teardown(env)
|
15
|
-
response
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|