diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-03-09 15:50:38 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-03-09 15:50:38 +0100 |
commit | c499a8a13a3059e3953727866beb7c986e46dd78 (patch) | |
tree | 173ee93cb957446855d8519335ad5dba0f7cc332 /lib | |
parent | 64a6de751d0f2bd8910ce36e2e8aa4049316e2c7 (diff) | |
download | gitbook-c499a8a13a3059e3953727866beb7c986e46dd78.zip gitbook-c499a8a13a3059e3953727866beb7c986e46dd78.tar.gz gitbook-c499a8a13a3059e3953727866beb7c986e46dd78.tar.bz2 |
Add back gitbook.generator property as deprecated
Diffstat (limited to 'lib')
-rw-r--r-- | lib/output/base.js | 15 | ||||
-rw-r--r-- | lib/output/json.js | 3 | ||||
-rw-r--r-- | lib/output/website.js | 2 | ||||
-rw-r--r-- | lib/page/index.js | 45 |
4 files changed, 37 insertions, 28 deletions
diff --git a/lib/output/base.js b/lib/output/base.js index 201eade..d513d71 100644 --- a/lib/output/base.js +++ b/lib/output/base.js @@ -5,8 +5,10 @@ var path = require('path'); var Promise = require('../utils/promise'); var pathUtil = require('../utils/path'); var location = require('../utils/location'); +var error = require('../utils/error'); var PluginsManager = require('../plugins'); var TemplateEngine = require('../template'); +var gitbook = require('../gitbook'); /* Output is like a stream interface for a parsed book @@ -37,6 +39,9 @@ function Output(book, opts, parent) { this.ignore = Ignore(); } +// Default name for generator +Output.prototype.name = 'base'; + // Default extension for output Output.prototype.defaultExtension = '.html'; @@ -230,7 +235,7 @@ Output.prototype.getSelfContext = function() { // Return a default context for templates Output.prototype.getContext = function() { - return _.extend( + var ctx = _.extend( { output: this.getSelfContext() }, @@ -238,8 +243,14 @@ Output.prototype.getContext = function() { this.book.langs.getContext(), this.book.summary.getContext(), this.book.glossary.getContext(), - this.book.config.getContext() + this.book.config.getContext(), + gitbook.getContext() ); + + // Deprecated fields + error.deprecateField(ctx.gitbook, 'generator', this.name, '"gitbook.generator" property is deprecated, use "output.name" instead'); + + return ctx; }; // Resolve a file path in the context of a specific page diff --git a/lib/output/json.js b/lib/output/json.js index 3246407..b66e593 100644 --- a/lib/output/json.js +++ b/lib/output/json.js @@ -1,3 +1,4 @@ +var _ = require('lodash'); var conrefsLoader = require('./conrefs'); var JSONOutput = conrefsLoader(); @@ -16,7 +17,7 @@ JSONOutput.prototype.onPage = function(page) { // Write as json .then(function() { - var json = page.getContext(); + var json = page.getOutputContext(that); // Delete some private properties delete json.config; diff --git a/lib/output/website.js b/lib/output/website.js index ae3d7af..e298b69 100644 --- a/lib/output/website.js +++ b/lib/output/website.js @@ -190,7 +190,7 @@ WebsiteOutput.prototype.onPage = function(page) { // Render the page template with the same context as the json output .then(function() { - return that.render('page', page.getContext()); + return that.render('page', page.getOutputContext(that)); }) // Write the HTML file diff --git a/lib/page/index.js b/lib/page/index.js index 6c63489..0377f35 100644 --- a/lib/page/index.js +++ b/lib/page/index.js @@ -116,30 +116,27 @@ Page.prototype.getContext = function() { if (dir == 'neutral') dir = null; } - return _.extend( - { - file: { - path: this.path, - mtime: this.mtime, - type: this.type - }, - page: _.extend({}, this.attributes, { - title: article? article.title : null, - next: next? next.getContext() : null, - previous: prev? prev.getContext() : null, - level: article? article.level : null, - depth: article? article.depth : 0, - content: this.content, - dir: dir - }) + return { + file: { + path: this.path, + mtime: this.mtime, + type: this.type }, - gitbook.getContext(), - this.book.getContext(), - this.book.langs.getContext(), - this.book.summary.getContext(), - this.book.glossary.getContext(), - this.book.config.getContext() - ); + page: _.extend({}, this.attributes, { + title: article? article.title : null, + next: next? next.getContext() : null, + previous: prev? prev.getContext() : null, + level: article? article.level : null, + depth: article? article.depth() : 0, + content: this.content, + dir: dir + }) + }; +}; + +// Return complete context for templating (page + book + summary + ...) +Page.prototype.getOutputContext = function(output) { + return _.extend({}, this.getContext(), output.getContext()); }; // Parse the page and return its content @@ -184,7 +181,7 @@ Page.prototype.toHTML = function(output) { // Render template .then(function() { - return output.template.render(that.content, that.getContext(), { + return output.template.render(that.content, that.getOutputContext(output), { path: that.path }) .then(that.update); |