summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--docs/SUMMARY.md3
-rw-r--r--docs/variables.md43
-rw-r--r--lib/page/index.js21
-rw-r--r--lib/template/blocks.js2
4 files changed, 62 insertions, 7 deletions
diff --git a/docs/SUMMARY.md b/docs/SUMMARY.md
index d899073..2816186 100644
--- a/docs/SUMMARY.md
+++ b/docs/SUMMARY.md
@@ -2,3 +2,6 @@
* [About this document](README.md)
* [Content References](conrefs.md)
+* [Variables](variables.md)
+ * [Filters](filters.md)
+
diff --git a/docs/variables.md b/docs/variables.md
new file mode 100644
index 0000000..35c7dd7
--- /dev/null
+++ b/docs/variables.md
@@ -0,0 +1,43 @@
+# Variables
+
+The following is a reference of the available data during book's parsing and theme generation.
+
+### Global Variables
+
+| Variable | Description |
+| -------- | ----------- |
+| `book` | Bookwide information + configuration settings from `book.json`. See below for details. |
+| `gitbook` | GitBook specific information |
+| `page` | Current page specific information |
+| `file` | File associated with the current page specific information |
+
+### Book Variables
+
+| Variable | Description |
+| -------- | ----------- |
+| `book.[CONFIGURATION_DATA]` | All the `variables` set via the `book.json` are available through the book variable. |
+
+### GitBook Variables
+
+| Variable | Description |
+| -------- | ----------- |
+| `gitbook.version` | Version of GitBook used to generate the book |
+
+### File Variables
+
+| Variable | Description |
+| -------- | ----------- |
+| `file.path` | The path to the raw page |
+| `file.mtime` | Modified Time, Time when file data last modified |
+
+#### Page Variables
+
+| Variable | Description |
+| -------- | ----------- |
+| `page.title` | Title of the page |
+| `page.previous` | Previous page in the Table of Contents (can be `null`) |
+| `page.next` | Next page in the Table of Contents (can be `null`) |
+
+
+
+
diff --git a/lib/page/index.js b/lib/page/index.js
index 2a4553f..d057441 100644
--- a/lib/page/index.js
+++ b/lib/page/index.js
@@ -103,6 +103,20 @@ Page.prototype.read = function() {
.then(this.update);
};
+// Return templating context for this page
+// This is used both for themes and page parsing
+Page.prototype.getContext = function() {
+ return {
+ file: {
+ path: this.path,
+ mtime: this.mtime
+ },
+ page: {
+ // todo
+ }
+ };
+};
+
// Parse the page and return its content
Page.prototype.parse = function(output) {
var that = this;
@@ -119,12 +133,7 @@ Page.prototype.parse = function(output) {
// Render template
.then(function() {
- return that.book.template.renderString(that.content, {
- file: {
- path: that.path,
- mtime: that.mtime
- }
- }, {
+ return that.book.template.renderString(that.content, that.getContext(), {
file: that.path
})
.then(that.update);
diff --git a/lib/template/blocks.js b/lib/template/blocks.js
index 92097a7..0e04643 100644
--- a/lib/template/blocks.js
+++ b/lib/template/blocks.js
@@ -6,6 +6,6 @@ module.exports = {
html: _.identity,
// Highlight a code block
- // This block can be extent by plugins
+ // This block can be replaced by plugins
code: _.identity
};