little css

This commit is contained in:
2013-02-14 08:18:17 -05:00
parent e96147b7ff
commit b603f2404c
73 changed files with 6191 additions and 24 deletions

139
node_modules/gzippo/lib/compress.js generated vendored Normal file
View File

@@ -0,0 +1,139 @@
/*!
* Connect - compress
* Copyright(c) 2010 Sencha Inc.
* Copyright(c) 2011 TJ Holowaychuk
* MIT Licensed
*/
/**
* Module dependencies.
*/
var zlib = require('zlib');
/**
* Supported content-encoding methods.
*/
exports.methods = {
gzip: zlib.createGzip,
deflate: zlib.createDeflate
};
/**
* Default filter function.
*/
exports.filter = function(req, res){
var type = res.getHeader('Content-Type') || '';
return type.match(/json|text|javascript/);
};
/**
* Compress response data with gzip/deflate.
*
* Filter:
*
* A `filter` callback function may be passed to
* replace the default logic of:
*
* exports.filter = function(req, res){
* var type = res.getHeader('Content-Type') || '';
* return type.match(/json|text|javascript/);
* };
*
* Options:
*
* All remaining options are passed to the gzip/deflate
* creation functions. Consult node's docs for additional details.
*
* - `chunkSize` (default: 16*1024)
* - `windowBits`
* - `level`: 0-9 where 0 is no compression, and 9 is slow but best compression
* - `memLevel`: 1-9 low is slower but uses less memory, high is fast but uses more
* - `strategy`: compression strategy
*
* @param {Object} options
* @return {Function}
* @api public
*/
module.exports = function compress(options) {
var options = options || {}
, names = Object.keys(exports.methods)
, filter = options.filter || exports.filter;
return function(req, res, next){
var accept = req.headers['accept-encoding']
, write = res.write
, end = res.end
, stream
, method;
// vary
res.setHeader('Vary', 'Accept-Encoding');
// proxy
res.write = function(chunk, encoding){
if (!this.headerSent) this._implicitHeader();
return stream
? stream.write(chunk, encoding)
: write.call(res, chunk, encoding);
};
res.end = function(chunk, encoding){
if (chunk) this.write(chunk, encoding);
return stream
? stream.end()
: end.call(res);
};
res.on('header', function(){
// default request filter
if (!filter(req, res)) return;
// SHOULD use identity
if (!accept) return;
// head
if ('HEAD' == req.method) return;
// default to gzip
if ('*' == accept.trim()) method = 'gzip';
// compression method
if (!method) {
for (var i = 0, len = names.length; i < len; ++i) {
if (~accept.indexOf(names[i])) {
method = names[i];
break;
}
}
}
// compression method
if (!method) return;
// compression stream
stream = exports.methods[method](options);
// header fields
res.setHeader('Content-Encoding', method);
res.removeHeader('Content-Length');
// compression
stream.on('data', function(chunk){
write.call(res, chunk);
});
stream.on('end', function(){
end.call(res);
});
});
next();
};
}

61
node_modules/gzippo/lib/fileAsset.js generated vendored Normal file
View File

@@ -0,0 +1,61 @@
var FileAsset = module.exports = function FileAsset(name, options) {
options = options || {};
this._maxAge = options.maxAge || 86400000;
this._mtime = options.mtime || new Date();
this._fileName = name;
this._ctime = +Date.now();
this.fileContents = [];
this.fileContentsLength = 0;
};
/**
* Prototype.
*/
FileAsset.prototype = {
set maxAge(maxAge) {
this._maxAge = maxAge;
},
get maxAge() {
return this._maxAge;
},
get mtime() {
return this._mtime;
},
get isExpired() {
return (this._ctime + this._maxAge) < +Date.now();
},
get name() {
return this._fileName;
},
get content() {
// var file = Buffer(this.fileContentsLength);
// var pos = 0;
// for (var i = 0; i < this.fileContents.length; i++) {
// // this.fileContents[i] = this.fileContents[i].toString();
// // buffer.copy(file, pos);
// // pos += buffer.length;
// }
return this.fileContents;
},
get length() {
return this.fileContentsLength;
},
get data() {
return {
expires: this._expires,
mtime: this._mtime,
content: this.content,
length: this.fileContentsLength
};
}
};

103
node_modules/gzippo/lib/memory.js generated vendored Normal file
View File

@@ -0,0 +1,103 @@
/*!
* gzippo - MemoryStore
*
* MIT Licensed
*/
var Store = require('./store'),
util = require('util');
/**
* new `MemoryStore`.
*
* @api public
*/
var MemoryStore = module.exports = function MemoryStore() {
Store.call(this);
this.assets = {};
};
util.inherits(MemoryStore, Store);
/**
* Attempt to fetch an asset by its filename - `file`.
*
* @param {String} fileName
* @param {Function} cb
* @api public
*/
MemoryStore.prototype.get = function(fileName, cb) {
var that = this;
process.nextTick(function(){
var expires,
asset = that.assets[fileName];
if (asset) {
// expires = (typeof asset.expires === 'string') ?
// +Date.parse(asset.expires) :
// asset.expires;
// if (!expires || +Date.now() < expires) {
cb(null, asset);
// } else {
// that.purgeFile(file, cb);
// }
} else {
cb();
}
});
};
/**
*
* @param {FileAsset} asset
* @param {Function} cb
* @api public
*/
MemoryStore.prototype.set = function(asset, cb) {
var that = this;
process.nextTick(function() {
that.assets[asset.name] = asset.data;
if(cb instanceof Function) cb();
});
};
/**
* purge the cache
*
* @param {Function} cb
* @api public
*/
MemoryStore.prototype.purge = function(cb){
this.assets = {};
if(cb instanceof Function) cb();
};
/**
* purge the an item from thecache
*
* @param {FileAsset} asset
* @param {Function} cb
* @api public
*/
MemoryStore.prototype.purgeFile = function(asset, cb){
process.nextTick(function() {
delete this.assets[asset.name];
if(cb instanceof Function) cb();
});
};
/**
* Fetch number of cached files.
*
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.length = function(cb){
cb(null, Object.keys(this.assets).length);
};

289
node_modules/gzippo/lib/staticGzip.js generated vendored Normal file
View File

@@ -0,0 +1,289 @@
/*!
* Tom Gallacher
*
* MIT Licensed
*/
/**
* Module dependencies.
*/
// Commented out as I think that connect is avalible from within express...
// try {
// var staticMiddleware = require('connect').static;
// } catch (e) {
// staticMiddleware = require('express').static;
// }
var fs = require('fs'),
parse = require('url').parse,
path = require('path'),
zlib = require('zlib'),
MemoryStore = require('./memory'),
StoreStream = require('./storeStream'),
FileAsset = require('./fileAsset'),
send = require('send'),
mime = send.mime
;
/**
* Strip `Content-*` headers from `res`.
*
* @param {ServerResponse} res
* @api public
*/
var removeContentHeaders = function(res){
Object.keys(res._headers).forEach(function(field){
if (0 === field.indexOf('content')) {
res.removeHeader(field);
}
});
};
/**
* Supported content-encoding methods.
*/
var methods = {
gzip: zlib.createGzip,
deflate: zlib.createDeflate
};
/**
* Default filter function.
*/
exports.filter = function(req, res){
var type = res.getHeader('Content-Type') || '';
return type.match(/json|text|javascript/);
};
/**
* Parse the `req` url with memoization.
*
* @param {ServerRequest} req
* @return {Object}
* @api private
*/
var parseUrl = function(req){
var parsed = req._parsedUrl;
if (parsed && parsed.href == req.url) {
return parsed;
} else {
return req._parsedUrl = parse(req.url);
}
};
/**
* By default gzip's static's that match the given regular expression /text|javascript|json/
* and then serves them with Connects static provider, denoted by the given `dirPath`.
*
* Options:
*
* - `maxAge` how long gzippo should cache gziped assets, defaulting to 1 day
* - `clientMaxAge` client cache-control max-age directive, defaulting to 0; 604800000 is one week.
* - `contentTypeMatch` - A regular expression tested against the Content-Type header to determine whether the response
* should be gzipped or not. The default value is `/text|javascript|json/`.
* - `prefix` - A url prefix. If you want all your static content in a root path such as /resource/. Any url paths not matching will be ignored
*
* Examples:
*
* connect.createServer(
* connect.staticGzip(__dirname + '/public/');
* );
*
* connect.createServer(
* connect.staticGzip(__dirname + '/public/', {maxAge: 86400000});
* );
*
* @param {String} path
* @param {Object} options
* @return {Function}
* @api public
*/
exports = module.exports = function staticGzip(dirPath, options){
options = options || {};
var maxAge = options.maxAge || 86400000,
contentTypeMatch = options.contentTypeMatch || /text|javascript|json/,
clientMaxAge = options.clientMaxAge || 604800000,
prefix = options.prefix || '',
names = Object.keys(methods),
compressionOptions = options.compression || {},
store = options.store || new MemoryStore();
if (!dirPath) throw new Error('You need to provide the directory to your static content.');
if (!contentTypeMatch.test) throw new Error('contentTypeMatch: must be a regular expression.');
dirPath = path.normalize(dirPath);
return function(req, res, next) {
var acceptEncoding = req.headers['accept-encoding'] || '',
url,
filename,
contentType,
charset,
method;
function pass(name) {
send(req, url.substring(prefix.length))
.maxage(clientMaxAge || 0)
.root(dirPath)
.pipe(res)
;
}
function setHeaders(stat, asset) {
res.setHeader('Content-Type', contentType);
res.setHeader('Content-Encoding', method);
res.setHeader('Vary', 'Accept-Encoding');
// if cache version is avalible then add this.
if (asset) {
// res.setHeader('Content-Length', asset.length);
res.setHeader('ETag', '"' + asset.length + '-' + Number(asset.mtime) + '"');
res.setHeader('Last-Modified', asset.mtime.toUTCString());
}
res.setHeader('Date', new Date().toUTCString());
res.setHeader('Expires', new Date(Date.now() + clientMaxAge).toUTCString());
res.setHeader('Cache-Control', 'public, max-age=' + (clientMaxAge / 1000));
}
// function gzipAndSend(filename, gzipName, mtime) {
// gzippo(filename, charset, function(gzippedData) {
// gzippoCache[gzipName] = {
// 'ctime': Date.now(),
// 'mtime': mtime,
// 'content': gzippedData
// };
// sendGzipped(gzippoCache[gzipName]);
// });
// }
function forbidden(res) {
var body = 'Forbidden';
res.setHeader('Content-Type', 'text/plain');
res.setHeader('Content-Length', body.length);
res.statusCode = 403;
res.end(body);
}
if (req.method !== 'GET' && req.method !== 'HEAD') {
return next();
}
url = decodeURI(parseUrl(req).pathname);
// Allow a url path prefix
if (url.substring(0, prefix.length) !== prefix) {
return next();
}
filename = path.normalize(path.join(dirPath, url.substring(prefix.length)));
// malicious path
if (0 != filename.indexOf(dirPath)){
return forbidden(res);
}
// directory index file support
if (filename.substr(-1) === '/') filename += 'index.html';
contentType = mime.lookup(filename);
charset = mime.charsets.lookup(contentType, 'UTF-8');
contentType = contentType + (charset ? '; charset=' + charset : '');
// default to gzip
if ('*' == acceptEncoding.trim()) method = 'gzip';
// compression method
if (!method) {
for (var i = 0, len = names.length; i < len; ++i) {
if (~acceptEncoding.indexOf(names[i])) {
method = names[i];
break;
}
}
}
if (!method) return pass(filename);
fs.stat(filename, function(err, stat) {
if (err) {
return next();
}
if (stat.isDirectory()) {
return next();
}
if (!contentTypeMatch.test(contentType)) {
return pass(filename);
}
// superceeded by if (!method) return;
// if (!~acceptEncoding.indexOf('gzip')) {
// return pass(filename);
// }
var base = path.basename(filename),
dir = path.dirname(filename),
gzipName = path.join(dir, base + '.gz');
var sendGzipped = function(filename) {
var stream = fs.createReadStream(filename);
req.on('close', stream.destroy.bind(stream));
var storeStream = new StoreStream(store, filename, {
mtime: stat.mtime,
maxAge: options.maxAge
});
var compressionStream = methods[method](options.compression);
stream.pipe(compressionStream).pipe(storeStream).pipe(res);
stream.on('error', function(err){
if (res.headerSent) {
console.error(err.stack);
req.destroy();
} else {
next(err);
}
});
};
store.get(decodeURI(filename), function(err, asset) {
setHeaders(stat, asset);
if (err) {
// handle error
} else if (!asset) {
sendGzipped(decodeURI(filename));
} else if ((asset.mtime < stat.mtime) || asset.isExpired) {
sendGzipped(decodeURI(filename));
}
else if (req.headers['if-modified-since'] && asset &&
// Optimisation: new Date().getTime is 90% faster that Date.parse()
+stat.mtime <= new Date(req.headers['if-modified-since']).getTime()) {
removeContentHeaders(res);
res.statusCode = 304;
return res.end();
}
else {
// StoreReadStream to pipe to res.
// console.log("hit: " + filename + " length: " + asset.length);
for (var i = 0; i < asset.content.length; i++) {
res.write(asset.content[i], 'binary');
}
res.end();
}
});
});
};
};

11
node_modules/gzippo/lib/store.js generated vendored Normal file
View File

@@ -0,0 +1,11 @@
var util = require('util');
/*
* gzippo - store
* Copyright(c) 2012 Tom Gallacher
* MIT Licensed
*/
var Store = module.exports = function Store(options) {
if (!(this instanceof Store)) return new Store(options);
};

119
node_modules/gzippo/lib/storeStream.js generated vendored Normal file
View File

@@ -0,0 +1,119 @@
var util = require('util'),
stream = require('stream'),
FileAsset = require('./fileAsset');
/*
* gzippo - StoreStream
* Copyright(c) 2012 Tom Gallacher
* MIT Licensed
*/
var StoreStream = module.exports = function StoreStream(store, fileName, options) {
if (!(this instanceof StoreStream)) return new StoreStream(store, options);
options = options || {};
this._queue = [];
this._processing = false;
this._ended = false;
this.readable = true;
this.writable = true;
this._asset = new FileAsset(fileName, options);
this._store = store;
};
util.inherits(StoreStream, stream.Stream);
StoreStream.prototype.write = function write(chunk, cb) {
if (this._ended) {
return this.emit('error', new Error('Cannot write after end'));
}
if (arguments.length === 1 && typeof chunk === 'function') {
cb = chunk;
chunk = null;
}
if (!chunk) {
chunk = null;
} else if (typeof chunk === 'string') {
chunk = new Buffer(chunk);
} else if (!Buffer.isBuffer(chunk)) {
return this.emit('error', new Error('Invalid argument'));
}
var empty = this._queue.length === 0;
this._queue.push([chunk, cb]);
this._process();
if (!empty) {
this._needDrain = true;
}
return empty;
};
StoreStream.prototype.flush = function flush(cb) {
return this.write(cb);
};
StoreStream.prototype.end = function end(chunk, cb) {
var self = this;
this._ending = true;
var ret = this.write(chunk, function() {
self.emit('end');
process.nextTick(function() {
self._store.set(self._asset);
});
if (cb) cb();
});
this._ended = true;
return ret;
};
StoreStream.prototype._process = function() {
var self = this;
if (this._processing || this._paused) return;
if (this._queue.length === 0) {
if (this._needDrain) {
this._needDrain = false;
this.emit('drain');
}
// nothing to do, waiting for more data at this point.
return;
}
var req = this._queue.shift();
var cb = req.pop();
var chunk = req.pop();
if (this._ending && this._queue.length === 0) {
this._flush = true;
}
if (chunk !== null) {
self.emit('data', chunk);
this._asset.fileContents.push(chunk);
}
// finished with the chunk.
self._processing = false;
if (cb) cb();
self._process();
};
StoreStream.prototype.destory = function() {
this._paused = true;
StoreStream.prototype.end.call(this);
};
StoreStream.prototype.pause = function() {
this._paused = true;
this.emit('pause');
};
StoreStream.prototype.resume = function() {
this._paused = false;
this._process();
};