summaryrefslogtreecommitdiffstats
path: root/lib/backbone/summary.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-17 13:59:52 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-17 13:59:52 +0100
commitc0196c97a50786cd28c9b72197b39fefb47be333 (patch)
tree1798de09f97132777613aec6c5f3714d56417bd3 /lib/backbone/summary.js
parent96105d6ba0ac1bc86bd34088ae4763bf09b3c3ea (diff)
downloadgitbook-c0196c97a50786cd28c9b72197b39fefb47be333.zip
gitbook-c0196c97a50786cd28c9b72197b39fefb47be333.tar.gz
gitbook-c0196c97a50786cd28c9b72197b39fefb47be333.tar.bz2
Add context for summary
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) {