mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 11:26:31 +00:00
Add "output" variables for templating
This commit is contained in:
@@ -12,6 +12,7 @@ The following is a reference of the available data during book's parsing and the
|
||||
| `file` | File associated with the current page specific information |
|
||||
| `summary` | Information about the table of contents |
|
||||
| `languages` | List of languages for multi-lingual books |
|
||||
| `output` | Information about the output generator |
|
||||
| `config` | Dump of the `book.json` |
|
||||
|
||||
### Book Variables
|
||||
@@ -62,3 +63,11 @@ The whole table of contents (`SUMMARY.md`) can be accessed:
|
||||
| `languages.list` | List of languages for this book |
|
||||
|
||||
Languages are defined by `{ id: 'en', title: 'English' }`.
|
||||
|
||||
### Output Variables
|
||||
|
||||
| Variable | Description |
|
||||
| -------- | ----------- |
|
||||
| `output.name` | Name of the output generator, possible values are `website`, `json`, `ebook` |
|
||||
| `output.format` | When `output.name == "ebook"`, `format` defines the ebook format that will be generated, possible values are `pdf`, `epub` or `mobi` |
|
||||
|
||||
|
||||
+10
-1
@@ -221,10 +221,19 @@ Output.prototype.onLanguageBook = function(book) {
|
||||
|
||||
// ---- Utilities ----
|
||||
|
||||
// Return conetxt for the output itself
|
||||
Output.prototype.getSelfContext = function() {
|
||||
return {
|
||||
name: this.name
|
||||
};
|
||||
};
|
||||
|
||||
// Return a default context for templates
|
||||
Output.prototype.getContext = function() {
|
||||
return _.extend(
|
||||
{},
|
||||
{
|
||||
output: this.getSelfContext()
|
||||
},
|
||||
this.book.getContext(),
|
||||
this.book.langs.getContext(),
|
||||
this.book.summary.getContext(),
|
||||
|
||||
@@ -21,6 +21,15 @@ var EbookOutput = assetsInliner(_EbookOutput);
|
||||
|
||||
EbookOutput.prototype.name = 'ebook';
|
||||
|
||||
// Return context for templating
|
||||
// Incldue type of ebbook generated
|
||||
EbookOutput.prototype.getSelfContext = function() {
|
||||
var ctx = EbookOutput.super_.prototype.getSelfContext.apply(this);
|
||||
ctx.format = this.opts.format;
|
||||
|
||||
return ctx;
|
||||
};
|
||||
|
||||
// Finish generation, create ebook using ebook-convert
|
||||
EbookOutput.prototype.finish = function() {
|
||||
var that = this;
|
||||
|
||||
Reference in New Issue
Block a user