hyper-router 0.99.6 → 1.0.alpha1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1029f00ea6f4bb20be28746b509e7e69fc4528ac7ed005192139da6fddac93f0
4
- data.tar.gz: 620f341162d21f78fa4fcc0458c4f5f46214207925f8abf4f748dfb4f72c9361
3
+ metadata.gz: 8863e7ef028f29e4bdfc0be2d61a74db9ce38984ccc52e2f224fe2e978c88740
4
+ data.tar.gz: 5da68227cc75ee76042d6707db1ca9402cb764df1fb036db663e07720c5f1079
5
5
  SHA512:
6
- metadata.gz: f12ae6ad6ac750c2f256265cf7bd0da437a6927e548859d9241cd806cd4ef3c8fac2e5e86fb032b2651c579c76b60a1d55bd08cc6ba6afdef368334c155e7dcc
7
- data.tar.gz: f80927e5c39695c090a63cb1b4f95f3052fbcf6acf761e0893b4843932160f552666fcea9c389b4788f1006f13c04240a3d0c26aec01357f2f463d10e79aade8
6
+ metadata.gz: 1752e464e7c42a18b04cf2b7d0a8f2c2d247c7f0f7aca9c8c1879990e98a3ebaa5f9feb69f7ccd9a90939e65f78e40a316af26f4930f99a63149db89490c5099
7
+ data.tar.gz: 06d11f811b38b198b166e40df26154c3295c4e458550c92d4ca772101d1030a91c715cd085b1412739cf00e93b17cef9f3fd60ae832927da321048ddb8dfc855
data/lib/hyper-router.rb CHANGED
@@ -2,34 +2,28 @@
2
2
 
3
3
  require 'hyper-component'
4
4
 
5
- Hyperloop.js_import 'hyper-router/react-router-source', defines: ['ReactRouter', 'ReactRouterDOM', 'History']
6
- Hyperloop.import 'hyper-router'
5
+ Hyperstack.js_import 'hyperstack/router/react-router-source', defines: ['ReactRouter', 'ReactRouterDOM', 'History']
6
+ Hyperstack.import 'hyper-router'
7
7
 
8
8
  if RUBY_ENGINE == 'opal'
9
9
  require 'react/router'
10
10
  require 'react/router/dom'
11
11
  require 'react/router/history'
12
12
 
13
- require 'hyper-router/isomorphic_methods'
14
- require 'hyper-router/history'
15
- require 'hyper-router/location'
16
- require 'hyper-router/match'
17
- require 'hyper-router/class_methods'
18
- require 'hyper-router/component_methods'
19
- require 'hyper-router/instance_methods'
13
+ require 'hyperstack/internal/router/isomorphic_methods'
14
+ require 'hyperstack/router/history'
15
+ require 'hyperstack/router/location'
16
+ require 'hyperstack/router/match'
17
+ require 'hyperstack/internal/router/class_methods'
18
+ require 'hyperstack/internal/router/helpers'
19
+ require 'hyperstack/internal/router/instance_methods'
20
20
 
21
- require 'hyperloop/router/base'
22
- require 'hyperloop/router/browser'
23
- require 'hyperloop/router/mixin'
24
- require 'hyperloop/router/component'
25
- require 'hyperloop/router/hash'
26
- require 'hyperloop/router/memory'
27
- require 'hyperloop/router/static'
28
- require 'hyperloop/router'
21
+ require 'hyperstack/router/helpers'
22
+ require 'hyperstack/router'
29
23
  else
30
24
  require 'opal'
31
- require 'hyper-router/isomorphic_methods'
32
- require 'hyper-router/version'
25
+ require 'hyperstack/internal/router/isomorphic_methods'
26
+ require 'hyperstack/router/version'
33
27
 
34
28
  Opal.append_path File.expand_path('../', __FILE__).untaint
35
29
  end
@@ -0,0 +1,80 @@
1
+ module Hyperstack
2
+ module Internal
3
+ module Router
4
+ module ClassMethods
5
+ def history(*args)
6
+ if args.count.positive?
7
+ @__history_type = args.first
8
+ elsif @__history_type
9
+ @__history ||= send(:"#{@__history_type}_history")
10
+ end
11
+ end
12
+
13
+ def location
14
+ Hyperstack::Router::Location.new(`#{history.to_n}.location`)
15
+ end
16
+
17
+ def render(container = nil, params = {}, &block)
18
+ if container
19
+ container = container.type if container.is_a? Hyperstack::Component::Element
20
+ select_router do
21
+ Hyperstack::Internal::Component::RenderingContext.render(container, params) do
22
+ instance_eval(&block) if block
23
+ end
24
+ end
25
+ else
26
+ select_router { instance_eval(&block) }
27
+ end
28
+ end
29
+
30
+ def select_router(&block)
31
+ if Hyperstack::Component::IsomorphicHelpers.on_opal_server?
32
+ prerender_router(&block)
33
+ else
34
+ render_router(&block)
35
+ end
36
+ end
37
+
38
+ alias route render
39
+
40
+ private
41
+
42
+ def browser_history
43
+ @__browser_history ||= React::Router::History.current.create_browser_history
44
+ end
45
+
46
+ def hash_history(*args)
47
+ @__hash_history ||= React::Router::History.current.create_hash_history(*args)
48
+ end
49
+
50
+ def memory_history(*args)
51
+ @__memory_history ||= React::Router::History.current.create_memory_history(*args)
52
+ end
53
+
54
+ def render_router(&block)
55
+ define_method(:render) do
56
+ self.class.history :browser unless history
57
+
58
+ React::Router::Router(history: history.to_n) do
59
+ instance_eval(&block)
60
+ end
61
+ end
62
+ end
63
+
64
+ def prerender_router(&block)
65
+ define_method(:render) do
66
+ location = {}.tap do |hash|
67
+ pathname, search = IsomorphicMethods.request_fullpath.split('?', 2)
68
+ hash[:pathname] = pathname
69
+ hash[:search] = search ? "?#{search}" : ''
70
+ end
71
+
72
+ React::Router::StaticRouter(location: location.to_n, context: {}.to_n) do
73
+ instance_eval(&block)
74
+ end
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,69 @@
1
+ # rubocop:disable Style/MethodName
2
+ module Hyperstack
3
+ module Internal
4
+ module Router
5
+ module Helpers
6
+ def Link(to, opts = {}, &children)
7
+ opts[:to] = {}.tap do |hash|
8
+ hash[:pathname] = to
9
+ hash[:search] = opts.delete(:search) if opts[:search]
10
+ hash[:hash] = opts.delete(:hash) if opts[:hash]
11
+ end.to_n
12
+ React::Router::DOM::Link(opts, &children)
13
+ end
14
+
15
+ def NavLink(to, opts = {}, &children)
16
+ opts[:to] = to.to_n
17
+ if (%i[active_class active_style active] & opts.keys).any?
18
+ opts[:activeClassName] = opts.delete(:active_class).to_n if opts[:active_class]
19
+ opts[:activeStyle] = opts.delete(:active_style).to_n if opts[:active_style]
20
+ opts[:isActive] = opts.delete(:active).to_n if opts[:active]
21
+ State::Mapper.observed! Hyperstack::Router::Location
22
+ end
23
+ React::Router::DOM::NavLink(opts, &children)
24
+ end
25
+
26
+ def Redirect(to, opts = {})
27
+ opts[:to] = to.to_n
28
+ React::Router::Redirect(opts)
29
+ end
30
+
31
+ def format_params(e)
32
+ {
33
+ match: Hyperstack::Router::Match.new(`#{e}.match`),
34
+ location: Hyperstack::Router::Location.new(`#{e}.location`),
35
+ history: Hyperstack::Router::History.new(`#{e}.history`)
36
+ }
37
+ end
38
+
39
+ def Route(to, opts = {}, &block)
40
+ opts[:path] = to.to_n
41
+
42
+ if opts[:mounts]
43
+ component = opts.delete(:mounts)
44
+
45
+ opts[:component] = lambda do |e|
46
+ route_params = format_params(e)
47
+
48
+ Hyperstack::Component::ReactAPI.create_element(component, route_params).to_n
49
+ end
50
+ end
51
+
52
+ if block
53
+ opts[:render] = lambda do |e|
54
+ route_params = format_params(e)
55
+
56
+ yield(route_params.values).to_n
57
+ end
58
+ end
59
+
60
+ React::Router::Route(opts)
61
+ end
62
+
63
+ def Switch(&children)
64
+ React::Router::Switch(&children)
65
+ end
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,15 @@
1
+ module Hyperstack
2
+ module Internal
3
+ module Router
4
+ module InstanceMethods
5
+ def history
6
+ self.class.history
7
+ end
8
+
9
+ def location
10
+ self.class.location
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ module Hyperstack
2
+ module Internal
3
+ module Router
4
+ class IsomorphicMethods
5
+ include Hyperstack::Component::IsomorphicHelpers
6
+
7
+ isomorphic_method(:request_fullpath) do |f|
8
+ f.when_on_client { `window.location.pathname` }
9
+ f.send_to_server
10
+ f.when_on_server { f.context.controller.request.fullpath }
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,32 @@
1
+ module Hyperstack
2
+ module Router
3
+ class NoHistoryError < StandardError; end
4
+ def self.included(base)
5
+ base.extend(Hyperstack::Internal::Router::ClassMethods)
6
+
7
+ base.include(Hyperstack::Internal::Router::Helpers)
8
+
9
+ base.class_eval do
10
+
11
+ def history
12
+ self.class.history
13
+ end
14
+
15
+ def location
16
+ self.class.location
17
+ end
18
+
19
+ after_mount do
20
+ @_react_router_unlisten = history.listen do |location, _action|
21
+ Hyperstack::Internal::State::Mapper.observed! Hyperstack::Router::Location
22
+ end
23
+ end
24
+
25
+ before_unmount do
26
+ @_react_router_unlisten.call if @_react_router_unlisten
27
+ end
28
+ end
29
+
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,39 @@
1
+ module Hyperstack
2
+ module Router
3
+ module Helpers
4
+ def match
5
+ if @__hyperstack_component_params_wrapper.param_accessor_style != :hyperstack
6
+ params.match
7
+ else
8
+ @Match
9
+ end
10
+ end
11
+
12
+ def location
13
+ if @__hyperstack_component_params_wrapper.param_accessor_style != :hyperstack
14
+ params.location
15
+ else
16
+ @Location
17
+ end
18
+ end
19
+
20
+ def history
21
+ if @__hyperstack_component_params_wrapper.param_accessor_style != :hyperstack
22
+ params.history
23
+ else
24
+ @History
25
+ end
26
+ end
27
+
28
+ def self.included(base)
29
+ base.include(Hyperstack::Internal::Router::Helpers)
30
+
31
+ base.class_eval do
32
+ param :match, default: nil
33
+ param :location, default: nil
34
+ param :history, default: nil
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,48 @@
1
+ module Hyperstack
2
+ module Router
3
+ class History
4
+ include Native
5
+
6
+ def initialize(native)
7
+ @native = native
8
+ end
9
+
10
+ def to_n
11
+ @native
12
+ end
13
+
14
+ def location
15
+ Location.new(`#{@native}.location`)
16
+ end
17
+
18
+ def block(message = nil)
19
+ if message
20
+ native_block(message.to_n)
21
+ else
22
+ native_block do |location, action|
23
+ yield Location.new(location), action
24
+ end
25
+ end
26
+ end
27
+
28
+ def listen
29
+ native_listen do |location, action|
30
+ yield Location.new(location), action
31
+ end
32
+ end
33
+
34
+ alias_native :action
35
+ alias_native :native_block, :block
36
+ alias_native :create_href, :createHref
37
+ alias_native :entries
38
+ alias_native :go
39
+ alias_native :go_back, :goBack
40
+ alias_native :go_forward, :goForward
41
+ alias_native :index
42
+ alias_native :length
43
+ alias_native :native_listen, :listen
44
+ alias_native :push, :push
45
+ alias_native :replace, :replace
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,31 @@
1
+ module Hyperstack
2
+ module Router
3
+ class Location
4
+ include Native
5
+
6
+ def initialize(native)
7
+ @native = native
8
+ end
9
+
10
+ def to_n
11
+ @native
12
+ end
13
+
14
+ def query
15
+ return {} if search.blank?
16
+
17
+ Hash[search[1..-1].split('&').map { |part|
18
+ name, value = part.split('=')
19
+
20
+ [`decodeURIComponent(#{name})`, `decodeURIComponent(#{value})`]
21
+ }]
22
+ end
23
+
24
+ alias_native :pathname
25
+ alias_native :search
26
+ alias_native :hash
27
+ alias_native :state
28
+ alias_native :key
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,20 @@
1
+ module Hyperstack
2
+ module Router
3
+ class Match
4
+ include Native
5
+
6
+ def initialize(native)
7
+ @native = native
8
+ end
9
+
10
+ def to_n
11
+ @native
12
+ end
13
+
14
+ alias_native :params
15
+ alias_native :is_exact, :isExact
16
+ alias_native :path
17
+ alias_native :url
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,3 @@
1
+ module HyperRouter
2
+ VERSION = '1.0.alpha1'
3
+ end
data/lib/react/router.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module React
2
- class Router < React::NativeLibrary
2
+ class Router < Hyperstack::Component::NativeLibrary
3
3
  imports 'ReactRouter'
4
4
  end
5
5
  end
@@ -1,6 +1,6 @@
1
1
  module React
2
2
  class Router
3
- class DOM < React::NativeLibrary
3
+ class DOM < Hyperstack::Component::NativeLibrary
4
4
  imports 'ReactRouterDOM'
5
5
  end
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyper-router
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.99.6
4
+ version: 1.0.alpha1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam George
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-01-30 00:00:00.000000000 Z
12
+ date: 2018-11-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: hyper-component
@@ -17,14 +17,28 @@ dependencies:
17
17
  requirements:
18
18
  - - '='
19
19
  - !ruby/object:Gem::Version
20
- version: 0.99.6
20
+ version: 1.0.alpha1
21
21
  type: :runtime
22
22
  prerelease: false
23
23
  version_requirements: !ruby/object:Gem::Requirement
24
24
  requirements:
25
25
  - - '='
26
26
  - !ruby/object:Gem::Version
27
- version: 0.99.6
27
+ version: 1.0.alpha1
28
+ - !ruby/object:Gem::Dependency
29
+ name: hyper-state
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - '='
33
+ - !ruby/object:Gem::Version
34
+ version: 1.0.alpha1
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '='
40
+ - !ruby/object:Gem::Version
41
+ version: 1.0.alpha1
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: opal-browser
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -101,14 +115,14 @@ dependencies:
101
115
  requirements:
102
116
  - - '='
103
117
  - !ruby/object:Gem::Version
104
- version: 0.99.6
118
+ version: 1.0.alpha1
105
119
  type: :development
106
120
  prerelease: false
107
121
  version_requirements: !ruby/object:Gem::Requirement
108
122
  requirements:
109
123
  - - '='
110
124
  - !ruby/object:Gem::Version
111
- version: 0.99.6
125
+ version: 1.0.alpha1
112
126
  - !ruby/object:Gem::Dependency
113
127
  name: listen
114
128
  requirement: !ruby/object:Gem::Requirement
@@ -129,14 +143,14 @@ dependencies:
129
143
  requirements:
130
144
  - - "~>"
131
145
  - !ruby/object:Gem::Version
132
- version: 0.2.4
146
+ version: 0.1.15
133
147
  type: :development
134
148
  prerelease: false
135
149
  version_requirements: !ruby/object:Gem::Requirement
136
150
  requirements:
137
151
  - - "~>"
138
152
  - !ruby/object:Gem::Version
139
- version: 0.2.4
153
+ version: 0.1.15
140
154
  - !ruby/object:Gem::Dependency
141
155
  name: opal-rails
142
156
  requirement: !ruby/object:Gem::Requirement
@@ -393,16 +407,16 @@ dependencies:
393
407
  name: unparser
394
408
  requirement: !ruby/object:Gem::Requirement
395
409
  requirements:
396
- - - "~>"
410
+ - - ">="
397
411
  - !ruby/object:Gem::Version
398
- version: 0.3.0
412
+ version: '0'
399
413
  type: :development
400
414
  prerelease: false
401
415
  version_requirements: !ruby/object:Gem::Requirement
402
416
  requirements:
403
- - - "~>"
417
+ - - ">="
404
418
  - !ruby/object:Gem::Version
405
- version: 0.3.0
419
+ version: '0'
406
420
  - !ruby/object:Gem::Dependency
407
421
  name: webdrivers
408
422
  requirement: !ruby/object:Gem::Requirement
@@ -425,34 +439,26 @@ executables: []
425
439
  extensions: []
426
440
  extra_rdoc_files: []
427
441
  files:
428
- - LICENSE
429
- - README.md
430
442
  - Rakefile
431
443
  - lib/hyper-router.rb
432
- - lib/hyper-router/class_methods.rb
433
- - lib/hyper-router/component_methods.rb
434
- - lib/hyper-router/history.rb
435
- - lib/hyper-router/instance_methods.rb
436
- - lib/hyper-router/isomorphic_methods.rb
437
- - lib/hyper-router/location.rb
438
- - lib/hyper-router/match.rb
439
- - lib/hyper-router/react-router-source.rb
440
- - lib/hyper-router/version.rb
441
- - lib/hyperloop/router.rb
442
- - lib/hyperloop/router/base.rb
443
- - lib/hyperloop/router/browser.rb
444
- - lib/hyperloop/router/component.rb
445
- - lib/hyperloop/router/hash.rb
446
- - lib/hyperloop/router/memory.rb
447
- - lib/hyperloop/router/mixin.rb
448
- - lib/hyperloop/router/static.rb
444
+ - lib/hyperstack/internal/router/class_methods.rb
445
+ - lib/hyperstack/internal/router/helpers.rb
446
+ - lib/hyperstack/internal/router/instance_methods.rb
447
+ - lib/hyperstack/internal/router/isomorphic_methods.rb
448
+ - lib/hyperstack/router.rb
449
+ - lib/hyperstack/router/helpers.rb
450
+ - lib/hyperstack/router/history.rb
451
+ - lib/hyperstack/router/location.rb
452
+ - lib/hyperstack/router/match.rb
453
+ - lib/hyperstack/router/react-router-source.rb
454
+ - lib/hyperstack/router/version.rb
449
455
  - lib/react/router.rb
450
456
  - lib/react/router/dom.rb
451
457
  - lib/react/router/history.rb
452
458
  - lib/src/history.min.js
453
459
  - lib/src/react-router-dom.min.js
454
460
  - lib/src/react-router.min.js
455
- homepage: http://ruby-hyperloop.org
461
+ homepage: http://hyperstack.org
456
462
  licenses:
457
463
  - MIT
458
464
  metadata: {}
@@ -467,12 +473,13 @@ required_ruby_version: !ruby/object:Gem::Requirement
467
473
  version: '0'
468
474
  required_rubygems_version: !ruby/object:Gem::Requirement
469
475
  requirements:
470
- - - ">="
476
+ - - ">"
471
477
  - !ruby/object:Gem::Version
472
- version: '0'
478
+ version: 1.3.1
473
479
  requirements: []
474
- rubygems_version: 3.0.2
480
+ rubyforge_project:
481
+ rubygems_version: 2.7.8
475
482
  signing_key:
476
483
  specification_version: 4
477
- summary: hyper-router for Opal, part of ruby-hyperloop
484
+ summary: hyper-router for Opal, part of the hyperstack framework
478
485
  test_files: []
data/LICENSE DELETED
@@ -1,22 +0,0 @@
1
- The MIT License (MIT)
2
-
3
- Copyright (c) 2015 catprintlabs
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
22
-
data/README.md DELETED
@@ -1,79 +0,0 @@
1
- <div class="githubhyperloopheader">
2
-
3
- <p align="center">
4
-
5
- <a href="http://ruby-hyperloop.org/" alt="Hyperloop" title="Hyperloop">
6
- <img width="350px" src="http://ruby-hyperloop.org/images/hyperloop-github-logo.png">
7
- </a>
8
-
9
- </p>
10
-
11
- <h2 align="center">The Complete Isomorphic Ruby Framework</h2>
12
-
13
- <br>
14
-
15
- <a href="http://ruby-hyperloop.org/" alt="Hyperloop" title="Hyperloop">
16
- <img src="http://ruby-hyperloop.org/images/githubhyperloopbadge.png">
17
- </a>
18
-
19
- <a href="https://gitter.im/ruby-hyperloop/chat" alt="Gitter chat" title="Gitter chat">
20
- <img src="http://ruby-hyperloop.org/images/githubgitterbadge.png">
21
- </a>
22
-
23
- [![Codeship Status for ruby-hyperloop/hyper-store](https://app.codeship.com/projects/4454c560-d4ea-0134-7c96-362b4886dd22/status?branch=master)](https://app.codeship.com/projects/202301)
24
- [![Gem Version](https://badge.fury.io/rb/hyper-router.svg)](https://badge.fury.io/rb/hyper-router)
25
-
26
- <p align="center">
27
- <img src="http://ruby-hyperloop.org/images/HyperRouter.png" width="100" alt="Hyper-router">
28
- </p>
29
-
30
- </div>
31
-
32
- ## Hyper-Router GEM is part of Hyperloop GEMS family
33
-
34
- Build interactive Web applications quickly. Hyperloop encourages rapid development with clean, pragmatic design. With developer productivity as our highest goal, Hyperloop takes care of much of the hassle of Web development, so you can focus on innovation and delivering end-user value.
35
-
36
- One language. One model. One set of tests. The same business logic and domain models running on the clients and the server. Hyperloop is fully integrated with Rails and also gives you unfettered access to the complete universe of JavaScript libraries (including React) from within your Ruby code. Hyperloop lets you build beautiful interactive user interfaces in Ruby.
37
-
38
- Everything has a place in our architecture. Components deliver interactive user experiences, Operations encapsulate business logic, Models magically synchronize data between clients and servers, Policies govern authorization and Stores hold local state.
39
-
40
- **Hyper-router** allows you write and use the React Router in Ruby through Opal.
41
-
42
-
43
- ## Getting Started
44
-
45
- 1. Update your Gemfile:
46
-
47
- ```ruby
48
- #Gemfile
49
-
50
- gem 'hyperloop'
51
- ```
52
-
53
- 2. At the command prompt, update your bundle :
54
-
55
- $ bundle update
56
-
57
- 3. Run the hyperloop install generator:
58
-
59
- $ rails g hyperloop:install
60
-
61
- 4. Follow the guidelines to start developing your application. You may find
62
- the following resources handy:
63
- * [Getting Started with Hyperloop](http://ruby-hyperloop.org/start/components/)
64
- * [Hyperloop Guides](http://ruby-hyperloop.org/docs/architecture)
65
- * [Hyperloop Tutorial](http://ruby-hyperloop.org/tutorials)
66
-
67
- ## Community
68
-
69
- #### Getting Help
70
- Please **do not post** usage questions to GitHub Issues. For these types of questions use our [Gitter chatroom](https://gitter.im/ruby-hyperloop/chat) or [StackOverflow](http://stackoverflow.com/questions/tagged/hyperloop).
71
-
72
- #### Submitting Bugs and Enhancements
73
- [GitHub Issues](https://github.com/ruby-hyperloop/hyperloop/issues) is for suggesting enhancements and reporting bugs. Before submiting a bug make sure you do the following:
74
- * Check out our [contributing guide](https://github.com/ruby-hyperloop/hyperloop/blob/master/CONTRIBUTING.md) for info on our release cycle.
75
-
76
- ## License
77
-
78
- Hyperloop is released under the [MIT License](http://www.opensource.org/licenses/MIT).
79
-
@@ -1,63 +0,0 @@
1
- module HyperRouter
2
- class NoHistoryError < StandardError; end
3
-
4
- module ClassMethods
5
- def history(*args)
6
- if args.count > 0
7
- @__history_type = args.first
8
- elsif @__history_type
9
- @__history ||= send(:"#{@__history_type}_history")
10
- end
11
- end
12
-
13
- def location
14
- Location.new(`#{history.to_n}.location`)
15
- end
16
-
17
- def route(&block)
18
- if React::IsomorphicHelpers.on_opal_server?
19
- prerender_router(&block)
20
- else
21
- render_router(&block)
22
- end
23
- end
24
-
25
- private
26
-
27
- def browser_history
28
- @__browser_history ||= React::Router::History.current.create_browser_history
29
- end
30
-
31
- def hash_history(*args)
32
- @__hash_history ||= React::Router::History.current.create_hash_history(*args)
33
- end
34
-
35
- def memory_history(*args)
36
- @__memory_history ||= React::Router::History.current.create_memory_history(*args)
37
- end
38
-
39
- def render_router(&block)
40
- define_method(:render) do
41
- self.class.history :browser unless history
42
-
43
- React::Router::Router(history: history.to_n) do
44
- instance_eval(&block)
45
- end
46
- end
47
- end
48
-
49
- def prerender_router(&block)
50
- define_method(:render) do
51
- location = {}.tap do |hash|
52
- pathname, search = IsomorphicMethods.request_fullpath.split('?', 2)
53
- hash[:pathname] = pathname
54
- hash[:search] = search ? "?#{search}" : ''
55
- end
56
-
57
- React::Router::StaticRouter(location: location.to_n, context: {}.to_n) do
58
- instance_eval(&block)
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,66 +0,0 @@
1
- # rubocop:disable Style/MethodName
2
-
3
- module HyperRouter
4
- module ComponentMethods
5
- def Link(to, opts = {}, &children)
6
- opts[:to] = {}.tap do |hash|
7
- hash[:pathname] = to
8
- hash[:search] = opts.delete(:search) if opts[:search]
9
- hash[:hash] = opts.delete(:hash) if opts[:hash]
10
- end.to_n
11
- React::Router::DOM::Link(opts, &children)
12
- end
13
-
14
- def NavLink(to, opts = {}, &children)
15
- opts[:to] = to.to_n
16
- opts[:activeClassName] = opts.delete(:active_class).to_n if opts[:active_class]
17
- opts[:activeStyle] = opts.delete(:active_style).to_n if opts[:active_style]
18
- opts[:isActive] = opts.delete(:active).to_n if opts[:active]
19
- if (%i[activeClassName activeStyle isActive] & opts.keys).any?
20
- React::State.get_state(HyperRouter, :location)
21
- end
22
- React::Router::DOM::NavLink(opts, &children)
23
- end
24
-
25
- def Redirect(to, opts = {})
26
- opts[:to] = to.to_n
27
- React::Router::Redirect(opts)
28
- end
29
-
30
- def format_params(e)
31
- {
32
- match: HyperRouter::Match.new(`#{e}.match`),
33
- location: HyperRouter::Location.new(`#{e}.location`),
34
- history: HyperRouter::History.new(`#{e}.history`)
35
- }
36
- end
37
-
38
- def Route(to, opts = {}, &block)
39
- opts[:path] = to.to_n
40
-
41
- if opts[:mounts]
42
- component = opts.delete(:mounts)
43
-
44
- opts[:component] = lambda do |e|
45
- route_params = format_params(e)
46
-
47
- React.create_element(component, route_params).to_n
48
- end
49
- end
50
-
51
- if block
52
- opts[:render] = lambda do |e|
53
- route_params = format_params(e)
54
-
55
- yield(route_params.values).to_n
56
- end
57
- end
58
-
59
- React::Router::Route(opts)
60
- end
61
-
62
- def Switch(&children)
63
- React::Router::Switch(&children)
64
- end
65
- end
66
- end
@@ -1,46 +0,0 @@
1
- module HyperRouter
2
- class History
3
- include Native
4
-
5
- def initialize(native)
6
- @native = native
7
- end
8
-
9
- def to_n
10
- @native
11
- end
12
-
13
- def location
14
- HyperRouter::Location.new(`#{@native}.location`)
15
- end
16
-
17
- def block(message = nil)
18
- if message
19
- native_block(message.to_n)
20
- else
21
- native_block do |location, action|
22
- yield Location.new(location), action
23
- end
24
- end
25
- end
26
-
27
- def listen
28
- native_listen do |location, action|
29
- yield Location.new(location), action
30
- end
31
- end
32
-
33
- alias_native :action
34
- alias_native :native_block, :block
35
- alias_native :create_href, :createHref
36
- alias_native :entries
37
- alias_native :go
38
- alias_native :go_back, :goBack
39
- alias_native :go_forward, :goForward
40
- alias_native :index
41
- alias_native :length
42
- alias_native :native_listen, :listen
43
- alias_native :push, :push
44
- alias_native :replace, :replace
45
- end
46
- end
@@ -1,11 +0,0 @@
1
- module HyperRouter
2
- module InstanceMethods
3
- def history
4
- self.class.history
5
- end
6
-
7
- def location
8
- self.class.location
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- module HyperRouter
2
- class IsomorphicMethods
3
- include React::IsomorphicHelpers
4
-
5
- isomorphic_method(:request_fullpath) do |f|
6
- f.when_on_client { `window.location.pathname` }
7
- f.send_to_server
8
- f.when_on_server { f.context.controller.request.fullpath }
9
- end
10
- end
11
- end
@@ -1,29 +0,0 @@
1
- module HyperRouter
2
- class Location
3
- include Native
4
-
5
- def initialize(native)
6
- @native = native
7
- end
8
-
9
- def to_n
10
- @native
11
- end
12
-
13
- def query
14
- return {} if search.blank?
15
-
16
- Hash[search[1..-1].split('&').map { |part|
17
- name, value = part.split('=')
18
-
19
- [`decodeURIComponent(#{name})`, `decodeURIComponent(#{value})`]
20
- }]
21
- end
22
-
23
- alias_native :pathname
24
- alias_native :search
25
- alias_native :hash
26
- alias_native :state
27
- alias_native :key
28
- end
29
- end
@@ -1,18 +0,0 @@
1
- module HyperRouter
2
- class Match
3
- include Native
4
-
5
- def initialize(native)
6
- @native = native
7
- end
8
-
9
- def to_n
10
- @native
11
- end
12
-
13
- alias_native :params
14
- alias_native :is_exact, :isExact
15
- alias_native :path
16
- alias_native :url
17
- end
18
- end
@@ -1,3 +0,0 @@
1
- module HyperRouter
2
- HYPERLOOP_VERSION = VERSION = '0.99.6'
3
- end
@@ -1,36 +0,0 @@
1
- module Hyperloop
2
- class Router
3
- def self.inherited(child)
4
- child.include(Hyperloop::Component::Mixin)
5
- child.include(Base)
6
- end
7
- end
8
-
9
- class BrowserRouter
10
- def self.inherited(child)
11
- child.include(Hyperloop::Component::Mixin)
12
- child.include(Hyperloop::Router::Browser)
13
- end
14
- end
15
-
16
- class HashRouter
17
- def self.inherited(child)
18
- child.include(Hyperloop::Component::Mixin)
19
- child.include(Hyperloop::Router::Hash)
20
- end
21
- end
22
-
23
- class MemoryRouter
24
- def self.inherited(child)
25
- child.include(Hyperloop::Component::Mixin)
26
- child.include(Hyperloop::Router::Memory)
27
- end
28
- end
29
-
30
- class StaticRouter
31
- def self.inherited(child)
32
- child.include(Hyperloop::Component::Mixin)
33
- child.include(Hyperloop::Router::Static)
34
- end
35
- end
36
- end
@@ -1,24 +0,0 @@
1
- module Hyperloop
2
- class Router
3
- module Base
4
- def self.included(base)
5
- base.extend(HyperRouter::ClassMethods)
6
-
7
- base.include(HyperRouter::InstanceMethods)
8
- base.include(HyperRouter::ComponentMethods)
9
-
10
- base.class_eval do
11
- after_mount do
12
- @_react_router_unlisten = history.listen do |location, _action|
13
- React::State.set_state(HyperRouter, :location, location)
14
- end
15
- end
16
-
17
- before_unmount do
18
- @_react_router_unlisten.call if @_react_router_unlisten
19
- end
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,13 +0,0 @@
1
- module Hyperloop
2
- class Router
3
- module Browser
4
- def self.included(base)
5
- base.extend(HyperRouter::ClassMethods)
6
- base.history(:browser)
7
-
8
- base.include(HyperRouter::InstanceMethods)
9
- base.include(HyperRouter::ComponentMethods)
10
- end
11
- end
12
- end
13
- end
@@ -1,11 +0,0 @@
1
- module Hyperloop
2
- class Router
3
- class Component
4
- class << self
5
- def inherited(base)
6
- base.include(Mixin)
7
- end
8
- end
9
- end
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- module Hyperloop
2
- class Router
3
- module Hash
4
- def self.included(base)
5
- base.extend(HyperRouter::ClassMethods)
6
- base.history(:hash)
7
-
8
- base.include(HyperRouter::InstanceMethods)
9
- base.include(HyperRouter::ComponentMethods)
10
- end
11
- end
12
- end
13
- end
@@ -1,13 +0,0 @@
1
- module Hyperloop
2
- class Router
3
- module Memory
4
- def self.included(base)
5
- base.extend(HyperRouter::ClassMethods)
6
- base.history(:memory)
7
-
8
- base.include(HyperRouter::InstanceMethods)
9
- base.include(HyperRouter::ComponentMethods)
10
- end
11
- end
12
- end
13
- end
@@ -1,30 +0,0 @@
1
- module Hyperloop
2
- class Router
3
- module Mixin
4
- class << self
5
- def included(base)
6
- base.include(Hyperloop::Component::Mixin)
7
- base.include(HyperRouter::ComponentMethods)
8
-
9
- base.class_eval do
10
- param :match, default: nil
11
- param :location, default: nil
12
- param :history, default: nil
13
-
14
- define_method(:match) do
15
- params.match
16
- end
17
-
18
- define_method(:location) do
19
- params.location
20
- end
21
-
22
- define_method(:history) do
23
- params.history
24
- end
25
- end
26
- end
27
- end
28
- end
29
- end
30
- end
@@ -1,19 +0,0 @@
1
- module Hyperloop
2
- class Router
3
- module Static
4
- module ClassMethods
5
- def route(&block)
6
- prerender_router(&block)
7
- end
8
- end
9
-
10
- def self.included(base)
11
- base.extend(HyperRouter::ClassMethods)
12
- base.extend(ClassMethods)
13
-
14
- base.include(HyperRouter::InstanceMethods)
15
- base.include(HyperRouter::ComponentMethods)
16
- end
17
- end
18
- end
19
- end