summaryrefslogtreecommitdiffstats
path: root/lib/backbone/summary.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/backbone/summary.js')
-rw-r--r--lib/backbone/summary.js36
1 files changed, 35 insertions, 1 deletions
diff --git a/lib/backbone/summary.js b/lib/backbone/summary.js
index cef3ae9..5d4d53c 100644
--- a/lib/backbone/summary.js
+++ b/lib/backbone/summary.js
@@ -45,7 +45,8 @@ TOCArticle.prototype.walk = function(iter) {
TOCArticle.prototype.getContext = function() {
return {
title: this.title,
- path: this.path
+ path: this.path,
+ anchor: this.anchor
};
};
@@ -98,6 +99,12 @@ TOCArticle.prototype.prev = function() {
}
};
+// Map over all articles
+TOCArticle.prototype.map = function(iter) {
+ return _.map(this.articles, iter);
+};
+
+
/*
A part of a ToC is a composed of a tree of articles.
*/
@@ -121,6 +128,11 @@ TOCPart.prototype.walk = function(iter) {
});
};
+// Map over all articles
+TOCPart.prototype.map = function(iter) {
+ return _.map(this.articles, iter);
+};
+
/*
A summary is composed of a list of parts, each composed wit a tree of articles.
*/
@@ -152,6 +164,28 @@ Summary.prototype.parse = function(content) {
});
};
+// Return templating context for the summary
+Summary.prototype.getContext = function() {
+ function onArticle(article) {
+ var result = article.getContext();
+ if (article.hasChildren()) {
+ result.articles = article.map(onArticle);
+ }
+
+ return result;
+ }
+
+ return {
+ summary: {
+ parts: _.map(this.parts, function(part) {
+ return {
+ articles: part.map(onArticle)
+ };
+ })
+ }
+ };
+};
+
// Iterate over all entries of the summary
// iter is called with an TOCArticle
Summary.prototype.walk = function(iter) {