From 582df127b6aee044b5ba6396ad9d9a97a2c35d16 Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 10:45:31 -0800 Subject: [PATCH 01/12] adding template, suggessted fix for @Earl-Brown --- lib/middleware/directory.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/middleware/directory.js b/lib/middleware/directory.js index ac8ea7a5c..c179281e9 100644 --- a/lib/middleware/directory.js +++ b/lib/middleware/directory.js @@ -1,4 +1,3 @@ - /*! * Connect - directory * Copyright(c) 2011 Sencha Inc. @@ -72,7 +71,8 @@ exports = module.exports = function directory(root, options){ , icons = options.icons , view = options.view || 'tiles' , filter = options.filter - , root = normalize(root + sep); + , root = normalize(root + sep) + , template = options.template || __dirname + '/../public/directory.html';; return function directory(req, res, next) { if ('GET' != req.method && 'HEAD' != req.method) return next(); @@ -110,7 +110,7 @@ exports = module.exports = function directory(root, options){ // not acceptable if (!type) return next(utils.error(406)); - exports[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view); + exports[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view, template); }); }); }; @@ -120,8 +120,8 @@ exports = module.exports = function directory(root, options){ * Respond with text/html. */ -exports.html = function(req, res, files, next, dir, showUp, icons, path, view){ - fs.readFile(__dirname + '/../public/directory.html', 'utf8', function(err, str){ +exports.html = function(req, res, files, next, dir, showUp, icons, path, view, template){ + fs.readFile(template, 'utf8', function(err, str){ if (err) return next(err); fs.readFile(__dirname + '/../public/style.css', 'utf8', function(err, style){ if (err) return next(err); From b75170973740954687f9bc84cb6ca93e9705b83a Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 11:04:16 -0800 Subject: [PATCH 02/12] adding template option to JSdoc --- lib/middleware/directory.js | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/middleware/directory.js b/lib/middleware/directory.js index c179281e9..ad23ef3d0 100644 --- a/lib/middleware/directory.js +++ b/lib/middleware/directory.js @@ -55,6 +55,7 @@ var mediaType = { * - `hidden` display hidden (dot) files. Defaults to false. * - `icons` display icons. Defaults to false. * - `filter` Apply this filter function to files. Defaults to false. + * - 'template' Optional path to html template. Defaults to __dirname + '/../public/directory.html' * * @param {String} root * @param {Object} options From 94df296ab082370cdc89fe3dbfb3c03bd7b70df0 Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 11:05:57 -0800 Subject: [PATCH 03/12] typo --- lib/middleware/directory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleware/directory.js b/lib/middleware/directory.js index ad23ef3d0..487dfff83 100644 --- a/lib/middleware/directory.js +++ b/lib/middleware/directory.js @@ -55,7 +55,7 @@ var mediaType = { * - `hidden` display hidden (dot) files. Defaults to false. * - `icons` display icons. Defaults to false. * - `filter` Apply this filter function to files. Defaults to false. - * - 'template' Optional path to html template. Defaults to __dirname + '/../public/directory.html' + * - `template` Optional path to html template. Defaults to __dirname + '/../public/directory.html' * * @param {String} root * @param {Object} options From 9b8165fb12b2b2ce0f1c16a2c2dfe83b97e2b615 Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 13:14:49 -0800 Subject: [PATCH 04/12] create template for test --- test/fixtures/template.html | 82 +++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 test/fixtures/template.html diff --git a/test/fixtures/template.html b/test/fixtures/template.html new file mode 100644 index 000000000..411ca92f7 --- /dev/null +++ b/test/fixtures/template.html @@ -0,0 +1,82 @@ + + + + + + listing directory {directory} + + + + + +
+

{linked-path}

+ {files} +
+ + From 1607b3ecdff9f27d4b3914f8e49ce4807519b94f Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 13:15:57 -0800 Subject: [PATCH 05/12] removed extra semicolon --- lib/middleware/directory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/middleware/directory.js b/lib/middleware/directory.js index 487dfff83..b8ed241fd 100644 --- a/lib/middleware/directory.js +++ b/lib/middleware/directory.js @@ -73,7 +73,7 @@ exports = module.exports = function directory(root, options){ , view = options.view || 'tiles' , filter = options.filter , root = normalize(root + sep) - , template = options.template || __dirname + '/../public/directory.html';; + , template = options.template || __dirname + '/../public/directory.html'; return function directory(req, res, next) { if ('GET' != req.method && 'HEAD' != req.method) return next(); From 2b62a918c42e56610db939dc563becf15993bc05 Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 13:30:46 -0800 Subject: [PATCH 06/12] adding test for template --- test/directory.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/test/directory.js b/test/directory.js index a121f35b1..0df201e40 100644 --- a/test/directory.js +++ b/test/directory.js @@ -1,4 +1,3 @@ - var connect = require('..'); var app = connect(); @@ -118,6 +117,25 @@ describe('directory()', function(){ }); }); + describe('when setting a custom template', function () { + var app = connect(connect.directory('test/fixtures'),{template: __dirname + '/fixtures/template.html'}); + + it('should respond with file list and testing template sentence', function (done) { + app.request() + .get('/') + .set('Accept', 'text/html') + .end(function(res){ + res.statusCode.should.equal(200); + res.body.should.include('users'); + res.body.should.include('g# %3 o %2525 %37 dir'); + res.body.should.include('file #1.txt'); + res.body.should.include('todo.txt'); + res.body.should.include('This is the test template'); + done(); + }); + }); + }); + describe('when set with trailing slash', function () { var app = connect(connect.directory('test/fixtures/')); From 99b50f0411936f8d9c436dcfdd598d1b26e5b137 Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 13:31:04 -0800 Subject: [PATCH 07/12] adding test string for test --- test/fixtures/template.html | 1 + 1 file changed, 1 insertion(+) diff --git a/test/fixtures/template.html b/test/fixtures/template.html index 411ca92f7..a59eaf462 100644 --- a/test/fixtures/template.html +++ b/test/fixtures/template.html @@ -74,6 +74,7 @@ +

This is the test template

{linked-path}

{files} From 11b5154bb690021ef709b6267dff502f7f69c229 Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 13:37:07 -0800 Subject: [PATCH 08/12] Delete template.html --- test/fixtures/template.html | 83 ------------------------------------- 1 file changed, 83 deletions(-) delete mode 100644 test/fixtures/template.html diff --git a/test/fixtures/template.html b/test/fixtures/template.html deleted file mode 100644 index a59eaf462..000000000 --- a/test/fixtures/template.html +++ /dev/null @@ -1,83 +0,0 @@ - - - - - - listing directory {directory} - - - - - -

This is the test template

-
-

{linked-path}

- {files} -
- - From 34dbe11ec44bae4a1119e7f3615ccdbeecebf253 Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 13:37:35 -0800 Subject: [PATCH 09/12] Create template.html --- test/shared/template.html | 83 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/shared/template.html diff --git a/test/shared/template.html b/test/shared/template.html new file mode 100644 index 000000000..a59eaf462 --- /dev/null +++ b/test/shared/template.html @@ -0,0 +1,83 @@ + + + + + + listing directory {directory} + + + + + +

This is the test template

+
+

{linked-path}

+ {files} +
+ + From f67a805aeb156359a64c72782ebbc7af1ad6a819 Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 13:38:21 -0800 Subject: [PATCH 10/12] Update directory.js --- test/directory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/directory.js b/test/directory.js index 0df201e40..dedf9e051 100644 --- a/test/directory.js +++ b/test/directory.js @@ -118,7 +118,7 @@ describe('directory()', function(){ }); describe('when setting a custom template', function () { - var app = connect(connect.directory('test/fixtures'),{template: __dirname + '/fixtures/template.html'}); + var app = connect(connect.directory('test/fixtures'),{template: __dirname + '/shared/template.html'}); it('should respond with file list and testing template sentence', function (done) { app.request() From 06b0c7aadef09d3ff6ddf3b086b6c2abd5ff353c Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 13:44:05 -0800 Subject: [PATCH 11/12] Update directory.js --- test/directory.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/directory.js b/test/directory.js index dedf9e051..152b140fe 100644 --- a/test/directory.js +++ b/test/directory.js @@ -126,6 +126,7 @@ describe('directory()', function(){ .set('Accept', 'text/html') .end(function(res){ res.statusCode.should.equal(200); + res.should.be.html; res.body.should.include('users'); res.body.should.include('g# %3 o %2525 %37 dir'); res.body.should.include('file #1.txt'); From 08822f502dfb7c8a02cb7e4301d9525fd3eb52a7 Mon Sep 17 00:00:00 2001 From: Joe Passavanti Date: Thu, 2 Jan 2014 13:55:56 -0800 Subject: [PATCH 12/12] Update directory.js --- test/directory.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/directory.js b/test/directory.js index 152b140fe..17a6a35c3 100644 --- a/test/directory.js +++ b/test/directory.js @@ -118,7 +118,7 @@ describe('directory()', function(){ }); describe('when setting a custom template', function () { - var app = connect(connect.directory('test/fixtures'),{template: __dirname + '/shared/template.html'}); + var app = connect(connect.directory('test/fixtures',{template: __dirname + '/shared/template.html'})); it('should respond with file list and testing template sentence', function (done) { app.request()