diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-01-27 10:24:06 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-01-27 10:24:06 +0100 |
commit | f305d57ab7702c3ca10fd6e32366d19e524ee1f0 (patch) | |
tree | 381ccb09c7cedc72cdf8ad6c98b681b72f4d1bc0 /lib/backbone/article.js | |
parent | 877f2e477b010f9f37a9044606f110a90f077680 (diff) | |
download | gitbook-f305d57ab7702c3ca10fd6e32366d19e524ee1f0.zip gitbook-f305d57ab7702c3ca10fd6e32366d19e524ee1f0.tar.gz gitbook-f305d57ab7702c3ca10fd6e32366d19e524ee1f0.tar.bz2 |
Add more classes structures
Diffstat (limited to 'lib/backbone/article.js')
-rw-r--r-- | lib/backbone/article.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/backbone/article.js b/lib/backbone/article.js new file mode 100644 index 0000000..68d8236 --- /dev/null +++ b/lib/backbone/article.js @@ -0,0 +1,28 @@ +var url = require('url'); +var _ = require('lodash'); + +/* +An article represent an entry in the Summary. +It's defined by a title, a reference, and children articles, the reference (ref) can be a filename + anchor (optional) + +*/ + +function Article(title, ref, articles) { + var parts = url.parse(ref); + + this.title = title; + this.filename = parts.pathname; + this.anchor = parts.hash; + 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 +Article.prototype.hasChildren = function() { + return this.articles.length > 0; +}; + + +module.exports = Article; |