routable 0.1.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ YzlmMzAzYzFlNDE4MDMyNTI4NTY1MmFkZGVhMGFkMDNjY2QxNjVkYQ==
5
+ data.tar.gz: !binary |-
6
+ ODcxNjZmOWUyNDdlNWQwYWNjNWUyZmI0NzUzNzI5YmU2YjIwNGZmMQ==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MDE5MDdiYmMwMTFlOWRhNzZlZjQyMGEzODI2ZWY4NDc4YzYwNWVmYTc2ODYy
10
+ MThkMWVkYjM4Mjk1ZjRmZjk3Y2RhNWIzZDU4NDJjN2E5OWI5NTQwNzcwYTlk
11
+ NzQwOTVlOTk0NTAwODkzNWMwMWVhOTZiMjkwYTIwMGE0NzAyNDk=
12
+ data.tar.gz: !binary |-
13
+ OWVkYTJmZmNlZTNlNDFiN2Y3NGRmNWRjNDhiZTNlNGRiM2M5NTRkMzExMmVm
14
+ ZWQ1ZDMzYjE3NTRkYjVlNDIxNjVjYmRiNTQ2MDFkYzUxN2U0NDQyNGY4ZDFl
15
+ NTkyZTNjZDQ5MjFjMDgzY2I3NzNlMTJiNTlmNjk2YmRmNTllYjU=
data/README.md CHANGED
@@ -74,11 +74,14 @@ class AppDelegate
74
74
 
75
75
  # :modal means we push it modally.
76
76
  @router.map("login", LoginController, modal: true)
77
+
77
78
  # :shared means it will only keep one instance of this VC in the hierarchy;
78
79
  # if we push it again later, it will pop any covering VCs.
79
80
  @router.map("menu", MenuController, shared: true)
80
81
  @router.map("profile/:id", ProfileController)
81
- @router.map("messages", MessagesController)
82
+
83
+ # :resets will reset the navigation stack with the target view controller
84
+ @router.map("messages", MessagesController, resets: true)
82
85
  @router.map("message/:id", MessageThreadController)
83
86
 
84
87
  # can also route arbitrary blocks of code
@@ -93,3 +96,16 @@ class AppDelegate
93
96
  end
94
97
  end
95
98
  ```
99
+
100
+ ## Configuration of View Controllers
101
+
102
+ If you need to configure a view controller before the router navigates to it, use a block:
103
+
104
+ ``` ruby
105
+ # Configure and push an ImageEditorController
106
+ BW::Device.camera.any.picture(media_types: [:movie, :image]) do |result|
107
+ router.open('editor') do |controller|
108
+ controller.image = result[:original_image]
109
+ end
110
+ end
111
+ ```
@@ -47,6 +47,8 @@ module Routable
47
47
  # - We present the VC modally (router is not shared between the new nav VC)
48
48
  # :shared => true/false
49
49
  # - If URL is called again, we pop to that VC if it's in memory.
50
+ # :resets => true/false
51
+ # - Resets the navigation stack with the target view controller
50
52
  # :transition => [:cover, :flip, :dissolve, :curl]
51
53
  # - A symbol to represented transition style used. Mapped to UIModalTransitionStyle.
52
54
  # :presentation => [:full_screen, :page_sheet, :form_sheet, :current]
@@ -69,11 +71,19 @@ module Routable
69
71
  self.routes[format] = options.merge!(klass: klass)
70
72
  end
71
73
 
74
+ # Open the given URL via the iOS protocol
75
+ # EX
76
+ # router.open_external("http://google.com")
77
+ # => Opens Google in Safari.app
78
+ def open_external(url)
79
+ UIApplication.sharedApplication.openURL(NSURL.URLWithString(url))
80
+ end
81
+
72
82
  # Push the UIViewController for the given url
73
83
  # EX
74
84
  # router.open("users/3")
75
85
  # => router.navigation_controller pushes a UsersController
76
- def open(url, animated = true)
86
+ def open(url, animated = true, &block)
77
87
  controller_options = options_for_url(url)
78
88
 
79
89
  if controller_options[:callback]
@@ -89,10 +99,28 @@ module Routable
89
99
  end
90
100
 
91
101
  controller = controller_for_url(url)
102
+
103
+ # Allow configuration of the view controller after
104
+ # initialization but before navigating to the view controller
105
+ if block_given?
106
+ block.call(controller)
107
+ end
108
+
92
109
  if self.navigation_controller.modalViewController
93
- self.navigation_controller.dismissModalViewControllerAnimated(animated)
110
+ dismiss_animated = animated
111
+
112
+ # Can't dismiss and present two controllers animated at the same time,
113
+ # so we just dismiss the current one without an animation
114
+ if controller_options[:modal] && dismiss_animated
115
+ dismiss_animated = false
116
+ end
117
+
118
+ self.navigation_controller.dismissModalViewControllerAnimated(dismiss_animated)
94
119
  end
95
- if controller_options[:modal]
120
+
121
+ if controller_options[:resets]
122
+ navigation_controller.setViewControllers([controller], animated: animated)
123
+ elsif controller_options[:modal]
96
124
  if controller.class == UINavigationController
97
125
  self.navigation_controller.presentModalViewController(controller, animated: animated)
98
126
  else
@@ -231,4 +259,4 @@ module Routable
231
259
  @shared_vc_cache ||= {}
232
260
  end
233
261
  end
234
- end
262
+ end
@@ -1,3 +1,3 @@
1
1
  module Routable
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2"
3
3
  end
@@ -14,6 +14,16 @@ end
14
14
  class LoginController < UIViewController
15
15
  end
16
16
 
17
+ class ConfigurableController < UIViewController
18
+ attr_accessor :configured
19
+
20
+ def init
21
+ super.tap do |controller|
22
+ controller.configured = false
23
+ end
24
+ end
25
+ end
26
+
17
27
  describe "the url router" do
18
28
  before do
19
29
  @router = Routable::Router.new
@@ -23,6 +33,21 @@ describe "the url router" do
23
33
  @nav_controller.viewControllers.count.should == 0
24
34
  end
25
35
 
36
+ describe '#open' do
37
+ it 'accepts a configuration block' do
38
+ url = 'configured'
39
+ @router.navigation_controller = @nav_controller
40
+ @router.map(url, ConfigurableController, shared: true)
41
+
42
+ @router.open(url) do |controller|
43
+ controller.configured = true
44
+ end
45
+
46
+ controller = @router.controller_for_url(url)
47
+ controller.configured.should.be.true
48
+ end
49
+ end
50
+
26
51
  def make_test_controller_route
27
52
  format = "users/:user_id"
28
53
  @router.map(format, UsersTestController)
@@ -121,4 +146,17 @@ describe "the url router" do
121
146
  @router.open("logout/123")
122
147
  @called.should == "123"
123
148
  end
124
- end
149
+
150
+ describe 'reset option' do
151
+ it 'resets the navigation controller stack with the target controller' do
152
+ @router.navigation_controller = @nav_controller
153
+ @router.map('start', NoParamsController)
154
+ @router.map('reset', NoParamsController, resets: true)
155
+
156
+ @router.open('start')
157
+ @router.open('reset')
158
+
159
+ @router.navigation_controller.viewControllers.count.should == 1
160
+ end
161
+ end
162
+ end
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
5
- prerelease:
4
+ version: '0.2'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Clay Allsopp
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-03-25 00:00:00.000000000 Z
11
+ date: 2013-05-06 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: A RubyMotion UIViewController -> URL router
15
14
  email:
@@ -30,27 +29,26 @@ files:
30
29
  - spec/main_spec.rb
31
30
  homepage: https://github.com/clayallsopp/Routable
32
31
  licenses: []
32
+ metadata: {}
33
33
  post_install_message:
34
34
  rdoc_options: []
35
35
  require_paths:
36
36
  - lib
37
37
  required_ruby_version: !ruby/object:Gem::Requirement
38
- none: false
39
38
  requirements:
40
39
  - - ! '>='
41
40
  - !ruby/object:Gem::Version
42
41
  version: '0'
43
42
  required_rubygems_version: !ruby/object:Gem::Requirement
44
- none: false
45
43
  requirements:
46
44
  - - ! '>='
47
45
  - !ruby/object:Gem::Version
48
46
  version: '0'
49
47
  requirements: []
50
48
  rubyforge_project:
51
- rubygems_version: 1.8.23
49
+ rubygems_version: 2.0.3
52
50
  signing_key:
53
- specification_version: 3
51
+ specification_version: 4
54
52
  summary: A RubyMotion UIViewController -> URL router
55
53
  test_files:
56
54
  - spec/main_spec.rb