summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-06-06 17:56:16 +0200
committerSamy Pessé <samypesse@gmail.com>2016-12-22 12:32:20 +0100
commitb3f74175ae64c8f04cf4c319f29a4a1db451e9a3 (patch)
treed12bdaf4a33be4e51ddd0b2f863262da7fc6abb7
parent2a01d0ea24907958d517b21048bae01d98227188 (diff)
downloadgitbook-b3f74175ae64c8f04cf4c319f29a4a1db451e9a3.zip
gitbook-b3f74175ae64c8f04cf4c319f29a4a1db451e9a3.tar.gz
gitbook-b3f74175ae64c8f04cf4c319f29a4a1db451e9a3.tar.bz2
Fix support of lodash@4
-rw-r--r--packages/gitbook-html/lib/totext.js48
1 files changed, 29 insertions, 19 deletions
diff --git a/packages/gitbook-html/lib/totext.js b/packages/gitbook-html/lib/totext.js
index fd9c5ae..368d62e 100644
--- a/packages/gitbook-html/lib/totext.js
+++ b/packages/gitbook-html/lib/totext.js
@@ -7,8 +7,12 @@ var _ = require('lodash');
function ToText(markup) {
+ if (!(this instanceof ToText)) {
+ return new ToText(markup);
+ }
+
_.extend(this, markup || {});
- _.bindAll(this);
+ _.bindAll(this, _.functionsIn(this));
};
// Break line
@@ -83,17 +87,19 @@ ToText.prototype.langs = function(languages) {
// ------ GLOSSARY
ToText.prototype.glossary = function(glossary) {
+ var that = this;
var content = '';
- content += this.onTitleStart(1) + this.onText('Glossary') + this.onTitleEnd(1);
- content += this.onSection();
+
+ content += that.onTitleStart(1) + that.onText('Glossary') + that.onTitleEnd(1);
+ content += that.onSection();
_.each(glossary, function(entry) {
- content += this.onTitleStart(2) + this.onText(entry.name) + this.onTitleEnd(2);
- content += this.onParagraphStart();
- content += this.onText(entry.description);
- content += this.onParagraphEnd();
- content += this.onSection();
- }, this);
+ content += that.onTitleStart(2) + that.onText(entry.name) + that.onTitleEnd(2);
+ content += that.onParagraphStart();
+ content += that.onText(entry.description);
+ content += that.onParagraphEnd();
+ content += that.onSection();
+ });
return content;
};
@@ -119,14 +125,16 @@ ToText.prototype._summaryArticle = function(article, level) {
return content;
};
ToText.prototype._summaryArticles = function(articles, level) {
+ var that = this;
var content = '';
+
level = level || 0;
- content += this.onListStart(level);
+ content += that.onListStart(level);
_.each(articles, function(article) {
- content += this._summaryArticle(article, level);
- }, this);
- content += this.onListEnd(level);
+ content += that._summaryArticle(article, level);
+ });
+ content += that.onListEnd(level);
return content;
};
@@ -141,22 +149,24 @@ ToText.prototype._summaryPart = function(part) {
};
ToText.prototype.summary = function(summary) {
+ var that = this;
var content = '';
- content += this.onTitleStart(1) + this.onText('Summary') + this.onTitleEnd(1);
- content += this.onSection();
+
+ content += that.onTitleStart(1) + that.onText('Summary') + that.onTitleEnd(1);
+ content += that.onSection();
_.each(summary.parts, function(part, i) {
var next = summary.parts[i + 1];
- content += this._summaryPart(part);
+ content += that._summaryPart(part);
if (next && !next.title) {
- content += this.onBL() + this.onHR() + this.onBL();
+ content += that.onBL() + that.onHR() + that.onBL();
} else {
- content += this.onSection();
+ content += that.onSection();
}
- }, this);
+ });
return content;
};