hyper-router 0.99.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8601619dfc2f38c2fb95739c31e22cd349ea66d43bbee063505980eeba899119
4
+ data.tar.gz: 5e1b4bce6f14d026a335119b398db3614832efe08e7cda173dcaa02cb57cc48c
5
+ SHA512:
6
+ metadata.gz: f42cc9e1451bc912d4d09fc718acb26e9edcaf29cfcd5904cbfe36b95e12299894e2c2dab480fd372609ecb0f47f57cef9eb51254b2edc3be41f4d8a51007a8a
7
+ data.tar.gz: 5b1a91d0dd6d1b5e77bd46c0da6b618ff4006106b24b326a7975feac8fce70eff8ad495e51264b3743ac832a7b206dcf46d6bd5a43054781a1b681d9fd3448ba
data/LICENSE ADDED
@@ -0,0 +1,22 @@
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 ADDED
@@ -0,0 +1,79 @@
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
+
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ namespace :spec do
7
+ task :prepare do
8
+ end
9
+ end
10
+
11
+ task :default => :spec
@@ -0,0 +1,35 @@
1
+ # rubocop:disable Style/FileName
2
+
3
+ require 'hyper-component'
4
+
5
+ Hyperloop.js_import 'hyper-router/react-router-source', defines: ['ReactRouter', 'ReactRouterDOM', 'History']
6
+ Hyperloop.import 'hyper-router'
7
+
8
+ if RUBY_ENGINE == 'opal'
9
+ require 'react/router'
10
+ require 'react/router/dom'
11
+ require 'react/router/history'
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'
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'
29
+ else
30
+ require 'opal'
31
+ require 'hyper-router/isomorphic_methods'
32
+ require 'hyper-router/version'
33
+
34
+ Opal.append_path File.expand_path('../', __FILE__).untaint
35
+ end
@@ -0,0 +1,63 @@
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
@@ -0,0 +1,66 @@
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
@@ -0,0 +1,46 @@
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
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,29 @@
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
@@ -0,0 +1,18 @@
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
@@ -0,0 +1,4 @@
1
+ # rubocop:disable Style/FileName
2
+ require 'src/react-router.min.js'
3
+ require 'src/react-router-dom.min.js'
4
+ require 'src/history.min.js'
@@ -0,0 +1,3 @@
1
+ module HyperRouter
2
+ HYPERLOOP_VERSION = VERSION = '0.99.1'
3
+ end
@@ -0,0 +1,36 @@
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