nl_tokens: route () is the main method for defining routes within an application . For great detail on routes check out : http : // code . quirkey . com / sammy / doc / routes . html This method also has aliases for each of the different verbs ( eg . get () post () etc . ) ### Arguments * verb A String in the set of ROUTE_VERBS or any . any will add routes for each of the ROUTE_VERBS . If only two arguments are passed the first argument is the path the second is the callback and the verb is assumed to be any . * path A Regexp or a String representing the path to match to invoke this verb . * callback A Function that is called / evaluated whent the route is run see : runRoute () . It is also possible to pass a string as the callback which is looked up as the name of a method on the application .
pl_tokens: function ( verb , path , callback ) { var app = this , param_names = [ ] , add_route , path_match ; // if the method signature is just (path, callback) // assume the verb is 'any' if ( ! callback && _isFunction ( path ) ) { path = verb ; callback = path ; verb = 'any' ; } verb = verb . toLowerCase ( ) ; // ensure verb is lower case // if path is a string turn it into a regex if ( path . constructor == <mask> ) { // Needs to be explicitly set because IE will maintain the index unless NULL is returned, // which means that with two consecutive routes that contain params, the second set of params will not be found and end up in splat instead of params // https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/RegExp/lastIndex PATH_NAME_MATCHER . lastIndex = 0 ; // find the names while ( ( path_match = PATH_NAME_MATCHER . exec ( path ) ) !== null ) { param_names . push ( path_match [ 1 ] ) ; } // replace with the path replacement path = new RegExp ( "^" + path . replace ( PATH_NAME_MATCHER , PATH_REPLACER ) + "$" ) ; } // lookup callback if ( typeof callback == 'string' ) { callback = app [ callback ] ; } add_route = function ( with_verb ) { var r = { verb : with_verb , path : path , callback : callback , param_names : param_names } ; // add route to routes array app . routes [ with_verb ] = app . routes [ with_verb ] || [ ] ; // place routes in order of definition app . routes [ with_verb ] . push ( r ) ; } ; if ( verb === 'any' ) { $ . each ( this . ROUTE_VERBS , function ( i , v ) { add_route ( v ) ; } ) ; } else { add_route ( verb ) ; } // return the app return this ; }