summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-17 15:07:56 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-17 15:07:56 +0100
commit067bdcda2db081a6df55913b8502a94f1f8251ac (patch)
tree0a80f42960997a72933c670b6b58e15932ab4ae5 /lib
parent3bc1934966bef98c69e6dc6d237364473202461f (diff)
downloadgitbook-067bdcda2db081a6df55913b8502a94f1f8251ac.zip
gitbook-067bdcda2db081a6df55913b8502a94f1f8251ac.tar.gz
gitbook-067bdcda2db081a6df55913b8502a94f1f8251ac.tar.bz2
Add "config" to templating context
Diffstat (limited to 'lib')
-rw-r--r--lib/backbone/summary.js18
-rw-r--r--lib/book.js6
-rw-r--r--lib/config/index.js7
-rw-r--r--lib/output/base.js3
4 files changed, 28 insertions, 6 deletions
diff --git a/lib/backbone/summary.js b/lib/backbone/summary.js
index 5d4d53c..a1caae7 100644
--- a/lib/backbone/summary.js
+++ b/lib/backbone/summary.js
@@ -24,8 +24,12 @@ function TOCArticle(summary, title, ref, articles, parent) {
}
var parts = url.parse(ref);
- this.path = parts.pathname;
- this.anchor = parts.hash;
+ this.ref = ref;
+
+ if (!this.isExternal()) {
+ this.path = parts.pathname;
+ this.anchor = parts.hash;
+ }
this.articles = _.map(articles || [], function(article) {
if (article instanceof TOCArticle) return article;
@@ -45,8 +49,9 @@ TOCArticle.prototype.walk = function(iter) {
TOCArticle.prototype.getContext = function() {
return {
title: this.title,
- path: this.path,
- anchor: this.anchor
+ path: this.isExternal()? undefined : this.path,
+ anchor: this.isExternal()? undefined : this.anchor,
+ url: this.isExternal()? this.ref : undefined
};
};
@@ -55,6 +60,11 @@ TOCArticle.prototype.hasLocation = function() {
return Boolean(this.path);
};
+// Return true if is pointing to an external location
+TOCArticle.prototype.isExternal = function() {
+ return location.isExternal(this.ref);
+};
+
// Return true if has children
TOCArticle.prototype.hasChildren = function() {
return this.articles.length > 0;
diff --git a/lib/book.js b/lib/book.js
index 7928f24..d0e415c 100644
--- a/lib/book.js
+++ b/lib/book.js
@@ -99,7 +99,11 @@ Book.prototype.getContext = function() {
return {
book: _.extend({
title: this.config.get('title'),
- description: this.config.get('description')
+ description: this.config.get('description'),
+ language: this.config.get('language'),
+ isbn: this.config.get('isbn'),
+ author: this.config.get('author'),
+ direction: this.config.get('direction')
}, variables)
};
};
diff --git a/lib/config/index.js b/lib/config/index.js
index ede45ba..a5a0d67 100644
--- a/lib/config/index.js
+++ b/lib/config/index.js
@@ -131,4 +131,11 @@ Config.prototype.dump = function() {
return _.cloneDeep(this.options);
};
+// Return templating context
+Config.prototype.getContext = function() {
+ return {
+ config: this.book.config.dump()
+ };
+};
+
module.exports = Config;
diff --git a/lib/output/base.js b/lib/output/base.js
index ad2d90d..638ee25 100644
--- a/lib/output/base.js
+++ b/lib/output/base.js
@@ -161,7 +161,8 @@ Output.prototype.getPageContext = function(page) {
page.getContext(),
gitbook.getContext(),
this.book.getContext(),
- this.book.summary.getContext()
+ this.book.summary.getContext(),
+ this.book.config.getContext()
);
};