routable 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -81,6 +81,11 @@ class AppDelegate
81
81
  @router.map("messages", MessagesController)
82
82
  @router.map("message/:id", MessageThreadController)
83
83
 
84
+ # can also route arbitrary blocks of code
85
+ @router.map("logout") do
86
+ User.logout
87
+ end
88
+
84
89
  @window.rootViewController = @router.navigation_controller
85
90
  end
86
91
  end
@@ -37,6 +37,11 @@ module Routable
37
37
  # Map a URL to a UIViewController
38
38
  # EX
39
39
  # router.map "/users/:id", UsersController
40
+ # PARAMS
41
+ # url => the URL to map
42
+ # klass (optional) => the UIViewController class to open
43
+ # options (optional) => hash of options
44
+ # &callback => the block to be run when opening the URL
40
45
  # OPTIONS
41
46
  # :modal => true/false
42
47
  # - We present the VC modally (router is not shared between the new nav VC)
@@ -46,9 +51,13 @@ module Routable
46
51
  # - A symbol to represented transition style used. Mapped to UIModalTransitionStyle.
47
52
  # :presentation => [:full_screen, :page_sheet, :form_sheet, :current]
48
53
  # - A symbol to represented presentation style used. Mapped to UIModalPresentationStyle.
49
- def map(url, klass, options = {})
54
+ def map(url, klass = nil, options = {}, &callback)
50
55
  format = url
51
56
 
57
+ if callback
58
+ self.routes[format] = options.merge!(callback: callback)
59
+ end
60
+
52
61
  if options[:transition] && !TRANSITION_STYLES.keys.include?(options[:transition])
53
62
  raise ArgumentError, ":transition must be one of #{TRANSITION_STYLES.keys}"
54
63
  end
@@ -66,6 +75,12 @@ module Routable
66
75
  # => router.navigation_controller pushes a UsersController
67
76
  def open(url, animated = true)
68
77
  controller_options = options_for_url(url)
78
+
79
+ if controller_options[:callback]
80
+ controller_options[:callback].call
81
+ return
82
+ end
83
+
69
84
  controller = controller_for_url(url)
70
85
  if self.navigation_controller.modalViewController
71
86
  self.navigation_controller.dismissModalViewControllerAnimated(animated)
@@ -205,7 +220,6 @@ module Routable
205
220
  controller
206
221
  end
207
222
 
208
- private
209
223
  def shared_vc_cache
210
224
  @shared_vc_cache ||= {}
211
225
  end
@@ -1,3 +1,3 @@
1
1
  module Routable
2
- VERSION = "0.0.3"
2
+ VERSION = "0.1.0"
3
3
  end
data/spec/main_spec.rb CHANGED
@@ -102,4 +102,13 @@ describe "the url router" do
102
102
  end.should.raise(ArgumentError)
103
103
  end
104
104
 
105
+ it "should work with callback blocks" do
106
+ @called = false
107
+ @router.map("logout") do
108
+ @called = true
109
+ end
110
+
111
+ @router.open("logout")
112
+ @called.should == true
113
+ end
105
114
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: routable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-10 00:00:00.000000000 Z
12
+ date: 2013-03-25 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: A RubyMotion UIViewController -> URL router
15
15
  email: