diff options
Diffstat (limited to 'lib/backbone')
-rw-r--r-- | lib/backbone/article.js | 2 | ||||
-rw-r--r-- | lib/backbone/glossary.js | 51 | ||||
-rw-r--r-- | lib/backbone/page.js | 4 |
3 files changed, 55 insertions, 2 deletions
diff --git a/lib/backbone/article.js b/lib/backbone/article.js index 68d8236..299df25 100644 --- a/lib/backbone/article.js +++ b/lib/backbone/article.js @@ -16,7 +16,7 @@ function Article(title, ref, articles) { this.articles = _.map(articles || [], function(article) { if (article instanceof Article) return article; return new Article(article.title, article.ref, article.articles); - }) + }); } // Return true if has children diff --git a/lib/backbone/glossary.js b/lib/backbone/glossary.js index aba83cf..b25d7c7 100644 --- a/lib/backbone/glossary.js +++ b/lib/backbone/glossary.js @@ -1,8 +1,57 @@ +var _ = require('lodash'); +var util = require('util'); +var BackboneFile = require('./file'); -function Glossary() { +/* +A glossary entry is represented by a name and a short description +An unique id for the entry is generated using its name +*/ +function GlossaryEntry(name, description) { if (!(this instanceof Glossary)) return new Glossary(); + + this.name = name; + this.description = description; + + Object.defineProperty(this, 'id', { + get: _.bind(this.getId, this) + }); +} + +// Normalizes a glossary entry's name to create an ID +GlossaryEntry.prototype.getId = function() { + return this.name.toLowerCase() + .replace(/[\/\\\?\%\*\:\;\|\"\'\\<\\>\#\$\(\)\!\.\@]/g, '') + .replace(/ /g, '_') + .trim(); +}; + + +function Glossary() { + BackboneFile.apply(this, arguments); + + this.entries = []; } +util.inherits(Glossary, BackboneFile); Glossary.prototype.type = 'glossary'; +// Parse the readme content +Glossary.prototype.parse = function(content) { + var that = this; + + return this.parser.glossary(content) + .then(function(entries) { + that.entries = _.map(entries, function(entry) { + return new GlossaryEntry(entry.name, entry.description); + }); + }); +}; + +// Return an entry by its id +Glossary.prototype.get = function(id) { + return _.find(this.entries, { + id: id + }); +}; + module.exports = Glossary; diff --git a/lib/backbone/page.js b/lib/backbone/page.js index fdfe3f7..33bd636 100644 --- a/lib/backbone/page.js +++ b/lib/backbone/page.js @@ -10,6 +10,10 @@ function Page(book, filename) { this.filename = filename; } +// Return the filename of the page with another extension +Page.prototype.withExtension = function(ext) { + return +}; module.exports = Page; |