lib/routable/router.rb in routable-0.0.3 vs lib/routable/router.rb in routable-0.1.0
- old
+ new
@@ -35,22 +35,31 @@
end
# Map a URL to a UIViewController
# EX
# router.map "/users/:id", UsersController
+ # PARAMS
+ # url => the URL to map
+ # klass (optional) => the UIViewController class to open
+ # options (optional) => hash of options
+ # &callback => the block to be run when opening the URL
# OPTIONS
# :modal => true/false
# - We present the VC modally (router is not shared between the new nav VC)
# :shared => true/false
# - If URL is called again, we pop to that VC if it's in memory.
# :transition => [:cover, :flip, :dissolve, :curl]
# - A symbol to represented transition style used. Mapped to UIModalTransitionStyle.
# :presentation => [:full_screen, :page_sheet, :form_sheet, :current]
# - A symbol to represented presentation style used. Mapped to UIModalPresentationStyle.
- def map(url, klass, options = {})
+ def map(url, klass = nil, options = {}, &callback)
format = url
+ if callback
+ self.routes[format] = options.merge!(callback: callback)
+ end
+
if options[:transition] && !TRANSITION_STYLES.keys.include?(options[:transition])
raise ArgumentError, ":transition must be one of #{TRANSITION_STYLES.keys}"
end
if options[:presentation] && !PRESENTATION_STYLES.keys.include?(options[:presentation])
@@ -64,10 +73,16 @@
# EX
# router.open("users/3")
# => router.navigation_controller pushes a UsersController
def open(url, animated = true)
controller_options = options_for_url(url)
+
+ if controller_options[:callback]
+ controller_options[:callback].call
+ return
+ end
+
controller = controller_for_url(url)
if self.navigation_controller.modalViewController
self.navigation_controller.dismissModalViewControllerAnimated(animated)
end
if controller_options[:modal]
@@ -203,10 +218,9 @@
end
controller
end
- private
def shared_vc_cache
@shared_vc_cache ||= {}
end
end
end
\ No newline at end of file