diff options
Diffstat (limited to 'lib/backbone')
-rw-r--r-- | lib/backbone/glossary.js | 3 | ||||
-rw-r--r-- | lib/backbone/langs.js | 54 |
2 files changed, 55 insertions, 2 deletions
diff --git a/lib/backbone/glossary.js b/lib/backbone/glossary.js index 22c4d42..9aed1ac 100644 --- a/lib/backbone/glossary.js +++ b/lib/backbone/glossary.js @@ -32,6 +32,9 @@ GlossaryEntry.prototype.getId = function() { }; +/* +A glossary is a list of entries stored in a GLOSSARY.md file +*/ function Glossary() { BackboneFile.apply(this, arguments); diff --git a/lib/backbone/langs.js b/lib/backbone/langs.js index 2818519..a40bd80 100644 --- a/lib/backbone/langs.js +++ b/lib/backbone/langs.js @@ -1,15 +1,65 @@ +var _ = require('lodash'); +var path = require('path'); +var util = require('util'); +var BackboneFile = require('./file'); +function Language(title, folder) { + var that = this; + + this.title = title; + this.folder = folder; + + Object.defineProperty(this, 'id', { + get: function() { + return path.basename(that.folder); + } + }); +} + +/* +A Langs is a list of languages stored in a LANGS.md file +*/ function Langs() { - if (!(this instanceof Langs)) return new Langs(); + BackboneFile.apply(this, arguments); this.languages = []; } +util.inherits(Langs, BackboneFile); Langs.prototype.type = 'langs'; +// Parse the readme content +Langs.prototype.parse = function(content) { + var that = this; + + return this.parser.langs(content) + .then(function(langs) { + that.languages = _.map(langs, function(entry) { + return new Language(entry.title, entry.path); + }); + }); +}; + +// Return the list of languages +Langs.prototype.list = function() { + return this.languages; +}; + +// Return default/main language for the book +Langs.prototype.getDefault = function() { + return _.first(this.languages); +}; + +// Return true if a language is the default one +// "lang" cam be a string (id) or a Language entry +Langs.prototype.isDefault = function(lang) { + lang = lang.id || lang; + return (this.cound() > 0 && this.getDefault().id == lang); +}; + // Return the count of languages Langs.prototype.count = function() { - return this.languages.length; + return _.size(this.languages); }; module.exports = Langs; |