Browse files

Sorry I've been gone so long guys

  • Loading branch information...
1 parent 42cd618 commit 867899adc374d5b4750f7c975b0f61802e83a3ef @partheseas committed Oct 7, 2012
View
16 Library/cli.js
@@ -1,16 +0,0 @@
-#!/usr/bin/env node
-
-var data, path, trailer;
-
-path = require( "path" )
-trailer = require( "trailer" )
-
-data = {
- // configuration: parseTrailerConfiguration( where ever )
-}
-
-data.configuration ? trailer.hitch( data.configuration ) : console.error( "No configuration file. :c" )
-
-
-
-
View
68 node_modules/errors/errors.js
@@ -0,0 +1,68 @@
+var errors, sandbox,
+events = require( "events" );
+
+module.exports = exports = errors = {
+ Sandbox: function ( name ) {
+ this.name = name
+ },
+
+ createSandbox: function () {
+ return new errors.Sandbox();
+ }
+}
+
+sandbox = errors.Sandbox.prototype = new events.EventEmitter();
+
+sandbox.addType = function ( name, level ) {
+ this[ name ] = function ( title, description, point ) {
+ var
+ out = level ? process.stderr : process.stdout,
+ broken = level > this.tolerance;
+
+ out.write( "\033[1m" + ( broken ? "\033[31m" : "\033[32m" ) + this.name + "\033[39m\033[22m " )
+
+ if ( arguments.length === 1 ) {
+ description = title
+ title = null
+ }
+
+ out.write( "\033[" + this.colors[ Math.min( 4, level ) ] + "m" +
+ name + "\033[39m " )
+
+ title && out.write( "\033[4m\033[37m" + title + "\033[39m\033[24m\n" )
+ out.write( description + "\n" )
+ point && out.write( "\n" + this.trace( point ) + "\n" )
+
+ out.write( "\n" )
+ broken && process.exit( 1 )
+ }
+
+ return this
+}
+
+sandbox.addType( "log", 0 )
+ .addType( "warning", 1 )
+ .addType( "error", 2 )
+ .addType( "critical", 4 )
+
+sandbox.trace = function ( point ) {
+ var space,
+ index = point.indexOf( "/>" ),
+ trace = " " + point.replace( "/>", "" ) + "\n";
+
+ for ( space = 0; space < index; space++ )
+ trace += " "
+
+ trace = trace.replace( /\n/g, "\n " ) + "^"
+
+ return trace
+}
+
+sandbox.colors = [
+ "36", "33", "35", "34", "31" ]
+
+sandbox.tolerance = 2
+
+
+
+
View
11 node_modules/errors/package.json
@@ -0,0 +1,11 @@
+{
+ "author": "Tyler Washburn (http://tyler.lt/)",
+ "name": "errors",
+ "description": "Error reporting",
+ "version": "1.0.0",
+ "keywords": [ "errors" ],
+ "main": "errors.js",
+ "engines": {
+ "node": ">=0.8"
+ }
+}
View
0 Library/node_modules/markdown/markdown.js → node_modules/markdown/markdown.js
File renamed without changes.
View
0 Library/node_modules/markdown/package.json → node_modules/markdown/package.json
File renamed without changes.
View
12 package.json
@@ -1,5 +1,5 @@
{
- "author": "Tyler Washburn (http://tylermwashburn.net/)",
+ "author": "Tyler Washburn (http://tyler.lt/)",
"name": "trailer",
"description": "An HTTP server written for Node.",
"version": "0.7.3",
@@ -9,15 +9,11 @@
"type": "git",
"url": "git://github.com/tylermwashburn/trailer.git"
},
- "main": "Library/trailer.js",
- "bin": {
- "trailer": "Library/cli.js"
- },
+ "main": "trailer.js",
"engines": {
- "node": "0.6 || 0.8"
+ "node": ">=0.8"
},
"dependencies": {
"markdown": "0.3.1"
- },
- "devDependencies": {}
+ }
}
View
28 Library/trailer.js → trailer.js
@@ -2,11 +2,12 @@
"use strict"
-var basics, configurations, data, events, fs, http, markdown, path, qs, server, trailer, url, rid, zlib;
-
Function.prototype.is = function ( item ) { return item != null && ( item.constructor === this.prototype.constructor ) }
+var basics, configurations, data, server, trailer, rid,
+
events = require( "events" ),
+errors = require( "errors" ),
fs = require( "fs" ),
http = require( "http" ),
path = require( "path" ),
@@ -15,14 +16,9 @@ url = require( "url" ),
markdown = require( "markdown" ),
zlib = require( "zlib" );
-// fs.exists compatibility
-if ( !fs.exists ) {
- fs.exists = path.exists
-}
-
// This isn't one of our event emitters,
// because then it would emit to itself in an infinite loop.
-global.trailer = trailer = module.exports = new events.EventEmitter()
+global.trailer = trailer = module.exports = new errors.Sandbox( "trailer" )
trailer.version = "0.7.3-"
// We put the http module here so that it can be extended.
@@ -109,16 +105,12 @@ trailer.MimeDictionary.prototype.fromApacheFile = function ( path, encoding ) {
} )
}
-trailer.hitch = function ( root, conf ) {
+trailer.hitch = function ( conf ) {
var prop, indexes;
- !conf&&( conf = {} )
-
- if ( String.is( root ) ) {
- conf.root = root
- } else {
- conf = root
- root = conf.root
+ if ( !conf ) {
+ trailer.warning( "hitch", "No configuration given!" )
+ return false
}
// After the given arguments have been assorted, emit that Trailer has received a configuration.
@@ -472,16 +464,16 @@ trailer.GET.preprocessors.push(
try {
return i.conf.api[ i.up ]( i, o, i.extra )
} catch ( error ) {
- console.log( "API " + i.up + " failed for " + i.url )
o.error( 500 )
+ trailer.error( i.up, i.up + " failed for " + i.url.pathname )
return true
}
} else if ( i.conf.api[ i.extra ] ) {
try {
return i.conf.api[ i.extra ]( i, o, i.up )
} catch ( error ) {
- console.log( "API " + i.extra + " failed for " + i.url )
o.error( 500 )
+ trailer.error( i.extra, i.extra + " failed for " + i.url.pathname )
return true
}
}

0 comments on commit 867899a

Please sign in to comment.