summaryrefslogtreecommitdiffstats
path: root/lib/backbone
diff options
context:
space:
mode:
Diffstat (limited to 'lib/backbone')
-rw-r--r--lib/backbone/article.js28
-rw-r--r--lib/backbone/file.js2
-rw-r--r--lib/backbone/page.js15
-rw-r--r--lib/backbone/summary.js1
4 files changed, 45 insertions, 1 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;
diff --git a/lib/backbone/file.js b/lib/backbone/file.js
index 71fc78c..34cf066 100644
--- a/lib/backbone/file.js
+++ b/lib/backbone/file.js
@@ -15,7 +15,7 @@ BackboneFile.prototype.type = '';
// Parse a backbone file
BackboneFile.prototype.parse = function() {
-
+ // To be implemented by each child
};
// Return true if backbone file exists
diff --git a/lib/backbone/page.js b/lib/backbone/page.js
new file mode 100644
index 0000000..fdfe3f7
--- /dev/null
+++ b/lib/backbone/page.js
@@ -0,0 +1,15 @@
+
+/*
+A page represent a parsable file in the book (Markdown, Asciidoc, etc)
+*/
+
+function Page(book, filename) {
+ if (!(this instanceof Page)) return new Page();
+
+ this.book = book;
+ this.filename = filename;
+}
+
+
+
+module.exports = Page;
diff --git a/lib/backbone/summary.js b/lib/backbone/summary.js
index e2cd485..7eb6e0c 100644
--- a/lib/backbone/summary.js
+++ b/lib/backbone/summary.js
@@ -1,3 +1,4 @@
+var Article = require('./article');
function Summary() {
if (!(this instanceof Summary)) return new Summary();