render_react 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -8
- data/CHANGELOG.md +4 -0
- data/README.md +19 -9
- data/lib/render_react/context.rb +17 -4
- data/lib/render_react/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 022ec3631f356bb5d1671c49dc061a4068112065d72296769e48f83fc8a6b71e
|
4
|
+
data.tar.gz: e6a47b8643ca49094aa9c72fc1378b8f6549f692d924fa14a4d8b46afee7e3c6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd121aab8734916739e92908591383a049def424bb44f0c177d1ef11037abf0c0d659f0b5a0fa057ff051cfec8fe50767e40cfb4bca3c725d894656eb7744a6e
|
7
|
+
data.tar.gz: 7c4f23e4a48c2ed413deccc9b6e57c265e22eae1d0fb4382331a923103a315f9fdef676b63aef7e21bcbe41126c8114e4cc9067fdf6476a6e434feedb953dce5
|
data/.travis.yml
CHANGED
@@ -2,21 +2,21 @@ sudo: false
|
|
2
2
|
language: ruby
|
3
3
|
|
4
4
|
rvm:
|
5
|
-
-
|
6
|
-
- 2.
|
5
|
+
- ruby-head
|
6
|
+
- 2.5.1
|
7
|
+
- 2.4.4
|
8
|
+
- 2.3.7
|
7
9
|
- 2.2
|
8
10
|
- 2.1
|
9
11
|
- 2.0
|
10
|
-
- jruby-9.1.12.0
|
11
|
-
- ruby-head
|
12
12
|
- jruby-head
|
13
|
-
|
14
|
-
cache:
|
15
|
-
- bundler
|
13
|
+
- jruby-9.1.16.0
|
16
14
|
|
17
15
|
matrix:
|
18
16
|
allow_failures:
|
19
|
-
- rvm: jruby-head
|
20
17
|
- rvm: ruby-head
|
18
|
+
- rvm: 2.2
|
19
|
+
- rvm: 2.1
|
21
20
|
- rvm: 2.0
|
21
|
+
- rvm: jruby-head
|
22
22
|
# fast_finish: true
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -11,7 +11,7 @@ class ExampleComponent extends React.Component {
|
|
11
11
|
```
|
12
12
|
|
13
13
|
```html
|
14
|
-
RenderReact.on_client_and_server("ExampleComponent", { example: "
|
14
|
+
RenderReact.on_client_and_server("ExampleComponent", { example: "!" })
|
15
15
|
# =>
|
16
16
|
<div id="RenderReact-caac405e-1714-495e-aeb4-77b42be42291">
|
17
17
|
<marquee data-reactroot="" data-reactid="1" data-react-checksum="441921122">
|
@@ -19,8 +19,12 @@ RenderReact.on_client_and_server("ExampleComponent", { example: "prop" })
|
|
19
19
|
</marquee>
|
20
20
|
</div>
|
21
21
|
<script>
|
22
|
-
RenderReact.ReactDOM.render(
|
23
|
-
|
22
|
+
RenderReact.ReactDOM.render(
|
23
|
+
RenderReact.React.createElement(
|
24
|
+
RenderReact.components.ExampleComponent, {"example":"!"}
|
25
|
+
),
|
26
|
+
document.getElementById('RenderReact-caac405e-1714-495e-aeb4-77b42be42291')
|
27
|
+
)
|
24
28
|
</script>
|
25
29
|
```
|
26
30
|
|
@@ -42,9 +46,9 @@ gem 'render_react'
|
|
42
46
|
|
43
47
|
```javascript
|
44
48
|
{
|
45
|
-
React: [variable which contains React
|
46
|
-
ReactDOM: [variable which contains ReactDOM,
|
47
|
-
ReactDOMServer: [variable which contains ReactDOMServer
|
49
|
+
React: [variable which contains React],
|
50
|
+
ReactDOM: [variable which contains ReactDOM],
|
51
|
+
ReactDOMServer: [variable which contains ReactDOMServer],
|
48
52
|
components: {
|
49
53
|
ComponentIdentifier1: [variable which contains the component 1],
|
50
54
|
ComponentIdentifier2: [variable which contains the component 2],
|
@@ -53,6 +57,10 @@ gem 'render_react'
|
|
53
57
|
}
|
54
58
|
```
|
55
59
|
|
60
|
+
- Where is **React**? See first paragraph of https://facebook.github.io/react/docs/react-api.html
|
61
|
+
- Where is **ReactDOM**? See first paragraph of https://facebook.github.io/react/docs/react-dom.html
|
62
|
+
- Where is **ReactDOMServer**? See first paragraph of https://facebook.github.io/react/docs/react-dom-server.html
|
63
|
+
|
56
64
|
You can have two different javascript bundle files - one for server rendering, and one for client-rendering.
|
57
65
|
|
58
66
|
- The client bundle has to be included into your application by a method of your choice. You may skip passing in `ReactDOMServer` for the client bundle
|
@@ -77,12 +85,12 @@ export default {
|
|
77
85
|
}
|
78
86
|
```
|
79
87
|
|
80
|
-
|
88
|
+
Gets imported as `RenderReact`
|
81
89
|
|
82
90
|
#### Example (With Browser Globals)
|
83
91
|
|
84
92
|
```javascript
|
85
|
-
window.RenderReact {
|
93
|
+
window.RenderReact = {
|
86
94
|
React: React,
|
87
95
|
ReactDOM: ReactDOM,
|
88
96
|
ReactDOMServer: ReactDOMServer,
|
@@ -100,6 +108,8 @@ Create a **RenderReact** context by passing your server-side JavaScript bundle:
|
|
100
108
|
RenderReact.create_context! File.read('path/to/your/server-bundle.js'), mode: :client_and_server
|
101
109
|
```
|
102
110
|
|
111
|
+
You can use it without a server-side bundle by not passing any file source.
|
112
|
+
|
103
113
|
The optional `mode:` keyword argument can have one of the following values
|
104
114
|
|
105
115
|
- `:client_and_server` (default) - component will be rendered server-side and mounted in the client
|
@@ -124,4 +134,4 @@ RenderReact.on_server("ExampleComponent") # only static
|
|
124
134
|
|
125
135
|
Copyright (C) 2017 Jan Lelis <http://janlelis.com>. Released under the MIT license.
|
126
136
|
|
127
|
-
React is BSD licensed.
|
137
|
+
React is BSD licensed.
|
data/lib/render_react/context.rb
CHANGED
@@ -6,14 +6,19 @@ module RenderReact
|
|
6
6
|
class Context
|
7
7
|
attr_reader :app, :mode
|
8
8
|
|
9
|
-
def initialize(javascript_source =
|
10
|
-
|
11
|
-
|
9
|
+
def initialize(javascript_source = nil, mode: :client_and_server)
|
10
|
+
if javascript_source == nil
|
11
|
+
@app = nil
|
12
|
+
@mode = :client_only
|
13
|
+
else
|
14
|
+
@app = ExecJS.compile(javascript_source)
|
15
|
+
@mode = mode
|
16
|
+
end
|
12
17
|
end
|
13
18
|
|
14
19
|
def render_react(*args)
|
15
20
|
case mode
|
16
|
-
when :client
|
21
|
+
when :client, :client_only
|
17
22
|
on_client(*args)
|
18
23
|
when :server
|
19
24
|
on_server(*args)
|
@@ -32,11 +37,19 @@ module RenderReact
|
|
32
37
|
end
|
33
38
|
|
34
39
|
def on_server(component_name, props_hash = {})
|
40
|
+
if mode == :client_only
|
41
|
+
raise ArgumentError, "Context mode is :client_only, create a server context to be able to use server-side rendering"
|
42
|
+
end
|
43
|
+
|
35
44
|
props_json = JSON.dump(props_hash)
|
36
45
|
app.eval(server_script(component_name, props_json, true))
|
37
46
|
end
|
38
47
|
|
39
48
|
def on_client_and_server(component_name, props_hash = {})
|
49
|
+
if mode == :client_only
|
50
|
+
raise ArgumentError, "Context mode is :client_only, create a server context to be able to use server-side rendering"
|
51
|
+
end
|
52
|
+
|
40
53
|
component_uuid = SecureRandom.uuid
|
41
54
|
props_json = JSON.dump(props_hash)
|
42
55
|
server_rendered = app.eval(server_script(component_name, props_json))
|
data/lib/render_react/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: render_react
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jan Lelis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: execjs
|
@@ -64,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
64
64
|
version: '0'
|
65
65
|
requirements: []
|
66
66
|
rubyforge_project:
|
67
|
-
rubygems_version: 2.
|
67
|
+
rubygems_version: 2.7.3
|
68
68
|
signing_key:
|
69
69
|
specification_version: 4
|
70
70
|
summary: Lo-fi way of rendering React components
|