Skip to content

Commit

Permalink
Fixed a bug with nested subdirectories not working
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelr committed Mar 7, 2012
1 parent 73c82cd commit 91e7612
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 36 deletions.
2 changes: 1 addition & 1 deletion nanodoc.js
Expand Up @@ -93,7 +93,7 @@ module.exports = function(options, cb) {

function parseOneInputFile(input, cb) {
var basename = input.match(inputBasename)[1];
var outputBasename = basename.replace('/', '.');
var outputBasename = basename.replace(/\//g, '.');
flow.exec(
function() {
fs.readFile(input, 'utf8', errcheck(this));
Expand Down
61 changes: 27 additions & 34 deletions test/input-transform.js
Expand Up @@ -7,43 +7,36 @@ describe('input transform', function() {
helper.nanodocHere(done);
});

it('should place files from the root directory', function(done) {
helper.isFile(helper.outfile('a.html'), function(err, success) {
if(err) return done(err);
expect(success).to.be.ok();
done();
});
});
function testPlace(filename) {
return function(done) {
helper.isFile(helper.outfile(filename), function(err, success) {
if(err) return done(err);
expect(success).to.be.ok();
done();
});
};
}

it('should transform the files from the root directory ', function(done) {
fs.readFile(helper.outfile('a.html'), 'utf8', function(err, data) {
if(err) return done(err);
expect(data.match(/^a-a-a;/)).to.be.ok();
expect(data.match(/a-a-a<\/h1>/)).to.be.ok();
expect(data.match(/text/)).to.be.ok();
expect(data.match(/NAVIGATION/)).to.be.ok();
done();
});
});
function testTransform(filename, content) {
return function(done) {
fs.readFile(helper.outfile(filename), 'utf8', function(err, data) {
if(err) return done(err);
expect(data.match(new RegExp('^' + content + ';'))).to.be.ok();
expect(data.match(new RegExp(content + '<\/h1>'))).to.be.ok();
expect(data.match(/TEXT/)).to.be.ok();
expect(data.match(/NAVIGATION/)).to.be.ok();
done();
});
};
}

it('should place files from subdirectories', function(done) {
helper.isFile(helper.outfile('sub.b.html'), function(err, success) {
if(err) return done(err);
expect(success).to.be.ok();
done();
});
});
it('should place files from the root directory', testPlace('a.html'));
it('should place files from subdirectories', testPlace('sub.b.html'));
it('should place files from nested subdirectories', testPlace('sub.again.c.html'));

it('should transform the files from subdirectories ', function(done) {
fs.readFile(helper.outfile('sub.b.html'), 'utf8', function(err, data) {
if(err) return done(err);
expect(data.match(/^b-b-b;/)).to.be.ok();
expect(data.match(/b-b-b<\/h1>/)).to.be.ok();
expect(data.match(/TEXT/)).to.be.ok();
expect(data.match(/NAVIGATION/)).to.be.ok();
done();
});
});
it('should transform the files from the root directory', testTransform('a.html', 'a-a-a'));
it('should transform the files from subdirectories ', testTransform('sub.b.html', 'b-b-b'));
it('should transform the files from nested subdirectories ', testTransform('sub.again.c.html', 'c-c-c'));

it('should use a default value for the title if none is given', function(done) {
fs.readFile(helper.outfile('no_title.html'), 'utf8', function(err, data) {
Expand Down
2 changes: 1 addition & 1 deletion test/test_data/input/a.md
@@ -1,3 +1,3 @@
a-a-a
=====
text
TEXT
3 changes: 3 additions & 0 deletions test/test_data/input/sub/again/c.md
@@ -0,0 +1,3 @@
c-c-c
=====
TEXT

0 comments on commit 91e7612

Please sign in to comment.