summaryrefslogtreecommitdiffstats
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
parent3bc1934966bef98c69e6dc6d237364473202461f (diff)
downloadgitbook-067bdcda2db081a6df55913b8502a94f1f8251ac.zip
gitbook-067bdcda2db081a6df55913b8502a94f1f8251ac.tar.gz
gitbook-067bdcda2db081a6df55913b8502a94f1f8251ac.tar.bz2
Add "config" to templating context
-rw-r--r--docs/variables.md4
-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
5 files changed, 30 insertions, 8 deletions
diff --git a/docs/variables.md b/docs/variables.md
index bf2e88d..fb85463 100644
--- a/docs/variables.md
+++ b/docs/variables.md
@@ -11,13 +11,12 @@ The following is a reference of the available data during book's parsing and the
| `page` | Current page specific information |
| `file` | File associated with the current page specific information |
| `summary` | Information about the table of contents |
+| `config` | Dump of the `book.json` |
### Book Variables
| Variable | Description |
| -------- | ----------- |
-| `book.title` | Title specified in the `book.json` (or detected from the README) |
-| `book.description` | Description specified in the `book.json` (or detected from the README) |
| `book.[CONFIGURATION_DATA]` | All the `variables` set via the `book.json` are available through the book variable. |
### GitBook Variables
@@ -33,6 +32,7 @@ The following is a reference of the available data during book's parsing and the
| -------- | ----------- |
| `file.path` | The path to the raw page |
| `file.mtime` | Modified Time, Time when file data last modified |
+| `file.type` | The name of the parser used to compile this file (ex: `markdown`, `asciidoc`, etc) |
#### Page Variables
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()
);
};