Permalink
Browse files

Convention shift

  • Loading branch information...
1 parent 307b36a commit f5a4d6917d961c2f89e20001f229dfb32e567a1c @serby committed May 30, 2012
View
@@ -1,13 +1,13 @@
-var
- version = '0.1',
- connect = require('connect'),
- versionator = require('../../');
+var version = '0.1'
+ , connect = require('connect')
+ , versionator = require('../../')
+ ;
connect(
- versionator.createBasic('v' + version).middleware,
- connect.static(__dirname + '/public', { maxAge: 2592000000 }),
- function(req, res) {
- res.setHeader('Content-Type', 'text/html');
- res.end('<script src="/js/v' + version + '/example.js"></script>');
- }
+ versionator.createBasic('v' + version).middleware,
+ connect.static(__dirname + '/public', { maxAge: 2592000000 }),
+ function(req, res) {
+ res.setHeader('Content-Type', 'text/html');
+ res.end('<script src="/js/v' + version + '/example.js"></script>');
+ }
).listen(3000);
@@ -33,18 +33,18 @@ versionator.createMapFromPath(__dirname + '/public', function(error, staticFileM
.use(express.bodyParser())
.use(express.methodOverride())
.use(mappedVersion.middleware)
- .use(stylus.middleware({
+ .use(stylus.middleware({
src: __dirname + '/public/',
compile: stylusCompile }))
.use(app.router)
.use(express.static(__dirname + '/public', { maxAge: 2592000000 }));
});
-
+
app.configure('development', function(){
- app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
// Routes
View
@@ -1,8 +1,8 @@
-var
- express = require('express'),
- stylus = require('stylus'),
- versionator = require('../../'),
- app = module.exports = express.createServer();
+var express = require('express')
+ , stylus = require('stylus')
+ , versionator = require('../../')
+ , app = module.exports = express.createServer()
+ ;
app.version = '0.1';
@@ -32,15 +32,15 @@ app.configure(function(){
.use(express.bodyParser())
.use(express.methodOverride())
.use(basic.middleware)
- .use(stylus.middleware({
+ .use(stylus.middleware({
src: __dirname + '/public/',
compile: stylusCompile }))
.use(app.router)
.use(express.static(__dirname + '/public', { maxAge: 2592000000 }));
});
app.configure('development', function(){
- app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
+ app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
// Routes
View
@@ -1,14 +1,14 @@
-var
- url = require('url'),
- async = require('async'),
- crypto = require('crypto'),
- fs = require('fs'),
- path = require('path'),
- _ = require('underscore'),
- walker = require('walker');
+var url = require('url')
+ , async = require('async')
+ , crypto = require('crypto')
+ , fs = require('fs')
+ , path = require('path')
+ , _ = require('underscore')
+ , walker = require('walker')
+;
module.exports = function(dirPath, params, callback) {
-
+
var
files = [],
options = {
@@ -44,13 +44,13 @@ module.exports = function(dirPath, params, callback) {
var hashMap = Object.create(null);
async.forEach(files, function(filename, fileCallback) {
hash(filename, function(error, fileHash) {
-
+
var
urlPath = path.normalize('/' + filename.substring(dirPath.length + 1)),
pos = urlPath.lastIndexOf('/');
-
- hashMap[urlPath] =
- urlPath.substring(0, pos) + '/' + fileHash +
+
+ hashMap[urlPath] =
+ urlPath.substring(0, pos) + '/' + fileHash +
urlPath.substring(pos) || url;
fileCallback(error);
@@ -62,7 +62,7 @@ module.exports = function(dirPath, params, callback) {
callback(undefined, hashMap);
});
}
-
+
if (options.fileList) {
for (var i in options.fileList) {
files.push(options.fileList[i]);
@@ -71,7 +71,7 @@ module.exports = function(dirPath, params, callback) {
return;
}
// else
-
+
walker(dirPath)
.on('file', function(filename) {
files.push(filename);
View
@@ -1,6 +1,5 @@
-var
- url = require('url'),
- path = require('path');
+var url = require('url')
+ , path = require('path');
module.exports = function(version) {
View
@@ -1,7 +1,6 @@
module.exports = function(mappedPaths) {
- var
- reverseMap = Object.create(null);
+ var reverseMap = Object.create(null);
if (typeof mappedPaths !== 'object') {
throw new Error('A hash map of paths is required');
@@ -1,85 +1,84 @@
-var
- appEngine,
- assert = require('assert'),
- request = require('request'),
- versionator = require('../'),
- appEngine = require('connect'),
- http = require('http');
+var appEngine
+ , assert = require('assert')
+ , request = require('request')
+ , versionator = require('../')
+ , appEngine = require('connect')
+ ;
describe('versionator', function() {
- describe('#createBasic', function() {
+ describe('#createBasic', function() {
- it('throws an error if no version is passed', function() {
- assert.throws(function() {
- versionator.createBasic();
- }, /version is required/);
- });
+ it('throws an error if no version is passed', function() {
+ assert.throws(function() {
+ versionator.createBasic();
+ }, /version is required/);
+ });
- it('returns a middleware function', function() {
- versionator.createBasic('0.0.0').middleware.should.be.a('function');
- });
+ it('returns a middleware function', function() {
+ versionator.createBasic('0.0.0').middleware.should.be.a('function');
+ });
- describe('#versionPath', function() {
- it('should inject the version correctly', function() {
- var basic = versionator.createBasic('v0.0.0');
- basic.versionPath('/js/test.js').should.eql('/js/v0.0.0/test.js');
- });
- it('strings without a \'/\' will be left unchanged' , function() {
- var basic = versionator.createBasic('v0.0.0');
- basic.versionPath('Hello this is an odd path').should.eql('Hello this is an odd path');
- });
+ describe('#versionPath', function() {
+ it('should inject the version correctly', function() {
+ var basic = versionator.createBasic('v0.0.0');
+ basic.versionPath('/js/test.js').should.eql('/js/v0.0.0/test.js');
+ });
+ it('strings without a \'/\' will be left unchanged' , function() {
+ var basic = versionator.createBasic('v0.0.0');
+ basic.versionPath('Hello this is an odd path').should.eql('Hello this is an odd path');
+ });
- it('should convert all urls in an array', function() {
- var basic = versionator.createBasic('v0.0.0');
- basic.versionPath(['/js/test.js']).should.eql(['/js/v0.0.0/test.js']);
- });
+ it('should convert all urls in an array', function() {
+ var basic = versionator.createBasic('v0.0.0');
+ basic.versionPath(['/js/test.js']).should.eql(['/js/v0.0.0/test.js']);
+ });
- it('should return an empty array when passed an empty url', function() {
- var basic = versionator.createBasic('v0.0.0');
- basic.versionPath([]).should.eql([]);
- });
- });
+ it('should return an empty array when passed an empty url', function() {
+ var basic = versionator.createBasic('v0.0.0');
+ basic.versionPath([]).should.eql([]);
+ });
+ });
- });
+ });
- describe('basic middleware', function() {
+ describe('basic middleware', function() {
- function startServer(port) {
- var app = appEngine.createServer(
- versionator.createBasic('v0.1.2').middleware,
- function(req, res, next) {
- res.end(req.url);
- }
- );
+ function startServer(port) {
+ var app = appEngine.createServer(
+ versionator.createBasic('v0.1.2').middleware,
+ function(req, res, next) {
+ res.end(req.url);
+ }
+ );
- return app.listen(port);
- }
+ return app.listen(port);
+ }
- it('req.url has version removed from pathname', function(done) {
+ it('req.url has version removed from pathname', function(done) {
- var app = startServer(9898);
+ var app = startServer(9898);
- request('http://localhost:9898/images/v0.1.2/sprite.png', function(error, response, data) {
- data.should.eql('/images/sprite.png');
- app.close();
- done();
- });
- });
+ request('http://localhost:9898/images/v0.1.2/sprite.png', function(error, response, data) {
+ data.should.eql('/images/sprite.png');
+ app.close();
+ done();
+ });
+ });
- it('req.url is unchanged if no version match is found', function(done) {
+ it('req.url is unchanged if no version match is found', function(done) {
- var app = startServer(9899);
+ var app = startServer(9899);
- request('http://localhost:9899/images/sprite.png', function(error, response, data) {
- data.should.eql('/images/sprite.png');
- app.close();
- done();
- });
- });
+ request('http://localhost:9899/images/sprite.png', function(error, response, data) {
+ data.should.eql('/images/sprite.png');
+ app.close();
+ done();
+ });
+ });
- });
+ });
});
Oops, something went wrong.

0 comments on commit f5a4d69

Please sign in to comment.