Created
April 3, 2012 19:58
-
-
Save denniskuczynski/2295142 to your computer and use it in GitHub Desktop.
A Helper for testing Backbone route matching
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.RouteHelpers = { | |
getRouteHandlerMethod: (router, url_fragment) -> | |
routeStripper = /^[#\/]/; | |
url_fragment = url_fragment.replace(routeStripper, '') | |
routes = Object.keys(router.routes) | |
return _.find routes, (route) => | |
regexp = router._routeToRegExp(route) | |
if (regexp.test(url_fragment)) | |
return true | |
else | |
return false | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment