the-tramp
Version:
Chaplin.js on Node.js. Use it for performance boosts, SEO, re-usability.
34 lines (22 loc) • 979 B
text/coffeescript
Chaplin = require 'chaplin'
module.exports = (handlers) ->
return match = (pattern, target, options) ->
if arguments.length is 2 and typeof target is 'object'
options = target
{controller, action} = options
unless controller and action
throw new Error 'Router#match must receive either target or ' +
'options.controller & options.action'
else
if typeof options is 'object'
{controller, action} = options
if controller or action
throw new Error 'Router#match cannot use both target and ' +
'options.controller / options.action'
[] = target.split('#')
route = new Chaplin.Route pattern, controller, action, options
handlers.push({route: route})