diff options
author | Soreine <nicolas@gitbook.com> | 2016-05-02 16:24:49 +0200 |
---|---|---|
committer | Soreine <nicolas@gitbook.com> | 2016-05-03 11:17:27 +0200 |
commit | 6b17d08892828818216a260576c83b7203c2098f (patch) | |
tree | 706d2a9376152ad44ddb69a9683a6ca79df71fe4 | |
parent | 79c91fd8c5f4a975b766d463af0464a656bbffc3 (diff) | |
download | gitbook-6b17d08892828818216a260576c83b7203c2098f.zip gitbook-6b17d08892828818216a260576c83b7203c2098f.tar.gz gitbook-6b17d08892828818216a260576c83b7203c2098f.tar.bz2 |
Adds default file naming utilities in Book model
-rw-r--r-- | lib/models/book.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/lib/models/book.js b/lib/models/book.js index cd6cfad..e39897b 100644 --- a/lib/models/book.js +++ b/lib/models/book.js @@ -245,6 +245,58 @@ Book.createForFS = function createForFS(fs) { }; /** + Infers the default extension for files + @return {String} +*/ +Book.prototype.getDefaultExt = function() { + // Inferring sources + var clues = [ + this.getReadme(), + this.getSummary(), + this.getGlossary() + ]; + + // List their extensions + var exts = clues.map(function (clue) { + var file = clue.getFile(); + if (file.exists()) { + return file.getParser().getExtensions().first(); + } else { + return null; + } + }); + // Adds the general default extension + exts.push('.md'); + + // Choose the first non null + return exts.find(function (e) { return e !== null; }); +}; + +/** + Infer the default path for a Readme. + @return {String} +*/ +Book.prototype.getDefaultReadmePath = function() { + return this.getContentRoot()+'README'+this.getDefaultExt(); +}; + +/** + Infer the default path for a Summary. + @return {String} +*/ +Book.prototype.getDefaultSummaryPath = function() { + return this.getContentRoot()+'SUMMARY'+this.getDefaultExt(); +}; + +/** + Infer the default path for a Glossary. + @return {String} +*/ +Book.prototype.getDefaultGlossaryPath = function() { + return this.getContentRoot()+'GLOSSARY'+this.getDefaultExt(); +}; + +/** Create a language book from a parent @param {Book} parent |