diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-04-24 00:15:38 +0200 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-04-24 00:15:38 +0200 |
commit | c3275a4aa985710c0fcc9d3f7104bc5ebed2eb04 (patch) | |
tree | e072d9aa0bdc59879d105a777a60010491971b56 /lib/models/book.js | |
parent | 927185d95c9875a9b74d176b93669ebdbceecd14 (diff) | |
download | gitbook-c3275a4aa985710c0fcc9d3f7104bc5ebed2eb04.zip gitbook-c3275a4aa985710c0fcc9d3f7104bc5ebed2eb04.tar.gz gitbook-c3275a4aa985710c0fcc9d3f7104bc5ebed2eb04.tar.bz2 |
Parse multilingual books
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; |