summaryrefslogtreecommitdiffstats
path: root/lib/book.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/book.js')
-rw-r--r--lib/book.js51
1 files changed, 48 insertions, 3 deletions
diff --git a/lib/book.js b/lib/book.js
index 77539ce..73a43ec 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -97,9 +97,27 @@ Book.prototype.prepareConfig = function() {
};
// Resolve a path in the book source
-// Enforce that the output path in the root folder
+// Enforce that the output path is in the scope
Book.prototype.resolve = function() {
- return pathUtil.resolveInRoot.apply(null, [this.root].concat(_.toArray(arguments)));
+ var filename = path.resolve.apply([this.root].concat(_.toArray(arguments)));
+ if (!this.isFileInScope(filename)) {
+ var err = new Error('EACCESS: "' + filename + '" not in "' + this.root + '"');
+ err.code = 'EACCESS';
+ throw err;
+ }
+
+ return filename;
+};
+
+// Return false if a file is outside the book' scope
+Book.prototype.isFileInScope = function(filename) {
+ filename = path.resolve(this.root, filename);
+
+ // Is the file in the scope of the parent?
+ if (this.parent && this.parent.isFileInScope(filename)) return true;
+
+ // Is file in the root folder?
+ return pathUtil.isInRoot(this.root, filename);
};
// Parse .gitignore, etc to extract rules
@@ -133,8 +151,25 @@ Book.prototype.parse = function() {
.then(function() {
if (that.isMultilingual()) {
+ if (that.isLanguageBook()) {
+ throw new Error('A multilingual book as a language book is forbidden');
+ }
+
that.log.info.ln('Parsing multilingual book, with', that.langs.count(), 'languages');
- return;
+
+ // Create a new book for each language and parse it
+ return Promise.serial(that.langs.list(), function(lang) {
+ that.log.debug.ln('Preparing book for language', lang.id);
+ var langBook = new Book({
+ fs: that.fs,
+ parent: that,
+ root: that.resolve(lang.id)
+ });
+
+ that.books.push(langBook);
+
+ return langBook.parse();
+ });
}
return Promise()
@@ -229,4 +264,14 @@ Book.prototype.isMultilingual = function() {
return this.langs.count() > 0;
};
+// Return true if file is in the scope of a child book
+Book.prototype.isInLanguageBook = function(filename) {
+ return _.some(this.langs.list(), function(lang) {
+ return pathUtil.isInRoot(
+ this.resolve(lang.id),
+ this.resolve(filename)
+ );
+ });
+};
+
module.exports = Book;