Add stylesheet option

closes #2
This commit is contained in:
Chris O'Connor
2014-04-28 14:10:35 -04:00
committed by Douglas Christopher Wilson
parent 5771318d78
commit e40300aa86
3 changed files with 28 additions and 4 deletions

View File

@@ -41,7 +41,7 @@ var defaultTemplate = join(__dirname, 'public', 'directory.html');
* Stylesheet.
*/
var stylesheet = join(__dirname, 'public', 'style.css');
var defaultStylesheet = join(__dirname, 'public', 'style.css');
/**
* Media types and the map for content negotiation.
@@ -93,7 +93,8 @@ exports = module.exports = function directory(root, options){
, view = options.view || 'tiles'
, filter = options.filter
, root = normalize(root + sep)
, template = options.template || defaultTemplate;
, template = options.template || defaultTemplate
, stylesheet = options.stylesheet || defaultStylesheet;
return function directory(req, res, next) {
if ('GET' != req.method && 'HEAD' != req.method) return next();
@@ -131,7 +132,7 @@ exports = module.exports = function directory(root, options){
// not acceptable
if (!type) return next(createError(406));
exports[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view, template);
exports[mediaType[type]](req, res, files, next, originalDir, showUp, icons, path, view, template, stylesheet);
});
});
};
@@ -141,7 +142,7 @@ exports = module.exports = function directory(root, options){
* Respond with text/html.
*/
exports.html = function(req, res, files, next, dir, showUp, icons, path, view, template){
exports.html = function(req, res, files, next, dir, showUp, icons, path, view, template, stylesheet){
fs.readFile(template, 'utf8', function(err, str){
if (err) return next(err);
fs.readFile(stylesheet, 'utf8', function(err, style){

3
test/shared/styles.css Normal file
View File

@@ -0,0 +1,3 @@
body {
color: #00ff00;
}

View File

@@ -161,6 +161,26 @@ describe('directory()', function(){
});
});
describe('when setting a custom stylesheet', function () {
var server;
before(function () {
server = createServer('test/fixtures', {'stylesheet': __dirname + '/shared/styles.css'});
});
after(function (done) {
server.close(done);
});
it('should respond with appropriate embedded styles', function (done) {
request(server)
.get('/')
.set('Accept', 'text/html')
.expect(200)
.expect('Content-Type', /html/)
.expect(/color: #00ff00;/)
.end(done);
});
});
describe('when set with trailing slash', function () {
var server;
before(function () {