(function(){
var ref$, Some, None, compilePath, guard, respond, i$, len$, m, out$ = typeof exports != 'undefined' && exports || this;
ref$ = require('fantasy-options'), Some = ref$.Some, None = ref$.None;
compilePath = require('./compiler').compilePath;
guard = function(cond){
if (cond) {
return Some(null);
} else {
return None;
}
};
out$.respond = respond = curry$(function(method, path, responder){
var lower, extract;
lower = method.toLowerCase();
extract = compilePath(path);
return function(request){
return guard(lower === method.toLowerCase()).chain(function(){
return extract(request.url).chain(function(params){
return Some(responder((request.params = params, request)));
});
});
};
});
for (i$ = 0, len$ = (ref$ = ['get', 'post', 'put', 'delete', 'patch', 'options', 'head', 'trace', 'connect']).length; i$ < len$; ++i$) {
m = ref$[i$];
exports[m] = respond(m);
}
function curry$(f, bound){
var context,
_curry = function(args) {
return f.length > 1 ? function(){
var params = args ? args.concat() : [];
context = bound ? context || this : this;
return params.push.apply(params, arguments) <
f.length && arguments.length ?
_curry.call(context, params) : f.apply(context, params);
} : f;
};
return _curry();
}
}).call(this);
|