Skip to content

Instantly share code, notes, and snippets.

/foo.js Secret

Created August 8, 2015 17:42
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 anonymous/de95b1d2e95da7a2fe3e to your computer and use it in GitHub Desktop.
Save anonymous/de95b1d2e95da7a2fe3e to your computer and use it in GitHub Desktop.
function ActionHandle() {
this.quux = 'quuz';
}
function Router() {
var self = this;
var ROUTES = {
"GET": {},
"POST": {},
"PATCH": {},
"DELETE": {}
};
self.get = function(path, action, method){
return compile_route_listing (path, action, method);
};
// this is how I view the routing listings outside of the debugging call below
self.list = function(){
console.dir(ROUTES);
};
function compile_route_listing(path, action, method){
var parts = action.split ("#"); // -> [controller, action]
var qualifier = new RegExp (path, "i");
var handle = new ActionHandle (parts[0], parts[1]);
ROUTES[method][path] = {
"qualifier": qualifier,
"handle": handle
};
console.dir(ROUTES); // debugging call, does same thing as self.list
return true;
}
}
var r = new Router();
r.get('foo', 'bar#baz', 'POST');
r.list();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment