summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-19 21:16:06 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-19 21:16:06 +0100
commita67dad8cbef26f800a9be67cd15bea5a304de140 (patch)
tree3573b8a1b65b2f88ece7f9bc596b4f3a129c0cfd
parentb549158483de1336b8b48a1ccbb5c87ea54e8b34 (diff)
downloadgitbook-a67dad8cbef26f800a9be67cd15bea5a304de140.zip
gitbook-a67dad8cbef26f800a9be67cd15bea5a304de140.tar.gz
gitbook-a67dad8cbef26f800a9be67cd15bea5a304de140.tar.bz2
Fix list of files and parsing of navigation files only
-rw-r--r--lib/book.js15
-rw-r--r--test/generation.js37
-rw-r--r--test/parsing.js4
3 files changed, 33 insertions, 23 deletions
diff --git a/lib/book.js b/lib/book.js
index 1236e5f..41b1d1a 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -33,6 +33,7 @@ var Book = function(root, options, parent) {
// Summary
this.summary = {};
+ this.navigation = [];
// Glossary
this.glossary = [];
@@ -85,19 +86,19 @@ Book.prototype.parse = function() {
.then(function() {
if (multilingal) return;
- return that.parseReadme();
+ return that.listAllFiles();
})
.then(function() {
if (multilingal) return;
- return that.parseSummary();
+ return that.parseReadme();
})
.then(function() {
if (multilingal) return;
- return that.parseGlossary();
+ return that.parseSummary();
})
.then(function() {
if (multilingal) return;
- return that.listAllFiles();
+ return that.parseGlossary();
})
.then(function() {
@@ -149,7 +150,7 @@ Book.prototype.generate = function(generator) {
if (file[file.length -1] == "/") {
return Q(generator.transferFolder(file));
- } else if (_.contains(parsers.extensions, path.extname(file)) && 1) {
+ } else if (_.contains(parsers.extensions, path.extname(file)) && that.navigation[file]) {
return that.parsePage(file)
.then(function(content) {
return Q(generator.writeParsedFile(content, file));
@@ -269,6 +270,7 @@ Book.prototype.parseSummary = function() {
})
.then(function(summary) {
that.summary = summary;
+ that.navigation = parseNavigation(that.summary, that.files);
});
};
@@ -307,8 +309,7 @@ Book.prototype.parsePage = function(filename) {
return filetype.parser.page(content);
})
.then(function(page) {
- page.navigation = parseNavigation(that.summary, that.files);
- page.progress = parseProgress(page.navigation, filename);
+ page.progress = parseProgress(that.navigation, filename);
return page;
});
};
diff --git a/test/generation.js b/test/generation.js
index 6bfb095..b043885 100644
--- a/test/generation.js
+++ b/test/generation.js
@@ -2,26 +2,35 @@ var path = require('path');
var _ = require('lodash');
var assert = require('assert');
-var fs = require('../lib/utils/fs');
+var fs = require("fs");
+var fsUtil = require("../lib/utils/fs");
+
+var testGeneration = function(book, type, func, done) {
+ var OUTPUT_PATH = book.options.output;
+
+ qdone(
+ book.generate(type)
+ .then(function() {
+ func(OUTPUT_PATH);
+ })
+ .fin(function() {
+ return fsUtil.remove(OUTPUT_PATH);
+ }),
+ done);
+};
+
describe('Book generation', function () {
it('should correctly generate a book to json', function(done) {
- var OUTPUT_PATH = book1.options.output;
-
- qdone(
- book1.generate("json")
- .fin(function() {
- return fs.remove(OUTPUT_PATH);
- }), done);
+ testGeneration(book1, "json", function(output) {
+ assert(!fs.existsSync(path.join(output, "README.json")));
+ assert(fs.existsSync(path.join(output, "intro.json")))
+ }, done);
});
it('should correctly generate a multilingual book to json', function(done) {
- var OUTPUT_PATH = book2.options.output;
+ testGeneration(book2, "json", function(output) {
- qdone(
- book2.generate("json")
- .fin(function() {
- return fs.remove(OUTPUT_PATH);
- }), done);
+ }, done);
});
});
diff --git a/test/parsing.js b/test/parsing.js
index 636b574..bde8be3 100644
--- a/test/parsing.js
+++ b/test/parsing.js
@@ -31,8 +31,8 @@ describe('Book parsing', function () {
it('should correctly parse files', function() {
var FILES = book1.files;
- assert.equal(FILES.length, 4);
- assert.equal(_.difference(FILES, [ 'GLOSSARY.md', 'README.md', 'SUMMARY.md', 'intro.md' ]).length, 0);
+ assert.equal(FILES.length, 2);
+ assert.equal(_.difference(FILES, [ 'intro.md', 'README.md' ]).length, 0);
});
it('should correctly parse the languages', function() {