From 84cbbc5cffa692c6586f4a5cdbc69ae2dfff6d65 Mon Sep 17 00:00:00 2001 From: jed Date: Sun, 26 Sep 2010 11:15:54 +0200 Subject: [PATCH] started from scratch... again --- LICENSE.txt | 20 -------- README.md | 27 ----------- apps/fab.body.js | 39 ---------------- apps/fab.capture.at.js | 16 ------- apps/fab.capture.js | 12 ----- apps/fab.collect.js | 23 ---------- apps/fab.defaults.Function.js | 5 -- apps/fab.defaults.Number.js | 15 ------ apps/fab.defaults.RegExp.js | 9 ---- apps/fab.defaults.js | 5 -- apps/fab.echo.js | 21 --------- apps/fab.filter.js | 18 -------- apps/fab.identity.js | 21 --------- apps/fab.js | 41 ----------------- apps/fab.map.body.js | 18 -------- apps/fab.map.js | 41 ----------------- apps/fab.method.DELETE.js | 7 --- apps/fab.method.GET.js | 7 --- apps/fab.method.POST.js | 7 --- apps/fab.method.PUT.js | 7 --- apps/fab.method.js | 52 --------------------- apps/fab.nodejs.contentLength.js | 14 ------ apps/fab.nodejs.fs.js | 34 -------------- apps/fab.nodejs.http.js | 44 ------------------ apps/fab.nodejs.js | 71 ----------------------------- apps/fab.nodejs.listen.js | 17 ------- apps/fab.parse.js | 12 ----- apps/fab.path.js | 49 -------------------- apps/fab.prepend.js | 14 ------ apps/fab.status.js | 42 ----------------- apps/fab.stringify.js | 11 ----- apps/fab.tap.js | 12 ----- apps/fab.tmpl.js | 34 -------------- builds/all.js | 8 ---- builds/core.js | 12 ----- examples/date.js | 16 ------- examples/focus.js | 66 --------------------------- examples/hello.js | 78 -------------------------------- examples/index.js | 13 ------ index.js | 14 ------ package.json | 16 ------- utils/build.js | 23 ---------- utils/test.js | 27 ----------- 43 files changed, 1038 deletions(-) delete mode 100644 LICENSE.txt delete mode 100644 README.md delete mode 100644 apps/fab.body.js delete mode 100644 apps/fab.capture.at.js delete mode 100644 apps/fab.capture.js delete mode 100644 apps/fab.collect.js delete mode 100644 apps/fab.defaults.Function.js delete mode 100644 apps/fab.defaults.Number.js delete mode 100644 apps/fab.defaults.RegExp.js delete mode 100644 apps/fab.defaults.js delete mode 100644 apps/fab.echo.js delete mode 100644 apps/fab.filter.js delete mode 100644 apps/fab.identity.js delete mode 100644 apps/fab.js delete mode 100644 apps/fab.map.body.js delete mode 100644 apps/fab.map.js delete mode 100644 apps/fab.method.DELETE.js delete mode 100644 apps/fab.method.GET.js delete mode 100644 apps/fab.method.POST.js delete mode 100644 apps/fab.method.PUT.js delete mode 100644 apps/fab.method.js delete mode 100644 apps/fab.nodejs.contentLength.js delete mode 100644 apps/fab.nodejs.fs.js delete mode 100644 apps/fab.nodejs.http.js delete mode 100644 apps/fab.nodejs.js delete mode 100644 apps/fab.nodejs.listen.js delete mode 100644 apps/fab.parse.js delete mode 100644 apps/fab.path.js delete mode 100644 apps/fab.prepend.js delete mode 100644 apps/fab.status.js delete mode 100644 apps/fab.stringify.js delete mode 100644 apps/fab.tap.js delete mode 100644 apps/fab.tmpl.js delete mode 100644 builds/all.js delete mode 100644 builds/core.js delete mode 100644 examples/date.js delete mode 100644 examples/focus.js delete mode 100644 examples/hello.js delete mode 100644 examples/index.js delete mode 100644 index.js delete mode 100644 package.json delete mode 100644 utils/build.js delete mode 100644 utils/test.js diff --git a/LICENSE.txt b/LICENSE.txt deleted file mode 100644 index 7b5b810..0000000 --- a/LICENSE.txt +++ /dev/null @@ -1,20 +0,0 @@ -Copyright (c) 2010 Jed Schmidt, http://jedschmidt.com/ - -Permission is hereby granted, free of charge, to any person obtaining -a copy of this software and associated documentation files (the -"Software"), to deal in the Software without restriction, including -without limitation the rights to use, copy, modify, merge, publish, -distribute, sublicense, and/or sell copies of the Software, and to -permit persons to whom the Software is furnished to do so, subject to -the following conditions: - -The above copyright notice and this permission notice shall be -included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE -LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION -OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION -WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index e8505e5..0000000 --- a/README.md +++ /dev/null @@ -1,27 +0,0 @@ -(fab) - a modular async web framework -===================================== - -(fab) is a lightweight toolkit that makes it easy to build asynchronous web apps. It takes advantage of the flexibility and functional nature of javascript to create a concise "DSL", without pre-compilation or magic scope hackery. - -Here's an example of a "hello world" app: - - with ( require( "fab" ) ) - - ( fab ) - - ( listen, 0xFAB ) - - ( /^\/hello/ ) - - ( tmpl ) - ( "Hello, <%= this %>!" ) - - ( /^\/(\w+)$/ ) - ( capture.at, 0 ) - ( "world" ) - - ( 404 ); - -See [more examples](http://github.com/jed/fab/tree/master/examples/), learn how to [make your own apps](http://wiki.github.com/jed/fab/fab-app-specification), or see the [apps that (fab) provides for you](http://wiki.github.com/jed/fab/built-in-fab-apps). - -Note that subsequent development on (fab) breaks the current API, and is happening over at the [v0.5 branch](http://github.com/jed/fab/tree/v0.5), so check there to see where things are heading. \ No newline at end of file diff --git a/apps/fab.body.js b/apps/fab.body.js deleted file mode 100644 index 2dae8b5..0000000 --- a/apps/fab.body.js +++ /dev/null @@ -1,39 +0,0 @@ -exports.name = "fab.body"; -exports.summary = "Turns an object into a unary app with the object as its response."; -exports.requires = []; -exports.app = body; - -function body( obj ) { - return function() { - var out = this({ body: obj }); - if ( out ) out(); - } -} - -exports.tests = ( function() { - var response = "hello" - , app = body( response ); - - return [ - - function - bodyReturnsUnaryApp() { - this( app.length === 0 ) - }, - - function - bodyRespondsWithCorrectPayload() { - var out = this; - app.call( function( obj ){ out( obj.body === response ) } ); - }, - - function - bodyClosesConnection() { - var out = this; - app.call( function() { - return function(){ out( !arguments.length ) } - }) - } - ]; - -})(); \ No newline at end of file diff --git a/apps/fab.capture.at.js b/apps/fab.capture.at.js deleted file mode 100644 index 7e5f7b9..0000000 --- a/apps/fab.capture.at.js +++ /dev/null @@ -1,16 +0,0 @@ -exports.name = "fab.capture.at"; -exports.summary = "Responds with the captured url component at the given position."; -exports.requires = [ "fab.map", "fab.capture" ]; - -var fab = { - map: require( "./fab.map" ).app, - capture: require( "./fab.capture" ).app -}; - -exports.app = function( pos ) { - pos.call( function( obj ){ pos = obj.body } ); - - return fab.map( function( obj ) { - return { body: obj.body[ pos ] }; - })( fab.capture ); -} \ No newline at end of file diff --git a/apps/fab.capture.js b/apps/fab.capture.js deleted file mode 100644 index 13256e7..0000000 --- a/apps/fab.capture.js +++ /dev/null @@ -1,12 +0,0 @@ -exports.name = "fab.capture"; -exports.summary = "Responds with the captured url components."; -exports.requires = []; - -exports.app = function() { - var out = this; - - return function( head ) { - out = out({ body: head.url.capture || [] }); - if ( out ) out(); - } -} \ No newline at end of file diff --git a/apps/fab.collect.js b/apps/fab.collect.js deleted file mode 100644 index c50c485..0000000 --- a/apps/fab.collect.js +++ /dev/null @@ -1,23 +0,0 @@ -exports.name = "fab.collect"; -exports.summary = "Collects apps until fab.collect.end appears, then returns an app that responds with the apps collected." -exports.requires = [ "fab.body" ]; - -var fab = { body: require( "./fab.body" ).app }; - -exports.app = ( function() { - collect.end = end; - return collect; - - function collect( app ) { - var apps = []; - - return ( function collect( app ) { - return app == end || fab.end - ? fab.body( apps ) - : apps.push( app ) && collect; - - })( app ); - } - - function end(){} -})(); \ No newline at end of file diff --git a/apps/fab.defaults.Function.js b/apps/fab.defaults.Function.js deleted file mode 100644 index c6c0e84..0000000 --- a/apps/fab.defaults.Function.js +++ /dev/null @@ -1,5 +0,0 @@ -exports.name = "fab.defaults.Function"; -exports.summary = "Returns the upstream app."; -exports.requires = []; - -exports.app = function( app ){ return app } \ No newline at end of file diff --git a/apps/fab.defaults.Number.js b/apps/fab.defaults.Number.js deleted file mode 100644 index 3e8a7fd..0000000 --- a/apps/fab.defaults.Number.js +++ /dev/null @@ -1,15 +0,0 @@ -exports.name = "fab.defaults.Number"; -exports.summary = "Calls fab.status for valid HTTP status codes, or fab.body otherwise."; -exports.requires = [ "fab.status", "fab.body" ]; - -var fab = { - status: require( "./fab.status" ).app, - body: require( "./fab.body" ).app -} - -exports.app = function( code ) { - var isHttpStatus = code < 506 && - code % 100 <= [ 0, 1, 6, 7, 17, 5 ][ code.toString()[0] ]; - - return fab[ isHttpStatus ? "status" : "body" ]( code ); -} \ No newline at end of file diff --git a/apps/fab.defaults.RegExp.js b/apps/fab.defaults.RegExp.js deleted file mode 100644 index 0bacf19..0000000 --- a/apps/fab.defaults.RegExp.js +++ /dev/null @@ -1,9 +0,0 @@ -exports.name = "fab.defaults.RegExp"; -exports.summary = "Uses fab.path for regular expressions."; -exports.requires = [ "fab.path" ]; - -var fab = { path: require( "./fab.path" ).app }; - -exports.app = function( pattern ) { - return fab.path.apply( this, arguments ); -} \ No newline at end of file diff --git a/apps/fab.defaults.js b/apps/fab.defaults.js deleted file mode 100644 index 4792401..0000000 --- a/apps/fab.defaults.js +++ /dev/null @@ -1,5 +0,0 @@ -exports.name = "fab.defaults"; -exports.summary = "Uses fab.body for unmatched object types."; -exports.requires = [ "fab.body" ]; - -exports.app = require( "./fab.body" ).app \ No newline at end of file diff --git a/apps/fab.echo.js b/apps/fab.echo.js deleted file mode 100644 index b4f208e..0000000 --- a/apps/fab.echo.js +++ /dev/null @@ -1,21 +0,0 @@ -exports.name = "fab.echo"; -exports.summary = "Pipes the inbound request stream back into the response."; -exports.requires = []; - -function echo() { - return this; -} - -exports.tests = ( function() { - function listener(){}; - - return [ - function - echoReturnsDownstreamListener() { - this( echo.call( listener ) == listener ) - } - ] - -})() - -exports.app = echo; \ No newline at end of file diff --git a/apps/fab.filter.js b/apps/fab.filter.js deleted file mode 100644 index 915d4b7..0000000 --- a/apps/fab.filter.js +++ /dev/null @@ -1,18 +0,0 @@ -exports.name = "fab.filter"; -exports.summary = "Sends only responses that satisfy the function."; -exports.requires = []; - -exports.app = function( fn ) { - return function( app ) { - return function() { - var out = this; - return app.call( function listener( obj ) { - if ( !obj || fn.call( obj, obj ) ) { - out = out.apply( this, arguments ); - } - - return listener; - }) - } - } -} \ No newline at end of file diff --git a/apps/fab.identity.js b/apps/fab.identity.js deleted file mode 100644 index 12a45d0..0000000 --- a/apps/fab.identity.js +++ /dev/null @@ -1,21 +0,0 @@ -exports.name = "fab.identity"; -exports.summary = "Returns the apstream app."; -exports.requires = []; - -function identity( app ) { - return app; -} - -exports.tests = ( function() { - function app(){}; - - return [ - function - identityReturnsUpstreamApp() { - this( identity( app ) == app ); - } - ] - -})() - -exports.app = identity; \ No newline at end of file diff --git a/apps/fab.js b/apps/fab.js deleted file mode 100644 index a5f867c..0000000 --- a/apps/fab.js +++ /dev/null @@ -1,41 +0,0 @@ -exports.name = "fab"; -exports.summary = "Glues apps of various arities together."; -exports.requires = [ "fab.defaults.*, fab.identity" ]; - -exports.app = function fab() { - var stack = []; - - return collect.apply( this, arguments ); - - function collect( fn ) { - var args = stack.slice.call( arguments ) - , length = args.length - , defaults = fab.defaults; - - if ( !length ) fn = fab.identity; - - if ( length > 1 ) fn = fab( fn ).apply( this, args.slice( 1 ) ); - - fn = ( fn && defaults[ fn.constructor.name ] || defaults )( fn ); - - stack.unshift( fn ); - - return reduce(); - } - - function reduce() { - if ( stack[ 0 ].length ) return collect; - - if ( stack.length == 1 ) return stack.shift(); - - if ( stack[ 1 ] == fab.identity ) { - var app = stack[ 0 ]; - stack.splice( 1, 1 ); - reduce(); - stack.unshift( app ); - } - - stack.splice( 0, 2, stack[ 1 ]( stack[ 0 ] ) ); - return reduce(); - } -} \ No newline at end of file diff --git a/apps/fab.map.body.js b/apps/fab.map.body.js deleted file mode 100644 index ef4cc79..0000000 --- a/apps/fab.map.body.js +++ /dev/null @@ -1,18 +0,0 @@ -exports.name = "fab.map.body"; -exports.summary = "Maps response bodies from the upstream app."; -exports.requires = []; - -exports.app = function( fn ) { - return function( app ) { - return function() { - var out = this; - return app.call( function listener( obj ) { - var body = obj && obj.body; - if ( body ) arguments[ 0 ].body = fn.call( body, body ); - out = out.apply( this, arguments ); - - return listener; - }) - } - } -} \ No newline at end of file diff --git a/apps/fab.map.js b/apps/fab.map.js deleted file mode 100644 index b18128d..0000000 --- a/apps/fab.map.js +++ /dev/null @@ -1,41 +0,0 @@ -exports.name = "fab.map"; -exports.summary = "Maps responses from the upstream app."; -exports.requires = []; - -map = exports.app = function( fn ) { - return function( app ) { - return function() { - var out = this; - return app.call( function listener( obj ) { - if ( obj ) arguments[ 0 ] = fn.call( obj, obj ); - out = out.apply( this, arguments ); - - return listener; - }) - } - } -} - -exports.tests = ( function() { - var fn = function( obj ) { return { body: JSON.stringify( obj ).length } } - , upstream = function(){ this({ body: { a: new Date } }) } - , binary = map( fn ) - , unary = binary( upstream ); - - return [ - - function - mapReturnsNaryApp() { - this( binary.length !== 0 ) - }, - - function - mapRespondsWithCorrectPayload() { - var out = this; - unary.call( function( obj ) { - out( obj.body === JSON.stringify({ body: { a: new Date }}).length ) } - ); - } - ]; - -})(); \ No newline at end of file diff --git a/apps/fab.method.DELETE.js b/apps/fab.method.DELETE.js deleted file mode 100644 index bd17421..0000000 --- a/apps/fab.method.DELETE.js +++ /dev/null @@ -1,7 +0,0 @@ -exports.name = "fab.method.DELETE"; -exports.summary = "Shortcut for fab.method( 'DELETE' )."; -exports.requires = [ "fab.method" ]; - -var fab = { method: require( "./fab.method" ).app }; - -exports.app = fab.method( "DELETE" ) \ No newline at end of file diff --git a/apps/fab.method.GET.js b/apps/fab.method.GET.js deleted file mode 100644 index a75fed0..0000000 --- a/apps/fab.method.GET.js +++ /dev/null @@ -1,7 +0,0 @@ -exports.name = "fab.method.GET"; -exports.summary = "Shortcut for fab.method( 'GET' )."; -exports.requires = [ "fab.method" ]; - -var fab = { method: require( "./fab.method" ).app }; - -exports.app = fab.method( "GET" ); \ No newline at end of file diff --git a/apps/fab.method.POST.js b/apps/fab.method.POST.js deleted file mode 100644 index bfe1267..0000000 --- a/apps/fab.method.POST.js +++ /dev/null @@ -1,7 +0,0 @@ -exports.name = "fab.method.POST"; -exports.summary = "Shortcut for fab.method( 'POST' )."; -exports.requires = [ "fab.method" ]; - -var fab = { method: require( "./fab.method" ).app }; - -exports.app = fab.method( "POST" ) \ No newline at end of file diff --git a/apps/fab.method.PUT.js b/apps/fab.method.PUT.js deleted file mode 100644 index d875813..0000000 --- a/apps/fab.method.PUT.js +++ /dev/null @@ -1,7 +0,0 @@ -exports.name = "fab.method.PUT"; -exports.summary = "Shortcut for fab.method( 'PUT' )."; -exports.requires = [ "fab.method" ]; - -var fab = { method: require( "./fab.method" ).app }; - -exports.app = fab.method( "PUT" ) \ No newline at end of file diff --git a/apps/fab.method.js b/apps/fab.method.js deleted file mode 100644 index 7e60725..0000000 --- a/apps/fab.method.js +++ /dev/null @@ -1,52 +0,0 @@ -exports.name = "fab.method"; -exports.summary = "Passes the request to the first app when the request method matches, and to the second app otherwise."; -exports.requires = []; - - -method = exports.app = function( names ) { - var methods = {} - , len = arguments.length; - - for ( var i = 0; i < len; i++ ) { - methods[ arguments[ i ] ] = true; - } - - return function( hit ) { - return function( miss ) { - return function() { - var out = this; - return function( head ) { - var app = head.method in methods ? hit : miss; - - app = app.call( out ); - if ( app ) app = app( head ); - - return app; - } - } - } - } -} - -exports.tests = ( function() { - var ok = function(){ this({ body: true }) } - , notok = function(){ this({ body: false }) } - , app = method( "GET" )( ok )( notok ); - - return [ - - function - methodMatchesGetCorrectly() { - var out = this; - app.call( function( obj ){ out( obj.body ) } )({ method: "GET" }); - }, - - function - methodMismatchesPostCorrectly() { - var out = this; - app.call( function( obj ){ out( !obj.body ) } )({ method: "POST" }); - } - - ]; - -})(); \ No newline at end of file diff --git a/apps/fab.nodejs.contentLength.js b/apps/fab.nodejs.contentLength.js deleted file mode 100644 index 8e6460a..0000000 --- a/apps/fab.nodejs.contentLength.js +++ /dev/null @@ -1,14 +0,0 @@ -exports.name = "fab.nodejs.contentLength"; -exports.summary = "Adds a Content-Length header based on the length of the response body."; -exports.requires = [ "fab.nodejs" ]; - -var fab = { map: require( "./fab.map" ).app }; - -exports.app = fab.map( function( obj ) { - if ( typeof obj.body == "string" ) { - ( obj.headers = obj.headers || {} ) - [ "content-length" ] = process._byteLength( obj.body ); - } - - return obj; -}) \ No newline at end of file diff --git a/apps/fab.nodejs.fs.js b/apps/fab.nodejs.fs.js deleted file mode 100644 index bbb8ca4..0000000 --- a/apps/fab.nodejs.fs.js +++ /dev/null @@ -1,34 +0,0 @@ -exports.name = "fab.nodejs.fs"; - -exports.summary = "Fetches a file from the file system based on the path in the upstream response." - -exports.details = "The path used to fetch the file is obtained from the response, as the pathname property of the url object first, or the body property otherwise."; - -exports.requires = [ "fab.nodejs" ]; - -exports.app = function( app ) { - var fs = require( "fs" ); - - return function() { - var out = this; - - return app.call( function listener( obj ) { - if (obj) { - var path = obj.url ? obj.url.pathname : obj.body - , body = "File not found: " + path || "No path given." - , notfound = { status: 404, body: body }; - - if ( !path ) { - out = out( err ); - if ( out ) out(); - } - - else fs.readFile( path, "utf8", function( err, data ) { - out = out( err ? notfound : { status: 200, body: data } ); - if ( out ) out(); - }); - } - return listener; - }) - } -} diff --git a/apps/fab.nodejs.http.js b/apps/fab.nodejs.http.js deleted file mode 100644 index 6735ac3..0000000 --- a/apps/fab.nodejs.http.js +++ /dev/null @@ -1,44 +0,0 @@ -exports.name = "fab.nodejs.http"; -exports.summary = "Proxies a request to a remote http server. The request information is provided entirely by the upstream app, either in the form of an object with method, headers, and url properties, or as a body property containing the url to proxy."; -exports.requires = [ "fab.nodejs" ]; - - - -exports.app = function( app ) { - var url = require( "url" ) - , http = require( "http" ); - - return function() { - var out = this; - - return app.call( function listener( obj ) { - - if (obj) { - var loc = obj.url || url.parse( obj.body ); - - http - .createClient( loc.port || 80, loc.hostname ) - .request( - obj.method || "GET", - loc.pathname + ( loc.search || "" ), - obj.headers || { host: loc.hostname } - ) - .addListener( "response", function( response ) { - out = out({ - status: response.statusCode, - headers: response.headers - }); - - response - .addListener( "data", function( chunk ) { - if ( out ) out = out({ body: chunk }); - }) - .addListener( "end", out ) - .setBodyEncoding( "utf8" ); - }) - .end(); - } - return listener; - }); - } -} diff --git a/apps/fab.nodejs.js b/apps/fab.nodejs.js deleted file mode 100644 index 449ccc7..0000000 --- a/apps/fab.nodejs.js +++ /dev/null @@ -1,71 +0,0 @@ -exports.name = "fab.nodejs"; -exports.summary = "Converts the upstream app into a node.js-compatible listener."; -exports.requires = []; - -exports.app = function( app ) { - var url = require( "url" ); - - return function() { - var - request = arguments[ 0 ], - response = arguments[ 1 ], - headers = undefined, - status = 200, - _encoding = "ascii", - inbound = app.call( listener ); - - if ( inbound ) { - inbound = inbound({ - method: request.method, - headers: request.headers, - url: url.parse( "//" + request.headers.host + request.url ) - }); - } - - if ( inbound ) { - request - .addListener( "end", inbound ) - .addListener( "data", function( body ) { - if ( inbound ) inbound = inbound({ body: body }); - }) - } - - function listener( obj ) { - if ( obj ) { - - if ( "status" in obj ) { - status = obj.status; - } - - if ( "headers" in obj ) { - if ( headers ) process.mixin( headers, obj.headers ); - else headers = obj.headers; - } - - if ( "_encoding" in obj ) { - _encoding = obj._encoding; - } - - if ( "body" in obj ) { - if ( headers !== false ) { - response.writeHead( status, headers || {} ); - headers = false; - } - - response.write( obj.body, _encoding ); - } - - return listener; - } - - else { - if ( headers !== false ) { - response.writeHead( status, headers || {} ); - headers = false; - } - - response.end(); - } - } - } -} \ No newline at end of file diff --git a/apps/fab.nodejs.listen.js b/apps/fab.nodejs.listen.js deleted file mode 100644 index c314c79..0000000 --- a/apps/fab.nodejs.listen.js +++ /dev/null @@ -1,17 +0,0 @@ -exports.name = "fab.nodejs.listen"; -exports.summary = "Starts a server listening on the port number from the first app, and mounts the second app on it."; -exports.requires = [ "fab.nodejs" ]; - -var fab = { nodejs: require( "./fab.nodejs" ).app }; - -exports.app = function( port ) { - port.call( function( obj ){ port = obj.body } ); - - return function( app ) { - require( "http" ) - .createServer( fab.nodejs( app ) ) - .listen( port ) - - return app; - } -} \ No newline at end of file diff --git a/apps/fab.parse.js b/apps/fab.parse.js deleted file mode 100644 index 3a285a5..0000000 --- a/apps/fab.parse.js +++ /dev/null @@ -1,12 +0,0 @@ -exports.name = "fab.parse"; -exports.summary = "Converts JSON responses into objects."; -exports.requires = []; - -var fab = { map: require( "./fab.map" ).app }; - - -exports.app = fab.map( function( obj ) { - var body = obj.body; - if ( typeof body == "string" ) obj.body = JSON.parse( body ); - return obj; -}) \ No newline at end of file diff --git a/apps/fab.path.js b/apps/fab.path.js deleted file mode 100644 index eb3816a..0000000 --- a/apps/fab.path.js +++ /dev/null @@ -1,49 +0,0 @@ -exports.name = "fab.path"; -exports.summary = "Passes the request to the first app if the path matches the pattern, or the second app otherwise. When the path is matched, the matching part of the existing path is truncated before the request is passed."; -exports.requires = []; - -exports.app = function( pattern ) { - var - proto = Array.prototype, - match = { - String: function( url ) { - if ( path.indexOf( pattern ) ) return false; - - url.pathname = url.pathname.substr( pattern.length ); - return true; - }, - - RegExp: function( url ) { - var matched = false; - - url.pathname = url.pathname.replace( pattern, function() { - matched = true; - - var capture = proto.slice.call( arguments, 1, -2 ); - - if ( !url.capture ) url.capture = capture; - else proto.push.apply( url.capture, capture ); - - return ""; - }); - - return matched; - } - }[ pattern.constructor.name ]; - - return function( hit ) { - return function( miss ) { - return function() { - var out = this; - return function( head ) { - var app = match( head.url ) ? hit : miss; - - app = app.call( out ); - if ( app ) app = app( head ); - - return app; - } - } - } - } -} \ No newline at end of file diff --git a/apps/fab.prepend.js b/apps/fab.prepend.js deleted file mode 100644 index 0f16de0..0000000 --- a/apps/fab.prepend.js +++ /dev/null @@ -1,14 +0,0 @@ -exports.name = "fab.prepend"; -exports.summary = "Prepends responses with the given string."; -exports.requires = [ "fab.map" ]; - -var fab = { map: require( "./fab.map" ).app }; - -exports.app = function( str ) { - str.call( function( obj ){ str = obj.body } ); - - return fab.map( function( obj ) { - obj.body = str + obj.body; - return obj; - }); -} \ No newline at end of file diff --git a/apps/fab.status.js b/apps/fab.status.js deleted file mode 100644 index 86ff2ef..0000000 --- a/apps/fab.status.js +++ /dev/null @@ -1,42 +0,0 @@ -exports.name = "fab.status"; -exports.summary = "Responds with with the given status code."; -exports.requires = []; - -function status( code ) { - code = +code; - return function() { - var out = this({ status: code }); - if ( out ) out(); - } -} - -exports.tests = ( function() { - var response = 200 - , app = status( response ) - , fn = function(){}; - - return [ - - function - statusReturnsUnaryApp() { - this( app.length === 0 ) - }, - - function - statusRespondsWithCorrectPayload() { - var out = this; - app.call( function( obj ){ out( obj.status === response ) } ); - }, - - function - statusClosesConnection() { - var out = this; - app.call( function() { - return function(){ out( !arguments.length ) } - }) - } - ]; - -})(); - -exports.app = status; \ No newline at end of file diff --git a/apps/fab.stringify.js b/apps/fab.stringify.js deleted file mode 100644 index 9ecfce8..0000000 --- a/apps/fab.stringify.js +++ /dev/null @@ -1,11 +0,0 @@ -var fab = { map: require( "./fab.map" ).app }; - -exports.name = "fab.stringify"; -exports.summary = "Converts non-string responses into JSON."; -exports.requires = [ "fab.map" ]; - -exports.app = fab.map( function( obj ) { - var body = obj.body; - if ( typeof body != "string" ) obj.body = JSON.stringify( body ); - return obj; -}) \ No newline at end of file diff --git a/apps/fab.tap.js b/apps/fab.tap.js deleted file mode 100644 index 2d837e9..0000000 --- a/apps/fab.tap.js +++ /dev/null @@ -1,12 +0,0 @@ -exports.name = "fab.tap"; -exports.summary = "Executes the given function when called, and then connects the downstream and upstream apps."; -exports.requires = []; - -exports.app = function( fn ) { - return function( app ) { - return function() { - fn(); - return app.call( this ); - } - } -} \ No newline at end of file diff --git a/apps/fab.tmpl.js b/apps/fab.tmpl.js deleted file mode 100644 index 5729706..0000000 --- a/apps/fab.tmpl.js +++ /dev/null @@ -1,34 +0,0 @@ -exports.name = "fab.tmpl"; -exports.summary = "Compiles the string response of the first app into a template function that maps subsequent responses from the second app."; -exports.requires = [ "fab.map" ]; - -var fab = { map: require( "./fab.map" ).app }; - - -exports.app = function( source ) { - var fn; - - source.call( function( obj ) { - fn = new Function( - "var p=[];p.push('" + - obj.body - .replace( /[\r\t\n]/g, " " ) - .replace( /'(?=[^%]*%>)/g, "\t" ) - .split( "'" ).join( "\\'" ) - .split( "\t" ).join( "'" ) - .replace( /<%=(.+?)%>/g, "',$1,'" ) - .split( "<%" ).join( "');" ) - .split( "%>" ).join( "p.push('" ) - + "');return p.join('');" ); - }); - - return function( app ) { - // TODO: fn might not be defined yet for async - app = fab.map( function( obj ) { - obj.body = fn.call( obj.body ); - return obj; - })( app ); - - return function() { return app.call( this ) }; - } -} \ No newline at end of file diff --git a/builds/all.js b/builds/all.js deleted file mode 100644 index a70b7f6..0000000 --- a/builds/all.js +++ /dev/null @@ -1,8 +0,0 @@ -var dir = require( "path" ).join( __dirname, "../apps") - , apps = exports.apps = require( "fs" ) - .readdirSync( dir ) - .filter( function( name ){ return name.substr( -3 ) == ".js" } ) - .map( function( name ){ return name.replace( /\.js$/, "" ) } ) - .sort(); - -exports.app = require( "../utils/build" )( apps ).app; \ No newline at end of file diff --git a/builds/core.js b/builds/core.js deleted file mode 100644 index 8d27ff1..0000000 --- a/builds/core.js +++ /dev/null @@ -1,12 +0,0 @@ -var apps = exports.apps = [ - "fab" - , "fab.body" - , "fab.Function" - , "fab.identity" - , "fab.Number" - , "fab.path" - , "fab.RegExp" - , "fab.status" -]; - -exports.app = require( "../utils/build" )( apps ).app; \ No newline at end of file diff --git a/examples/date.js b/examples/date.js deleted file mode 100644 index 731f33d..0000000 --- a/examples/date.js +++ /dev/null @@ -1,16 +0,0 @@ -with ( fab = require( "../" ) ) module.exports = fab - - ( contentLength ) - ( stringify ) - - ( /\/date/ ) - ( tmpl ) - ( "The date is <%= this.toDateString() %>." ) - () - - ( /\/time/ ) - ( tmpl ) - ( "The time is <%= this.toTimeString() %>." ) - () - - ( new Date ); \ No newline at end of file diff --git a/examples/focus.js b/examples/focus.js deleted file mode 100644 index 106bcc6..0000000 --- a/examples/focus.js +++ /dev/null @@ -1,66 +0,0 @@ -var - fab = require( "../" ), - listeners = []; - -module.exports = fab - - ( /\/listen/ ) - ( function(){ listeners.push( this ) } ) - - ( /\/init/ ) - ( fab.tmpl, "(<%= this %>)()" ) - ( client.toString() ) - - ( /\/focused/ ) - ( broadcast, listeners ) - ( fab.tmpl, "$('body').html('<%= this %>');" ) - ( userAgent ) - - ( fab.tmpl, "<%= this %>" ) - - ( - "" + - "" - ); - -function broadcast( listeners ) { - listeners.call( function( obj ){ listeners = obj.body } ); - - return function( app ) { - return function() { - this(); - - return app.call( function fn( obj ) { - var i = listeners.length; - - while ( i-- ) { - ( obj ? listeners[ i ] : listeners.pop() ) - .apply( this, arguments ); - } - - return fn; - }) - } - } -} - -function userAgent() { - var out = this; - return function( head ) { - var ua = head.headers[ "user-agent" ]; - - out({ body: - ~ua.indexOf( "Firefox" ) ? "Firefox" : - ~ua.indexOf( "Chrome" ) ? "Chrome" : - ~ua.indexOf( "Safari" ) ? "Safari" : - "Other" - })(); - } -} - -function client() { - ( function listen(){ $.getScript( "/focus/listen", listen ) })(); - $( window ) - .focus( function(){ $.getScript( "/focus/focused" ) } ) - .focus(); -} diff --git a/examples/hello.js b/examples/hello.js deleted file mode 100644 index d592b46..0000000 --- a/examples/hello.js +++ /dev/null @@ -1,78 +0,0 @@ -fab = require( "../" ); - -module.exports = fab - - ( /\// ) - - ( /1/ ) // simple - ( function() { - this({ body: "Hello, world!" })(); - }) - - ( /2/ ) // streaming - ( function() { - this - ({ body: "Hello, " }) - ({ body: "world!" }) - (); - }) - - ( /3/ ) // complete, jsgi-style - ( function() { - this({ - status: 200, - headers: { "content-type": "text/plain" }, - body: "Hello, world!" - })(); - }) - - ( /4/ ) // asynchronous - ( function() { - var - out = this, - res = "Hello, world!".split(""), - interval = setInterval( function() { - out = out({ body: res.shift() }); - - if ( !res.length ) { - if ( out ) out(); - clearInterval( interval ); - } - }, 500 ); - }) - - ( /5/ ) // request-specific - ( function() { - var out = this; - - return function( head ) { - var body = "Hello, " + head.url.pathname.substr(1) + "!"; - out({ body: body })(); - } - }) - - ( /6/ ) // incoming body listener - ( function() { - var out = this, length = 0; - - return function listener( obj ) { - if ( !obj ) out({ body: "Hello, " + length + " bytes!" })(); - - else if ( obj.body ) { - length += process._byteLength( obj.body.toString() ); - } - - return listener; - } - }) - - ( /7/ ) // fab-style - ( fab.tmpl, "Hello, <%= this[ 0 ] %>!" ) - - ( /^\/(\w+)$/ ) - ( fab.capture ) - ( [ "world" ] ) - - ( 404 ) - - ( 404 ); \ No newline at end of file diff --git a/examples/index.js b/examples/index.js deleted file mode 100644 index a6f31b0..0000000 --- a/examples/index.js +++ /dev/null @@ -1,13 +0,0 @@ -var hello = require( "./hello" ) - , focus = require( "./focus" ) - , date = require( "./date" ); - -with ( require( "../" ) ) fab - - ( listen, 0xFAB ) - - ( /^\/hello/, hello ) - ( /^\/focus/, focus ) - ( /^\/date/, date ) - - ( 404 ); \ No newline at end of file diff --git a/index.js b/index.js deleted file mode 100644 index 659993a..0000000 --- a/index.js +++ /dev/null @@ -1,14 +0,0 @@ -var name - , app - , fab - = module.exports - = require( "./builds/all" ).app; - -for ( name in fab ) { - app = fab[ name ]; - - for ( name in app ) - { fab[ name ] = fab[ name ] || app[ name ] }; -} - -fab.fab = fab; \ No newline at end of file diff --git a/package.json b/package.json deleted file mode 100644 index aa288b9..0000000 --- a/package.json +++ /dev/null @@ -1,16 +0,0 @@ -{ "name" : "fab" -, "description" : "A modular async web framework for node.js" -, "version" : "0.4.0" -, "author" : "Jed Schmidt " -, "repository" : - { "type" : "git" - , "url" : "http://github.com/jed/fab.git" - } -, "main" : "./index" -, "engines": [ "node" ] -, "licenses" : - [ { "type" : "MIT" - , "url" : "http://github.com/jed/fab/blob/master/LICENSE.txt" - } - ] -} \ No newline at end of file diff --git a/utils/build.js b/utils/build.js deleted file mode 100644 index 032bf66..0000000 --- a/utils/build.js +++ /dev/null @@ -1,23 +0,0 @@ -module.exports = function( apps ) { - var tests = [] - , ret = {} - , dir = require( "path" ).join( __dirname, "../apps/"); - - apps.forEach( function( name ) { - var name - , parent = ret - , parts = name.split( "." ) - , app = require( dir + name ); - - while ( parts.length > 1 ) - { parent = parent[ parts.shift() ] } - - parent[ parts.shift() ] = app.app; - tests.push.apply( tests, app.tests || [] ); - }); - - ret.tests = tests; - ret.app = ret.fab; - - return ret; -} \ No newline at end of file diff --git a/utils/test.js b/utils/test.js deleted file mode 100644 index f181297..0000000 --- a/utils/test.js +++ /dev/null @@ -1,27 +0,0 @@ -var puts = require( "sys" ).puts; - -module.exports = function( build ) { - var tests = build.tests - , count = tests.length - , results = [ 0, 0 ]; - - puts( "Running " + count + " tests..." ) - - build.tests.forEach( function( test ) { - test.call( function( ok ) { - results[ +ok ]++ - puts( test.name + ": " + ok ); - - if ( results[ 0 ] + results[ 1 ] == count ) { - puts( - [ "Done. " - , results[ 1 ] - , " passed, " - , results[ 0 ] - , " failed." - ].join("") - ) - } - }); - }) -} \ No newline at end of file