diff options
Diffstat (limited to 'lib/models')
-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 |