routable 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +11 -1
- data/lib/routable/router.rb +52 -1
- data/lib/routable/version.rb +1 -1
- data/spec/main_spec.rb +34 -0
- metadata +2 -2
data/Rakefile
CHANGED
@@ -1 +1,11 @@
|
|
1
|
-
|
1
|
+
$:.unshift("/Library/RubyMotion/lib")
|
2
|
+
require 'motion/project'
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
|
5
|
+
$:.unshift("./lib/")
|
6
|
+
require './lib/routable'
|
7
|
+
|
8
|
+
Motion::Project::App.setup do |app|
|
9
|
+
# Use `rake config' to see complete project settings.
|
10
|
+
app.name = 'Routable'
|
11
|
+
end
|
data/lib/routable/router.rb
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
module Routable
|
2
2
|
class Router
|
3
|
+
TRANSITION_STYLES = {
|
4
|
+
:cover => UIModalTransitionStyleCoverVertical,
|
5
|
+
:flip => UIModalTransitionStyleFlipHorizontal,
|
6
|
+
:dissolve => UIModalTransitionStyleCrossDissolve,
|
7
|
+
:curl => UIModalTransitionStylePartialCurl
|
8
|
+
}
|
9
|
+
|
10
|
+
PRESENTATION_STYLES = {
|
11
|
+
:full_screen => UIModalPresentationFullScreen,
|
12
|
+
:page_sheet => UIModalPresentationPageSheet,
|
13
|
+
:form_sheet => UIModalPresentationFormSheet,
|
14
|
+
:current => UIModalPresentationCurrentContext
|
15
|
+
}
|
16
|
+
|
3
17
|
# Singleton, for practical use (you might not want)
|
4
18
|
# to have more than one router.
|
5
19
|
class << self
|
@@ -28,9 +42,21 @@ module Routable
|
|
28
42
|
# - We present the VC modally (router is not shared between the new nav VC)
|
29
43
|
# :shared => true/false
|
30
44
|
# - If URL is called again, we pop to that VC if it's in memory.
|
31
|
-
|
45
|
+
# :transition => [:cover, :flip, :dissolve, :curl]
|
46
|
+
# - A symbol to represented transition style used. Mapped to UIModalTransitionStyle.
|
47
|
+
# :presentation => [:full_screen, :page_sheet, :form_sheet, :current]
|
48
|
+
# - A symbol to represented presentation style used. Mapped to UIModalPresentationStyle.
|
32
49
|
def map(url, klass, options = {})
|
33
50
|
format = url
|
51
|
+
|
52
|
+
if options[:transition] && !TRANSITION_STYLES.keys.include?(options[:transition])
|
53
|
+
raise ArgumentError, ":transition must be one of #{TRANSITION_STYLES.keys}"
|
54
|
+
end
|
55
|
+
|
56
|
+
if options[:presentation] && !PRESENTATION_STYLES.keys.include?(options[:presentation])
|
57
|
+
raise ArgumentError, ":presentation must be one of #{PRESENTATION_STYLES.keys}"
|
58
|
+
end
|
59
|
+
|
34
60
|
self.routes[format] = options.merge!(klass: klass)
|
35
61
|
end
|
36
62
|
|
@@ -50,6 +76,8 @@ module Routable
|
|
50
76
|
else
|
51
77
|
tempNavigationController = UINavigationController.alloc.init
|
52
78
|
tempNavigationController.pushViewController(controller, animated: false)
|
79
|
+
tempNavigationController.modalTransitionStyle = controller.modalTransitionStyle
|
80
|
+
tempNavigationController.modalPresentationStyle = controller.modalPresentationStyle
|
53
81
|
self.navigation_controller.presentModalViewController(tempNavigationController, animated: animated)
|
54
82
|
end
|
55
83
|
else
|
@@ -61,6 +89,17 @@ module Routable
|
|
61
89
|
end
|
62
90
|
end
|
63
91
|
|
92
|
+
# Pop the top level UIViewController
|
93
|
+
# EX
|
94
|
+
# router.pop
|
95
|
+
def pop(animated = true)
|
96
|
+
if self.navigation_controller.modalViewController
|
97
|
+
self.navigation_controller.dismissModalViewControllerAnimated(animated)
|
98
|
+
else
|
99
|
+
self.navigation_controller.popViewControllerAnimated(animated)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
64
103
|
def options_for_url(url)
|
65
104
|
# map of url => options
|
66
105
|
|
@@ -136,6 +175,7 @@ module Routable
|
|
136
175
|
else
|
137
176
|
controller = controller.init
|
138
177
|
end
|
178
|
+
|
139
179
|
if open_options[:shared]
|
140
180
|
shared_vc_cache[url] = controller
|
141
181
|
# when controller.viewDidUnload called, remove from cache.
|
@@ -149,6 +189,17 @@ module Routable
|
|
149
189
|
end
|
150
190
|
end
|
151
191
|
end
|
192
|
+
|
193
|
+
transition = open_options[:transition]
|
194
|
+
if transition
|
195
|
+
controller.modalTransitionStyle = TRANSITION_STYLES[transition]
|
196
|
+
end
|
197
|
+
|
198
|
+
presentation = open_options[:presentation]
|
199
|
+
if presentation
|
200
|
+
controller.modalPresentationStyle = PRESENTATION_STYLES[presentation]
|
201
|
+
end
|
202
|
+
|
152
203
|
controller
|
153
204
|
end
|
154
205
|
|
data/lib/routable/version.rb
CHANGED
data/spec/main_spec.rb
CHANGED
@@ -11,6 +11,9 @@ end
|
|
11
11
|
class NoParamsController < UIViewController
|
12
12
|
end
|
13
13
|
|
14
|
+
class LoginController < UIViewController
|
15
|
+
end
|
16
|
+
|
14
17
|
describe "the url router" do
|
15
18
|
before do
|
16
19
|
@router = Routable::Router.new
|
@@ -68,4 +71,35 @@ describe "the url router" do
|
|
68
71
|
@router.open("users")
|
69
72
|
@nav_controller.viewControllers.count.should == 3
|
70
73
|
end
|
74
|
+
|
75
|
+
it "should use transition option" do
|
76
|
+
[:cover, :flip, :dissolve, :curl].each do |transition|
|
77
|
+
url = "login/#{transition.to_s}"
|
78
|
+
@router.map(url, LoginController, modal: true, transition:transition)
|
79
|
+
controller = @router.controller_for_url(url)
|
80
|
+
controller.modalTransitionStyle.should == Routable::Router::TRANSITION_STYLES[transition]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should raise error when transition is unexpected value" do
|
85
|
+
lambda do
|
86
|
+
@router.map("login", LoginController, modal: true, transition: :unexpected)
|
87
|
+
end.should.raise(ArgumentError)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should use presentation option" do
|
91
|
+
[:full_screen, :page_sheet, :form_sheet, :current].each do |presentation|
|
92
|
+
url = "login/#{presentation.to_s}"
|
93
|
+
@router.map(url, LoginController, modal: true, presentation:presentation)
|
94
|
+
controller = @router.controller_for_url(url)
|
95
|
+
controller.modalPresentationStyle.should == Routable::Router::PRESENTATION_STYLES[presentation]
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
it "should raise error when presentation is unexpected value" do
|
100
|
+
lambda do
|
101
|
+
@router.map("login", LoginController, modal: true, presentation: :unexpected)
|
102
|
+
end.should.raise(ArgumentError)
|
103
|
+
end
|
104
|
+
|
71
105
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: routable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.0.
|
5
|
+
version: 0.0.2
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Clay Allsopp
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2012-
|
13
|
+
date: 2012-06-09 00:00:00 Z
|
14
14
|
dependencies: []
|
15
15
|
|
16
16
|
description: A RubyMotion UIViewController -> URL router
|