Skip to content

Instantly share code, notes, and snippets.

@jeffrydegrande
Created January 17, 2013 16:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffrydegrande/4557239 to your computer and use it in GitHub Desktop.
Save jeffrydegrande/4557239 to your computer and use it in GitHub Desktop.
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