diff options
Diffstat (limited to 'lib/models/book.js')
-rw-r--r-- | lib/models/book.js | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/lib/models/book.js b/lib/models/book.js index da0deee..62faba6 100644 --- a/lib/models/book.js +++ b/lib/models/book.js @@ -27,7 +27,14 @@ var Book = Immutable.Record({ readme: Readme(), summary: Summary(), glossary: Glossary(), - languages: Languages() + languages: Languages(), + + + // Parent of this book, if multilingual + parent: null, + + // List of children, if multilingual + books: Immutable.List() }); Book.prototype.getLogger = function() { @@ -62,8 +69,12 @@ Book.prototype.getLanguages = function() { return this.get('languages'); }; -Book.prototype.getPages = function() { - return this.get('pages'); +Book.prototype.getParent = function() { + return this.get('parent'); +}; + +Book.prototype.getBooks = function() { + return this.get('books'); }; /** @@ -132,6 +143,15 @@ Book.prototype.getPage = function(ref) { }; /** + Is this book the parent of language's books + + @return {Boolean} +*/ +Book.prototype.isMultilingual = function() { + return (this.getLanguages().getList().size > 0); +}; + +/** Create a book using a filesystem @param {FS} fs @@ -143,4 +163,19 @@ Book.createForFS = function createForFS(fs) { }); }; +/** + Create a language book from a parent + + @param {Book} parent + @param {String} basePath: folder o the book in the parent + @return {Book} +*/ +Book.createFromParent = function createFromParent(parent, basePath) { + return new Book({ + logger: parent.getLogger(), + parent: parent, + fs: FS.reduceScope(book.getFS(), basePath) + }); +}; + module.exports = Book; |