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.js64
1 files changed, 35 insertions, 29 deletions
diff --git a/lib/backbone/summary.js b/lib/backbone/summary.js
index 4cfff28..439546b 100644
--- a/lib/backbone/summary.js
+++ b/lib/backbone/summary.js
@@ -124,12 +124,10 @@ TOCArticle.prototype.map = function(iter) {
/*
A part of a ToC is a composed of a tree of articles and an optiona title
*/
-function TOCPart(part, summary) {
- if (!(this instanceof TOCPart)) return new TOCPart(part);
+function TOCPart(part, parent) {
+ if (!(this instanceof TOCPart)) return new TOCPart(part, parent);
TOCArticle.apply(this, arguments);
-
- this.summary = summary;
}
util.inherits(TOCPart, TOCArticle);
@@ -138,7 +136,7 @@ TOCPart.prototype.validate = function() { };
// Return a sibling (next or prev) of this part
TOCPart.prototype.sibling = function(direction) {
- var parts = this.summary.parts;
+ var parts = this.parent.parts;
var pos = _.findIndex(parts, this);
if (parts[pos + direction]) {
@@ -200,6 +198,11 @@ util.inherits(Summary, BackboneFile);
Summary.prototype.type = 'summary';
+// Prepare summary when non existant
+Summary.prototype.parseNotFound = function() {
+ this.update([]);
+};
+
// Parse the summary content
Summary.prototype.parse = function(content) {
var that = this;
@@ -207,28 +210,7 @@ Summary.prototype.parse = function(content) {
return this.parser.summary(content)
.then(function(summary) {
- that.parts = _.map(summary.parts, function(part) {
- return new TOCPart(part, that);
- });
-
- // Create first part if none
- if (that.parts.length == 0) {
- that.parts.push(new TOCPart({}, that));
- }
-
- // Add README as first entry
- var firstArticle = that.parts[0].articles[0];
- if (!firstArticle || firstArticle.path != that.book.readme.path) {
- that.parts[0].articles.unshift(new TOCArticle({
- title: 'Introduction',
- path: that.book.readme.path,
- isAutoIntro: true
- }, that.parts[0]));
- }
- that.parts[0].articles[0].isIntroduction = true;
-
- // Update count of articles and create "level"
- that.update();
+ that.update(summary.parts);
});
};
@@ -297,9 +279,33 @@ Summary.prototype.count = function() {
return this._length;
};
-// Update the count and indexing of "level"
-Summary.prototype.update = function() {
+// Prepare the summary
+Summary.prototype.update = function(parts) {
var that = this;
+
+
+ that.parts = _.map(parts, function(part) {
+ return new TOCPart(part, that);
+ });
+
+ // Create first part if none
+ if (that.parts.length == 0) {
+ that.parts.push(new TOCPart({}, that));
+ }
+
+ // Add README as first entry
+ var firstArticle = that.parts[0].articles[0];
+ if (!firstArticle || firstArticle.path != that.book.readme.path) {
+ that.parts[0].articles.unshift(new TOCArticle({
+ title: 'Introduction',
+ path: that.book.readme.path,
+ isAutoIntro: true
+ }, that.parts[0]));
+ }
+ that.parts[0].articles[0].isIntroduction = true;
+
+
+ // Update the count and indexing of "level"
var prev = undefined;
that._length = 0;