reactive-router 0.2.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/reactive-router.rb +1 -0
- data/lib/reactive-router/router.rb +41 -12
- data/lib/reactive-router/version.rb +1 -1
- data/lib/reactive-router/window_location.rb +13 -0
- metadata +3 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 76464038f9ab3477f15cfa11a50f726339a2488f
|
4
|
+
data.tar.gz: c9a74c8523720d3e0d60dee87145e13b2285ed27
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6e49d2cad407f11eaf7069fd3da3ac057442236b040a5bd8cc0da838f5d7895318feac5964b21f6c106ab090cfeb413aefd3f5d67ff00c66c1ec6c76397bcfaa
|
7
|
+
data.tar.gz: 26ffb6cd930963f45bac01f83de27dd8dd9531266dbb8a7b3d16aa19e8e071da97426d1f68659a9042ae6a744d408d23c0271747e0c6c697571e92ebb38c3f08
|
data/lib/reactive-router.rb
CHANGED
@@ -10,11 +10,37 @@ module React
|
|
10
10
|
base.class_eval do
|
11
11
|
|
12
12
|
include React::Component
|
13
|
+
include React::IsomorphicHelpers
|
14
|
+
|
15
|
+
before_first_mount do |context|
|
16
|
+
if `typeof ReactRouter === 'undefined'`
|
17
|
+
if on_opal_client?
|
18
|
+
message = "ReactRouter not defined in browser assets - you must manually include it in your assets"
|
19
|
+
else
|
20
|
+
message = "ReactRouter not defined in components.js.rb assets manifest - you must manually include it in your assets"
|
21
|
+
end
|
22
|
+
`console.error(message)`
|
23
|
+
@routing = true
|
24
|
+
else
|
25
|
+
@routing = false
|
26
|
+
end
|
27
|
+
end
|
13
28
|
|
14
29
|
export_component
|
15
30
|
|
16
31
|
def render
|
17
|
-
|
32
|
+
if self.class.routing?
|
33
|
+
show
|
34
|
+
elsif on_opal_server?
|
35
|
+
self.class.routing!
|
36
|
+
routes = self.class.build_routes
|
37
|
+
%x{
|
38
|
+
ReactRouter.run(#{routes}, window.reactive_router_static_location, function(root) {
|
39
|
+
self.root = React.createElement(root);
|
40
|
+
});
|
41
|
+
}
|
42
|
+
React::Element.new(@root, 'Root', {}, nil)
|
43
|
+
end
|
18
44
|
end
|
19
45
|
|
20
46
|
def self.routing?
|
@@ -27,30 +53,33 @@ module React
|
|
27
53
|
was_routing
|
28
54
|
end
|
29
55
|
|
30
|
-
def self.handler(handler)
|
31
|
-
React::API.create_native_react_class(handler)
|
32
|
-
end
|
33
|
-
|
34
56
|
after_mount do
|
35
57
|
unless self.class.routing!
|
36
|
-
|
37
|
-
routes = self.class.
|
58
|
+
dom_node = `React.findDOMNode(#{self}.native)`
|
59
|
+
routes = self.class.build_routes
|
38
60
|
%x{
|
39
61
|
ReactRouter.run(#{routes}, ReactRouter.HistoryLocation, function(root) {
|
40
|
-
React.render(React.createElement(root), #{
|
62
|
+
React.render(React.createElement(root), #{dom_node});
|
41
63
|
});
|
42
64
|
}
|
43
65
|
end
|
44
66
|
end
|
45
67
|
|
46
68
|
def self.routes(opts = {}, &block)
|
47
|
-
|
48
|
-
@
|
69
|
+
@routes_opts = opts
|
70
|
+
@routes_block = block
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.build_routes
|
74
|
+
routes_opts = @routes_opts.dup
|
75
|
+
routes_opts[:handler] ||= self
|
76
|
+
route(routes_opts, generate_node = true, &@routes_block)
|
49
77
|
end
|
50
78
|
|
51
79
|
def self.route(opts = {}, generate_node = nil, &block)
|
52
|
-
opts
|
53
|
-
|
80
|
+
opts = opts.dup
|
81
|
+
opts[:handler] = React::API.create_native_react_class(opts[:handler])
|
82
|
+
(generate_node ? RR::Route_as_node(opts, &block) : RR::Route(opts, &block))
|
54
83
|
end
|
55
84
|
|
56
85
|
def self.default_route(ops = {}, &block)
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module React
|
2
|
+
module Router
|
3
|
+
class WindowLocation
|
4
|
+
|
5
|
+
include React::IsomorphicHelpers
|
6
|
+
|
7
|
+
before_first_mount do |context|
|
8
|
+
context.eval("window.reactive_router_static_location = '#{context.controller.request.path}?#{context.controller.request.query_string}'")
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: reactive-router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam George
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
11
|
+
date: 2015-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: react-router-rails
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: 0.13.3
|
76
|
-
type: :runtime
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: 0.13.3
|
83
69
|
description: Adds the ability to write and use the react-router in Ruby through Opal
|
84
70
|
email:
|
85
71
|
- adamgeorge.31@gmail.com
|
@@ -94,6 +80,7 @@ files:
|
|
94
80
|
- lib/reactive-router/component.rb
|
95
81
|
- lib/reactive-router/router.rb
|
96
82
|
- lib/reactive-router/version.rb
|
83
|
+
- lib/reactive-router/window_location.rb
|
97
84
|
homepage:
|
98
85
|
licenses: []
|
99
86
|
metadata: {}
|