Created
July 16, 2011 17:15
-
-
Save func09/1086556 to your computer and use it in GitHub Desktop.
routes.js.coffee
This file contains hidden or 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
match = (path, callback) -> | |
$ -> | |
param_names = path.match(/:([\w]+)/g) | |
regexp = new RegExp('^'+path.replace(/:[\w]+/g,'([\\w]+)')+'$') | |
if m = window.location.pathname.match regexp | |
m.shift() | |
params = {} | |
if param_names | |
for param_name in param_names | |
params[param_name] = m.shift() | |
callback.apply this, [params] | |
window.match = match | |
# in other file examples | |
match '/users/:id', (params) -> | |
App.User.Show.instance().setup(params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment