Browse files

Fixed a bug with nested subdirectories not working

  • Loading branch information...
1 parent 73c82cd commit 91e7612f4ed36a9dfa6ae8d5317222d4debe628f @raphaelr committed Mar 7, 2012
Showing with 32 additions and 36 deletions.
  1. +1 −1 nanodoc.js
  2. +27 −34 test/input-transform.js
  3. +1 −1 test/test_data/input/a.md
  4. +3 −0 test/test_data/input/sub/again/c.md
View
2 nanodoc.js
@@ -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));
View
61 test/input-transform.js
@@ -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) {
View
2 test/test_data/input/a.md
@@ -1,3 +1,3 @@
a-a-a
=====
-text
+TEXT
View
3 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.