Created
January 17, 2013 16:25
-
-
Save jeffrydegrande/4557239 to your computer and use it in GitHub Desktop.
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
class Router | |
@prefix = "something" | |
@path: (url)-> @prefix + url | |
@pathWithArgs: (url, args)-> @prefix + url + @serialize(args) | |
@serialize = (obj, prefix) -> | |
str = [] | |
for p, v of obj | |
k = if prefix then prefix + "[" + p + "]" else p | |
if typeof v == "object" | |
str.push(serialize(v, k)) | |
else | |
str.push(encodeURIComponent(k) + "=" + encodeURIComponent(v)) | |
str.join("&") | |
# route definitions | |
@people_path: -> @path "/people" | |
@person_path: (id, args)-> @pathWithArgs("/person/#{id}?", args) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment