From 37a224ac6b30b034b82962c5dddec3df8898df3e Mon Sep 17 00:00:00 2001 From: "Gun.io Whitespace Robot" Date: Sat, 29 Oct 2011 08:10:35 -0400 Subject: [PATCH] Remove whitespace [Gun.io WhitespaceBot] --- .gitignore | 20 ++++++++++++++++++++ concat.js | 12 ++++++------ demo.js | 20 ++++++++++---------- head.js | 8 ++++---- html.js | 24 ++++++++++++------------ index.js | 6 +++--- log.js | 2 +- method.js | 4 ++-- node/addContentLength.js | 8 ++++---- node/fs.js | 2 +- node/listen.js | 4 ++-- node/listener.js | 18 +++++++++--------- queue.js | 12 ++++++------ render.js | 6 +++--- route.js | 18 +++++++++--------- run.js | 6 +++--- sleep.js | 2 +- 17 files changed, 96 insertions(+), 76 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ac8f968 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# Compiled source # +################### +*.com +*.class +*.dll +*.exe +*.o +*.so +*.pyc + +# Logs and databases # +###################### +*.log + +# OS generated files # +###################### +.DS_Store* +ehthumbs.db +Icon? +Thumbs.db diff --git a/concat.js b/concat.js index 4aa4dc5..5865ac9 100644 --- a/concat.js +++ b/concat.js @@ -2,24 +2,24 @@ module.exports = function( exports ) { return exports( function( write ) { var buffer = "" , types = { String: true, Buffer: true }; - + return function read( body, head ) { // TODO: add timeout to flush? - + if ( head && head.status >= 400 ) { write( body, head )(); return function x(){ return x }; } - + else if ( body && types[ body.constructor.name ] ) buffer += body; - + else { if ( buffer ) write = write( buffer ); - + buffer = ""; write = write.apply( undefined, arguments ); } - + return arguments.length ? read : write; } }); diff --git a/demo.js b/demo.js index 19cb1f7..f6ba9a1 100644 --- a/demo.js +++ b/demo.js @@ -35,30 +35,30 @@ module.exports = function( exports, imports ) { // this is blank because we don't need to give run a downstream function, // since we're not piping anything to stdout. () - + // this fires up a listener on port 4011 ( node$listen, 0xFAB ) - + // let's route for static files. route is an app that takes two streams, // one for matches and one for non-matches. ( route, /^\/static/ ) // we matched! - + // the fs module takes one stream: the path name. it's just middleware // that converts an upstream path name to the contents of the file. ( node$fs ) // first, get the current directory ( __dirname ) - + // then sleep for 500, just because we can ( sleep, 500 ) - + // then append the pathname ( head.url.pathname ) () () // we didn't match the /static url, so we keep going. - + // now let's return the front page ( route, /^\/hello/ ) // since we've with'ed the html app above, each uppercase element @@ -69,7 +69,7 @@ module.exports = function( exports, imports ) { ( HTML ) ( BODY, { id: "show" } ) ( "Hello, " ) - + ( EM ) // this pattern looks for a url that ends with an alphanumeric string ( route, /^\/(\w+)$/ ) @@ -77,15 +77,15 @@ module.exports = function( exports, imports ) { // the captured path segment at the given index. ( route.capture, 0 ) () - // we didn't match, so let's output a generic hello. + // we didn't match, so let's output a generic hello. ( "world" ) () - + ( "!" ) () () () - + // this is a catchall 404 for any paths that haven't matched. ( "Not found.", { status: 404 } ) (); diff --git a/head.js b/head.js index b7aede8..1dd04c3 100644 --- a/head.js +++ b/head.js @@ -5,7 +5,7 @@ module.exports = function( exports ) { url: "href protocol host auth hostname port pathname search query hash capture", headers: "accept acceptCharset acceptEncoding acceptLanguage acceptRanges authorization cacheControl connection cookie contentLength contentType date expect from host ifMatch ifModifiedSince ifNoneMatch ifRange ifUnmodifiedSince maxForwards pragma proxyAuthorization range referer te upgrade userAgent via warning" }; - + for ( prop in props ) { var subprops = props[ prop ].split( " " ); @@ -14,12 +14,12 @@ module.exports = function( exports ) { head[ prop ][ subprop ] = getter( "head." + prop + "." + subprop ); } } - + return exports( head ); - + function writer( val ) { return new Function( "write", "head", "return write(" + val + ")" ); } - function getter( name ){ return writer( writer( name ) ) } + function getter( name ){ return writer( writer( name ) ) } }; \ No newline at end of file diff --git a/html.js b/html.js index 7462020..a6171f6 100644 --- a/html.js +++ b/html.js @@ -16,56 +16,56 @@ module.exports = function( exports ) { SOURCE WBR".split( " " ) ]; - + for ( var isVoid = 0, names; names = tags[ isVoid ]; isVoid++ ) { for ( var i = 0, name; name = names[ i++ ]; ) { elem[ name ] = elem( name.toLowerCase(), !!isVoid ); } } - + elem.DOCTYPE = function( write, dec ) { return write( "\n" ); } elem.COMMENT = function( write ) { write = write( "" ); write = write( obj ); - return read; + return read; } } - + return exports( elem ); - + function elem( name, isVoid ) { return function( write, obj ) { write = write( "<" + name ); write = attrs( write )( obj )( ">" ); - + if ( isVoid ) return write; - + return function read( arg ) { if ( !arguments.length ) return write( "" ); - + write = write.apply( undefined, arguments ); return read; }; } } - + function attrs( write ) { return function read( obj ) { for ( var name in obj ) { write = write( " " )( name )( "=" ); write = attr( write )( obj[ name ] ); } - + return write; } } - + function attr( write ) { return function read( value ) { return write( "\"" )( value )( "\"" ); diff --git a/index.js b/index.js index 0151ada..ce3d13a 100644 --- a/index.js +++ b/index.js @@ -15,15 +15,15 @@ function imports( exports ) { : exports.toString() .split( /[^\w$]+/, exports.length + !!exports.name + 1 ) .slice( !!exports.name + 1 ); - + ( function loop() { var name = names.shift(); if ( !name ) exports.apply( undefined, libs ); - + else { console.log( name.replace( /\W/g, "/" ), name.replace( /\W/g, "/" ) ) - + require( name.replace( /\W/g, "/" ) )( function( lib ) { libs.push( lib ); loop(); diff --git a/log.js b/log.js index be6abff..f0607b2 100644 --- a/log.js +++ b/log.js @@ -4,7 +4,7 @@ module.exports = function( exports ) { console.log( msg ); return write; } - + return function read( body ) { console.log( body ); write = write.apply( undefined, arguments ); diff --git a/method.js b/method.js index ff93918..0d3dd32 100644 --- a/method.js +++ b/method.js @@ -1,7 +1,7 @@ module.exports = function( exports, imports ) { return imports( function( queue ) { var names = "GET PUT POST DELETE HEAD".split( " " ); - + function method( write, name ) { return queue( function( yes ) { return queue( function( no ) { @@ -11,7 +11,7 @@ module.exports = function( exports, imports ) { }); }); } - + for ( var i = names.length; i--; ) ( function( name ) { method[ name ] = function( write ) { return method( write, name ); diff --git a/node/addContentLength.js b/node/addContentLength.js index 3fa4f18..48b1ce2 100644 --- a/node/addContentLength.js +++ b/node/addContentLength.js @@ -5,16 +5,16 @@ module.exports = function( exports, imports ) { return write( function( write, head, body ) { var buffered = queue() , length = 0; - + return upstream( render( function read( body, head ) { buffered = buffered.apply( this, arguments ); - + if ( !arguments.length ) return buffered( write( undefined, { headers: { "content-length": length } } ) ); - + if ( body ) length += body.length; - + return read; }, head, body ), head, body ); })(); diff --git a/node/fs.js b/node/fs.js index 4270ab1..39a0b04 100644 --- a/node/fs.js +++ b/node/fs.js @@ -13,7 +13,7 @@ module.exports = function( exports, imports ) { .on( "error", function(){ rest( write( "File not found: " + path, { status: 404 } ), head, body )}); - + return ignore; }, head, body ), head, body), head, body ); }); diff --git a/node/listen.js b/node/listen.js index bdf5971..f4e9f40 100644 --- a/node/listen.js +++ b/node/listen.js @@ -8,12 +8,12 @@ module.exports = function( exports, imports ) { server = http.createServer(); server.listen( where ); } - + return queue( function( upstream ) { upstream( listener( function( listener ) { server.on( "request", listener ); })) - + return upstream( write ); }); }); diff --git a/node/listener.js b/node/listener.js index caa2eb6..a9242e9 100644 --- a/node/listener.js +++ b/node/listener.js @@ -10,45 +10,45 @@ module.exports = function( exports, imports ) { function listener( req, res ) { var status = 200 , headers = {}; - + upstream( render( read, - + { method: req.method, headers: req.headers, url: url.parse( "//" + req.headers.host + req.url, false, true ) }, - + function body( write ) { req.on( "data", write ).on( "end", write ); } )); - + function read( body, head ) { if ( !arguments.length ) res.end(); - + else { if ( head ) { if ( "status" in head ) status = head.status; - + if ( "headers" in head ) { for ( var name in head.headers ) { headers[ name ] = head.headers[ name ] } } } - + if ( body ) { if ( headers ) { res.writeHead( status, headers ); headers = undefined; } - + res.write( body ); } } - + return read; } } diff --git a/queue.js b/queue.js index 46b97a6..a76b7b5 100644 --- a/queue.js +++ b/queue.js @@ -1,20 +1,20 @@ module.exports = function( exports ) { return exports( function( write, queue ) { queue = queue || []; - + var length = queue.length; - - function drain( write, req ) { + + function drain( write, req ) { for ( var i = 0; i < length; ) { write = write.apply( undefined, queue[ i++ ] ); } - + return write(); }; - + return function read() { if ( !arguments.length ) return write ? write( drain ) : drain; - + queue[ length++ ] = arguments; return read; } diff --git a/render.js b/render.js index 655da28..cbeee87 100644 --- a/render.js +++ b/render.js @@ -1,15 +1,15 @@ module.exports = function( exports ) { return exports( function( write ) { var args = [].slice.call( arguments ); - + return function read( obj ) { if ( obj && obj.apply ) { args[ 0 ] = read; return obj.apply( undefined, args ); } - + write = write.apply( undefined, arguments ); - + return arguments.length ? read : write; } }); diff --git a/route.js b/route.js index 34b1702..8d174a0 100644 --- a/route.js +++ b/route.js @@ -8,30 +8,30 @@ module.exports = function( exports, imports ) { return write( i >= 0 ? capture[ i ] : capture ); }); } - + return exports( route ); - + function route( write, pattern ) { return queue( function( yes ) { return queue( function( no ) { return write( function( write, head, body ) { var app = no , url = head.url; - + url.pathname = url.pathname.replace( pattern, function() { app = yes; - + url.capture = ( url.capture || [] ) .concat( slice.call( arguments, 1, -2 ) ); - - return ""; + + return ""; }); - + return app( function read( data ) { if ( !arguments.length ) return write; - + write = write.apply( this, arguments ); - return read; + return read; }, head, body ); })(); }); diff --git a/run.js b/run.js index 13cf340..5476722 100644 --- a/run.js +++ b/run.js @@ -1,16 +1,16 @@ module.exports = function( exports, imports ) { return exports( function run( write, imports ) { write = write || function x(){ return x } - + return function read( obj ) { if ( obj && obj.apply ) { var fn = obj; - + arguments[ 0 ] = write; return run( fn.apply( undefined, arguments ) ); } - + write = write.apply( undefined, arguments ); return read; } diff --git a/sleep.js b/sleep.js index 89e7526..41c0bc7 100644 --- a/sleep.js +++ b/sleep.js @@ -5,7 +5,7 @@ module.exports = function( exports, imports ) { return queue( function( rest ) { setTimeout( function(){ return rest( write ) }, - duration || 0 + duration || 0 ); }); });