summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/book.js9
-rw-r--r--lib/utils/fs.js12
-rw-r--r--test/books/structure/glossary.md5
-rw-r--r--test/structure.js18
4 files changed, 37 insertions, 7 deletions
diff --git a/lib/book.js b/lib/book.js
index cb00ab1..93c9486 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -614,12 +614,13 @@ Book.prototype.findFile = function(filename) {
var filepath = basename+ext;
- return that.fileExists(filepath)
- .then(function(exists) {
- if (!exists) return null;
+ return fs.findFile(that.root, filepath)
+ .then(function(realFilepath) {
+ if (!realFilepath) return null;
+
return {
parser: parsers.get(ext),
- path: filepath
+ path: realFilepath
};
});
});
diff --git a/lib/utils/fs.js b/lib/utils/fs.js
index 716e3a0..b82701f 100644
--- a/lib/utils/fs.js
+++ b/lib/utils/fs.js
@@ -30,6 +30,7 @@ var fsUtils = {
fs.exists(path, d.resolve);
return d.promise;
},
+ findFile: findFile,
existsSync: fs.existsSync.bind(fs),
readFileSync: fs.readFileSync.bind(fs),
clean: cleanFolder,
@@ -178,4 +179,15 @@ function cleanFolder(root) {
});
}
+// Find a file in a folder (case incensitive)
+// Return the real filename
+function findFile(root, filename) {
+ return Q.nfcall(fs.readdir, root)
+ .then(function(files) {
+ return _.find(files, function(file) {
+ return (file.toLowerCase() == filename.toLowerCase());
+ });
+ });
+}
+
module.exports = fsUtils;
diff --git a/test/books/structure/glossary.md b/test/books/structure/glossary.md
new file mode 100644
index 0000000..8c6c0fd
--- /dev/null
+++ b/test/books/structure/glossary.md
@@ -0,0 +1,5 @@
+# Glossary
+
+### Hello
+
+Hello world
diff --git a/test/structure.js b/test/structure.js
index b25a021..90413cb 100644
--- a/test/structure.js
+++ b/test/structure.js
@@ -1,8 +1,20 @@
describe('Structure', function () {
- it('should prioritize structure defined in book.json', function() {
+ var book;
+
+ before(function() {
return books.parse('structure')
- .then(function(book) {
- book.readmeFile.should.equal('README.adoc');
+ .then(function(_book) {
+ book = _book;
});
});
+
+
+ it('should prioritize structure defined in book.json', function() {
+ book.readmeFile.should.equal('README.adoc');
+ });
+
+ it('should be case incensitive', function() {
+ book.glossaryFile.should.equal('glossary.md');
+ book.glossary.should.have.lengthOf(1);
+ });
});