reactive-router 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +22 -0
- data/README.md +37 -0
- data/Rakefile +2 -0
- data/lib/reactive-router.rb +12 -0
- data/lib/reactive-router/component.rb +28 -0
- data/lib/reactive-router/router.rb +69 -0
- data/lib/reactive-router/version.rb +3 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f7a8fd6cc3a6c46b51545b58ab6cd38c209702d0
|
4
|
+
data.tar.gz: d752c6775a07ed7533921b3b080f33ec29e9b575
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 66cbf2995946b6c6126bb9b819608630e538d98c548051cc7454f0dd40bac89141e26ae7ea9eb8623ea1ec43b73b9fcbe29d9fc67a9caf1d67976496e620faf7
|
7
|
+
data.tar.gz: c5f1b5f780a41e82b7fe139050e39e47c686a99b8e1f6e1b526cff52f64180ffe32c09a8be619f839bbaf4d3181ea1a7f4861aa2ce139f112826b1de6122579e
|
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,37 @@
|
|
1
|
+
## ReactiveRouter
|
2
|
+
|
3
|
+
ReactiveRouter allows you write and use the React Router in Ruby through Opal.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'reactive-router'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install reactor-router
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
TODO: Write usage instructions here
|
24
|
+
|
25
|
+
## Development
|
26
|
+
|
27
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
28
|
+
|
29
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
30
|
+
|
31
|
+
## Contributing
|
32
|
+
|
33
|
+
1. Fork it ( https://github.com/catprintlabs/reactor-router/fork )
|
34
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
35
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
36
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
37
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
if RUBY_ENGINE == 'opal'
|
2
|
+
require 'reactive-router/component'
|
3
|
+
require 'reactive-router/router'
|
4
|
+
require 'reactive-router/version'
|
5
|
+
else
|
6
|
+
require 'opal'
|
7
|
+
require 'opal-react'
|
8
|
+
require 'reactive-router/version'
|
9
|
+
|
10
|
+
Opal.append_path File.expand_path('../', __FILE__).untaint
|
11
|
+
Opal.append_path File.expand_path('../../vendor', __FILE__).untaint
|
12
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module React
|
2
|
+
module Component
|
3
|
+
|
4
|
+
module ClassMethods
|
5
|
+
|
6
|
+
def router_param(name, &block)
|
7
|
+
define_state name
|
8
|
+
before_mount do
|
9
|
+
send("#{name}!", yield(params[:params][name]))
|
10
|
+
end
|
11
|
+
before_receive_props do |new_params|
|
12
|
+
send("#{name}!", yield(new_params[:params][name]))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def route_handler
|
19
|
+
Router::RR::RouteHandler()
|
20
|
+
end
|
21
|
+
|
22
|
+
def link(opts = {}, &block)
|
23
|
+
opts[:params] = opts[:params].to_n if opts[:params]
|
24
|
+
Router::RR::Link(opts, &block)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module React
|
2
|
+
|
3
|
+
module Router
|
4
|
+
|
5
|
+
class RR < React::NativeLibrary
|
6
|
+
imports ReactRouter
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.included(base)
|
10
|
+
base.class_eval do
|
11
|
+
|
12
|
+
include React::Component
|
13
|
+
|
14
|
+
export_component
|
15
|
+
|
16
|
+
def render
|
17
|
+
show if self.class.routing?
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.routing?
|
21
|
+
@routing
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.routing!
|
25
|
+
was_routing = @routing
|
26
|
+
@routing = true
|
27
|
+
was_routing
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.handler(handler)
|
31
|
+
React::API.create_native_react_class(handler)
|
32
|
+
end
|
33
|
+
|
34
|
+
after_mount do
|
35
|
+
unless self.class.routing!
|
36
|
+
x = `React.findDOMNode(#{self}.native)`
|
37
|
+
routes = self.class.class_eval { @routes.call }
|
38
|
+
%x{
|
39
|
+
ReactRouter.run(#{routes}, ReactRouter.HistoryLocation, function(root) {
|
40
|
+
React.render(React.createElement(root), #{x});
|
41
|
+
});
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.routes(opts = {}, &block)
|
47
|
+
opts[:handler] ||= self
|
48
|
+
@routes = -> { self.route(opts, generate_node = true, &block) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def self.route(opts = {}, generate_node = nil, &block)
|
52
|
+
opts[:handler] = self.handler(opts[:handler])
|
53
|
+
generate_node ? RR::Route_as_node(opts, &block) : RR::Route(opts, &block)
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.default_route(ops = {}, &block)
|
57
|
+
RR::DefaultRoute(opts, &block)
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.redirect(opts = {}, &block)
|
61
|
+
RR::Redirect(opts, &block)
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reactive-router
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam George
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.8'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.8'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: opal-rails
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: react-rails
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
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
|
+
description: Adds the ability to write and use the react-router in Ruby through Opal
|
84
|
+
email:
|
85
|
+
- adamgeorge.31@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- LICENSE
|
91
|
+
- README.md
|
92
|
+
- Rakefile
|
93
|
+
- lib/reactive-router.rb
|
94
|
+
- lib/reactive-router/component.rb
|
95
|
+
- lib/reactive-router/router.rb
|
96
|
+
- lib/reactive-router/version.rb
|
97
|
+
homepage:
|
98
|
+
licenses: []
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.8
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: react-router for Opal, part of the reactive-ruby gem family
|
120
|
+
test_files: []
|