hyper-router 4.0.0 → 4.0.1
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/README.md +33 -3
- data/lib/hyper-router.rb +1 -5
- data/lib/hyper-router/class_methods.rb +42 -20
- data/lib/hyper-router/history.rb +4 -1
- data/lib/hyper-router/instance_methods.rb +11 -0
- data/lib/hyper-router/version.rb +1 -1
- data/lib/hyperloop/router.rb +5 -5
- data/lib/hyperloop/router/base.rb +1 -1
- data/lib/hyperloop/router/browser.rb +2 -1
- data/lib/hyperloop/router/component.rb +1 -1
- data/lib/hyperloop/router/hash.rb +4 -3
- data/lib/hyperloop/router/memory.rb +3 -2
- data/lib/hyperloop/router/static.rb +8 -1
- metadata +4 -8
- data/lib/hyperloop/router/base/class_methods.rb +0 -21
- data/lib/hyperloop/router/browser/class_methods.rb +0 -15
- data/lib/hyperloop/router/hash/class_methods.rb +0 -15
- data/lib/hyperloop/router/memory/class_methods.rb +0 -15
- data/lib/hyperloop/router/static/class_methods.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6e5fcad96836cef5e80a04939e0a50ffc6884584
|
4
|
+
data.tar.gz: 7728921b4f4f45a9b60a9e8e22eac90cd6ad86cb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a3f6ab32532f2b455e17539b8ee74b93192239a55fd64eb5d190ee1419b872b47026375939c9fc49e13855081492ab2ac894dde68ae34543db609eeffe4c546
|
7
|
+
data.tar.gz: a25595ed8d84964d8df069cfcb57f9e4f7688a4b73eee454dc7526f90dde1d63bb1c817affa16543cb3b4510f3cd0f7548bc85c0b0a808f5d1a4d8d060d69a5d
|
data/README.md
CHANGED
@@ -1,6 +1,17 @@
|
|
1
|
-
|
1
|
+
<p align="center">
|
2
|
+
<a href="http://ruby-hyperloop.io/" alt="Hyperloop" title="Hyperloop">
|
3
|
+
<img src="https://github.com/ruby-hyperloop/ruby-hyperloop.io/blob/sprint/source/images/HyperRouter.png" width="150px"/>
|
4
|
+
</a>
|
5
|
+
</p>
|
6
|
+
|
7
|
+
<h1 align="center">
|
8
|
+
HyperRouter
|
9
|
+
</h1>
|
10
|
+
|
11
|
+
<p align="center">
|
12
|
+
HyperRouter allows you write and use the React Router in Ruby through Opal.
|
13
|
+
</p>
|
2
14
|
|
3
|
-
HyperRouter allows you write and use the React Router in Ruby through Opal.
|
4
15
|
|
5
16
|
## Installation
|
6
17
|
|
@@ -201,7 +212,7 @@ class MyRouter < Hyperloop::Router
|
|
201
212
|
end
|
202
213
|
```
|
203
214
|
|
204
|
-
### BrowserRouter, HashRouter, MemoryRouter
|
215
|
+
### BrowserRouter, HashRouter, MemoryRouter
|
205
216
|
|
206
217
|
Using one of these classes automatically takes care of the history for you,
|
207
218
|
so you don't need to specify one.
|
@@ -216,6 +227,25 @@ class MyRouter < React::Component::Base
|
|
216
227
|
end
|
217
228
|
```
|
218
229
|
|
230
|
+
### StaticRouter
|
231
|
+
|
232
|
+
Static router is a little different, since it doesn't actually have a history.
|
233
|
+
These are used under-the-hood for any other Router during prerendering.
|
234
|
+
To use a path with a StaticRouter, with the macro `initial_path`.
|
235
|
+
This acts the same as `prerender_path` for other routers.
|
236
|
+
|
237
|
+
```ruby
|
238
|
+
class MyRouter < Hyperloop::StaticRouter
|
239
|
+
initial_path :current_path
|
240
|
+
|
241
|
+
route do
|
242
|
+
DIV do
|
243
|
+
Route('/:name', mounts: Greet)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
```
|
248
|
+
|
219
249
|
### Rendering a Router
|
220
250
|
|
221
251
|
To render children/routes use the `route` macro, it is the equivalent to `render` of a component.
|
data/lib/hyper-router.rb
CHANGED
@@ -30,12 +30,8 @@ IF USING NPM/WEBPACK:
|
|
30
30
|
require 'hyper-router/match'
|
31
31
|
require 'hyper-router/class_methods'
|
32
32
|
require 'hyper-router/component_methods'
|
33
|
+
require 'hyper-router/instance_methods'
|
33
34
|
|
34
|
-
require 'hyperloop/router/base/class_methods'
|
35
|
-
require 'hyperloop/router/browser/class_methods'
|
36
|
-
require 'hyperloop/router/hash/class_methods'
|
37
|
-
require 'hyperloop/router/memory/class_methods'
|
38
|
-
require 'hyperloop/router/static/class_methods'
|
39
35
|
require 'hyperloop/router/base'
|
40
36
|
require 'hyperloop/router/browser'
|
41
37
|
require 'hyperloop/router/component'
|
@@ -1,43 +1,41 @@
|
|
1
1
|
module HyperRouter
|
2
|
+
class NoHistoryError < StandardError; end
|
3
|
+
|
2
4
|
module ClassMethods
|
3
|
-
def
|
5
|
+
def initial_path(*args)
|
4
6
|
name = args[0].is_a?(Hash) ? args[0].first[0] : args[0]
|
5
7
|
|
6
|
-
define_method(:
|
8
|
+
define_method(:initial_path) do
|
7
9
|
params.send(:"#{name}")
|
8
10
|
end
|
9
11
|
|
10
12
|
param(*args)
|
11
13
|
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
15
|
+
alias prerender_path initial_path
|
16
|
+
|
17
|
+
def history(*args)
|
18
|
+
if args.count > 0
|
19
|
+
@__history_type = args.first
|
20
|
+
elsif @__history_type
|
21
|
+
@__history ||= send(:"#{@__history_type}_history")
|
16
22
|
end
|
17
23
|
end
|
18
24
|
|
19
|
-
def
|
20
|
-
|
21
|
-
location = {}.tap do |hash|
|
22
|
-
pathname, search = (respond_to?(:prerender_path) ? prerender_path : '').split('?', 2)
|
23
|
-
hash[:pathname] = pathname
|
24
|
-
hash[:search] = search ? "?#{search}" : ''
|
25
|
-
end
|
26
|
-
|
27
|
-
React::Router::StaticRouter(location: location.to_n, context: {}.to_n) do
|
28
|
-
instance_eval(&block)
|
29
|
-
end
|
30
|
-
end
|
25
|
+
def location
|
26
|
+
Location.new(`#{history.to_n}.location`)
|
31
27
|
end
|
32
28
|
|
33
29
|
def route(&block)
|
34
|
-
if React::IsomorphicHelpers.
|
35
|
-
render_router(&block)
|
36
|
-
else
|
30
|
+
if React::IsomorphicHelpers.on_opal_server?
|
37
31
|
prerender_router(&block)
|
32
|
+
else
|
33
|
+
render_router(&block)
|
38
34
|
end
|
39
35
|
end
|
40
36
|
|
37
|
+
private
|
38
|
+
|
41
39
|
def browser_history
|
42
40
|
React::Router::History.current.create_browser_history
|
43
41
|
end
|
@@ -49,5 +47,29 @@ module HyperRouter
|
|
49
47
|
def memory_history(*args)
|
50
48
|
React::Router::History.current.create_memory_history(*args)
|
51
49
|
end
|
50
|
+
|
51
|
+
def render_router(&block)
|
52
|
+
define_method(:render) do
|
53
|
+
raise(HyperRouter::NoHistoryError, 'A history must be defined') unless history
|
54
|
+
|
55
|
+
React::Router::Router(history: history.to_n) do
|
56
|
+
instance_eval(&block)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def prerender_router(&block)
|
62
|
+
define_method(:render) do
|
63
|
+
location = {}.tap do |hash|
|
64
|
+
pathname, search = (respond_to?(:initial_path) ? initial_path : '').split('?', 2)
|
65
|
+
hash[:pathname] = pathname
|
66
|
+
hash[:search] = search ? "?#{search}" : ''
|
67
|
+
end
|
68
|
+
|
69
|
+
React::Router::StaticRouter(location: location.to_n, context: {}.to_n) do
|
70
|
+
instance_eval(&block)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
52
74
|
end
|
53
75
|
end
|
data/lib/hyper-router/history.rb
CHANGED
@@ -10,12 +10,15 @@ module HyperRouter
|
|
10
10
|
@native
|
11
11
|
end
|
12
12
|
|
13
|
+
def location
|
14
|
+
HyperRouter::Location.new(`#{@native}.location`)
|
15
|
+
end
|
16
|
+
|
13
17
|
alias_native :block
|
14
18
|
alias_native :create_href, :createHref
|
15
19
|
alias_native :go
|
16
20
|
alias_native :go_back, :goBack
|
17
21
|
alias_native :go_forward, :goForward
|
18
|
-
alias_native :location, :location
|
19
22
|
alias_native :push, :push
|
20
23
|
alias_native :replace, :replace
|
21
24
|
end
|
data/lib/hyper-router/version.rb
CHANGED
data/lib/hyperloop/router.rb
CHANGED
@@ -1,35 +1,35 @@
|
|
1
1
|
module Hyperloop
|
2
2
|
class Router
|
3
3
|
def self.inherited(child)
|
4
|
-
child.include(
|
4
|
+
child.include(Hyperloop::Component::Mixin)
|
5
5
|
child.include(Base)
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
9
|
class BrowserRouter
|
10
10
|
def self.inherited(child)
|
11
|
-
child.include(
|
11
|
+
child.include(Hyperloop::Component::Mixin)
|
12
12
|
child.include(Hyperloop::Router::Browser)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
class HashRouter
|
17
17
|
def self.inherited(child)
|
18
|
-
child.include(
|
18
|
+
child.include(Hyperloop::Component::Mixin)
|
19
19
|
child.include(Hyperloop::Router::Hash)
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
class MemoryRouter
|
24
24
|
def self.inherited(child)
|
25
|
-
child.include(
|
25
|
+
child.include(Hyperloop::Component::Mixin)
|
26
26
|
child.include(Hyperloop::Router::Memory)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
30
30
|
class StaticRouter
|
31
31
|
def self.inherited(child)
|
32
|
-
child.include(
|
32
|
+
child.include(Hyperloop::Component::Mixin)
|
33
33
|
child.include(Hyperloop::Router::Static)
|
34
34
|
end
|
35
35
|
end
|
@@ -1,10 +1,11 @@
|
|
1
1
|
module Hyperloop
|
2
2
|
class Router
|
3
|
-
module
|
3
|
+
module Hash
|
4
4
|
def self.included(base)
|
5
5
|
base.extend(HyperRouter::ClassMethods)
|
6
|
-
base.
|
7
|
-
|
6
|
+
base.history(:hash)
|
7
|
+
|
8
|
+
base.include(HyperRouter::InstanceMethods)
|
8
9
|
base.include(HyperRouter::ComponentMethods)
|
9
10
|
end
|
10
11
|
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
module Hyperloop
|
2
2
|
class Router
|
3
3
|
module Static
|
4
|
+
module ClassMethods
|
5
|
+
def route(&block)
|
6
|
+
prerender_router(&block)
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
4
10
|
def self.included(base)
|
5
11
|
base.extend(HyperRouter::ClassMethods)
|
6
12
|
base.extend(ClassMethods)
|
7
|
-
|
13
|
+
|
14
|
+
base.include(HyperRouter::InstanceMethods)
|
8
15
|
base.include(HyperRouter::ComponentMethods)
|
9
16
|
end
|
10
17
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hyper-router
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.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: 2017-03-
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hyper-component
|
@@ -486,22 +486,18 @@ files:
|
|
486
486
|
- lib/hyper-router/class_methods.rb
|
487
487
|
- lib/hyper-router/component_methods.rb
|
488
488
|
- lib/hyper-router/history.rb
|
489
|
+
- lib/hyper-router/instance_methods.rb
|
489
490
|
- lib/hyper-router/location.rb
|
490
491
|
- lib/hyper-router/match.rb
|
491
492
|
- lib/hyper-router/react-router-source.rb
|
492
493
|
- lib/hyper-router/version.rb
|
493
494
|
- lib/hyperloop/router.rb
|
494
495
|
- lib/hyperloop/router/base.rb
|
495
|
-
- lib/hyperloop/router/base/class_methods.rb
|
496
496
|
- lib/hyperloop/router/browser.rb
|
497
|
-
- lib/hyperloop/router/browser/class_methods.rb
|
498
497
|
- lib/hyperloop/router/component.rb
|
499
498
|
- lib/hyperloop/router/hash.rb
|
500
|
-
- lib/hyperloop/router/hash/class_methods.rb
|
501
499
|
- lib/hyperloop/router/memory.rb
|
502
|
-
- lib/hyperloop/router/memory/class_methods.rb
|
503
500
|
- lib/hyperloop/router/static.rb
|
504
|
-
- lib/hyperloop/router/static/class_methods.rb
|
505
501
|
- lib/react/router.rb
|
506
502
|
- lib/react/router/dom.rb
|
507
503
|
- lib/react/router/history.rb
|
@@ -527,7 +523,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
527
523
|
version: '0'
|
528
524
|
requirements: []
|
529
525
|
rubyforge_project:
|
530
|
-
rubygems_version: 2.5.
|
526
|
+
rubygems_version: 2.5.2
|
531
527
|
signing_key:
|
532
528
|
specification_version: 4
|
533
529
|
summary: react-router for Opal, part of the hyperloop gem family
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module Hyperloop
|
2
|
-
class Router
|
3
|
-
module Base
|
4
|
-
module ClassMethods
|
5
|
-
def render_router(&block)
|
6
|
-
define_method(:render) do
|
7
|
-
if respond_to?(:history)
|
8
|
-
React::Router::Router(history: history.to_n) do
|
9
|
-
instance_eval(&block)
|
10
|
-
end
|
11
|
-
else
|
12
|
-
React::Router::MemoryRouter(location: { pathname: '/' }.to_n) do
|
13
|
-
instance_eval(&block)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|