summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-02-12 20:48:51 +0100
committerSamy Pesse <samypesse@gmail.com>2016-02-12 20:48:51 +0100
commit82f94b010f1d77957c9d1b0967dcdd5eafe73c39 (patch)
treec13607b4bbdf20eb589052dc785edb6e70d6e031 /lib
parent4555c541a8f98cb6ad4cbec2d7bf85b375dbf505 (diff)
downloadgitbook-82f94b010f1d77957c9d1b0967dcdd5eafe73c39.zip
gitbook-82f94b010f1d77957c9d1b0967dcdd5eafe73c39.tar.gz
gitbook-82f94b010f1d77957c9d1b0967dcdd5eafe73c39.tar.bz2
Remove concept of generator, to merge it with Output
Diffstat (limited to 'lib')
-rw-r--r--lib/generators/base.js29
-rw-r--r--lib/generators/website/index.js22
-rw-r--r--lib/output/base.js (renamed from lib/output.js)42
-rw-r--r--lib/output/index.js (renamed from lib/generators/index.js)0
-rw-r--r--lib/output/json.js (renamed from lib/generators/json.js)20
-rw-r--r--lib/output/website/index.js22
-rw-r--r--lib/output/website/theme.js (renamed from lib/generators/website/theme.js)0
-rw-r--r--lib/page/index.js5
-rw-r--r--lib/utils/error.js14
9 files changed, 67 insertions, 87 deletions
diff --git a/lib/generators/base.js b/lib/generators/base.js
deleted file mode 100644
index 0fc0be9..0000000
--- a/lib/generators/base.js
+++ /dev/null
@@ -1,29 +0,0 @@
-
-function Generator(output, type) {
- this.output = output;
- this.book = output.book;
- this.type = type;
-}
-
-// Prepare the generation
-Generator.prototype.prepare = function() {
-
-};
-
-// Copy an asset file (non-parsable), ex: images, etc
-Generator.prototype.writeAsset = function(filename) {
-
-};
-
-// Write a page (parsable file), ex: markdown, etc
-Generator.prototype.writePage = function(page) {
-
-};
-
-// Finish the generation
-Generator.prototype.finish = function() {
-
-};
-
-
-module.exports = Generator;
diff --git a/lib/generators/website/index.js b/lib/generators/website/index.js
deleted file mode 100644
index 67c80b6..0000000
--- a/lib/generators/website/index.js
+++ /dev/null
@@ -1,22 +0,0 @@
-var util = require('util');
-var Generator = require('../base');
-
-function WebsiteGenerator() {
- Generator.apply(this, arguments);
-}
-util.inherits(WebsiteGenerator, Generator);
-
-// Copy an asset file
-WebsiteGenerator.prototype.writeAsset = function(filename) {
- return this.output.copyFile(
- this.book.resolve(filename),
- filename
- );
-};
-
-// Write a page (parsable file)
-WebsiteGenerator.prototype.writePage = function(page) {
-
-};
-
-module.exports = WebsiteGenerator;
diff --git a/lib/output.js b/lib/output/base.js
index 2ada022..8bc27d4 100644
--- a/lib/output.js
+++ b/lib/output/base.js
@@ -2,22 +2,17 @@ var _ = require('lodash');
var Ignore = require('ignore');
var path = require('path');
-var Promise = require('./utils/promise');
-var pathUtil = require('./utils/path');
-var error = require('./utils/error');
-var fs = require('./utils/fs');
-var generators = require('./generators');
-var PluginsManager = require('./plugins');
+var Promise = require('../utils/promise');
+var pathUtil = require('../utils/path');
+var fs = require('../utils/fs');
+var PluginsManager = require('../plugins');
function Output(book, type) {
- if (!generators[type]) throw error.GeneratorNotFoundError({ generator: type });
-
this.book = book;
this.log = this.book.log;
this.type = type;
this.plugins = new PluginsManager(book);
- this.generator = new generators[type](this, type);
// Files to ignore in output
this.ignore = Ignore();
@@ -95,7 +90,7 @@ Output.prototype.generate = function() {
// Initialize the generation
.then(function() {
- return that.generator.prepare();
+ return that.prepare();
})
// Process all files
@@ -109,17 +104,38 @@ Output.prototype.generate = function() {
// Process file as page or asset
if (that.book.hasPage(filename)) {
- return that.generator.writePage(that.book.getPage(filename));
+ return that.writePage(that.book.getPage(filename));
} else {
- return that.generator.writeAsset(filename);
+ return that.copyAsset(filename);
}
});
})
// Finish the generation
.then(function() {
- return that.generator.finish();
+ return that.finish();
});
};
+// Prepare the generation
+Output.prototype.prepare = function() {
+
+};
+
+// Copy an asset file (non-parsable), ex: images, etc
+Output.prototype.copyAsset = function(filename) {
+
+};
+
+// Write a page (parsable file), ex: markdown, etc
+Output.prototype.writePage = function(page) {
+
+};
+
+// Finish the generation
+Output.prototype.finish = function() {
+
+};
+
+
module.exports = Output;
diff --git a/lib/generators/index.js b/lib/output/index.js
index dcb2ffe..dcb2ffe 100644
--- a/lib/generators/index.js
+++ b/lib/output/index.js
diff --git a/lib/generators/json.js b/lib/output/json.js
index 5ba2d16..b03df6e 100644
--- a/lib/generators/json.js
+++ b/lib/output/json.js
@@ -1,14 +1,14 @@
var util = require('util');
-var Generator = require('./base');
+var Output = require('./base');
var gitbook = require('../gitbook');
-function JSONGenerator() {
- Generator.apply(this, arguments);
+function JSONOutput() {
+ Output.apply(this, arguments);
}
-util.inherits(JSONGenerator, Generator);
+util.inherits(JSONOutput, Output);
// Write a page (parsable file)
-JSONGenerator.prototype.writePage = function(page) {
+JSONOutput.prototype.writePage = function(page) {
var that = this;
// Parse the page
@@ -24,7 +24,7 @@ JSONGenerator.prototype.writePage = function(page) {
sections: page.content
};
- return that.output.writeFile(
+ return that.writeFile(
page.withExtension('.json'),
JSON.stringify(json, null, 4)
);
@@ -32,16 +32,16 @@ JSONGenerator.prototype.writePage = function(page) {
};
// At the end of generation, generate README.json for multilingual books
-JSONGenerator.prototype.finish = function() {
+JSONOutput.prototype.finish = function() {
if (!this.book.isMultilingual()) return;
// Copy README.json from main book
var mainLanguage = this.book.langs.getDefault().id;
- return this.output.copyFile(
- this.output.resolve(mainLanguage, 'README.json'),
+ return this.copyFile(
+ this.resolve(mainLanguage, 'README.json'),
'README.json'
);
};
-module.exports = JSONGenerator;
+module.exports = JSONOutput;
diff --git a/lib/output/website/index.js b/lib/output/website/index.js
new file mode 100644
index 0000000..2b7db73
--- /dev/null
+++ b/lib/output/website/index.js
@@ -0,0 +1,22 @@
+var util = require('util');
+var Output = require('../base');
+
+function WebsiteOutput() {
+ Output.apply(this, arguments);
+}
+util.inherits(WebsiteOutput, Output);
+
+// Copy an asset file
+WebsiteOutput.prototype.writeAsset = function(filename) {
+ return this.copyFile(
+ this.book.resolve(filename),
+ filename
+ );
+};
+
+// Write a page (parsable file)
+WebsiteOutput.prototype.writePage = function(page) {
+
+};
+
+module.exports = WebsiteOutput;
diff --git a/lib/generators/website/theme.js b/lib/output/website/theme.js
index 1cc2891..1cc2891 100644
--- a/lib/generators/website/theme.js
+++ b/lib/output/website/theme.js
diff --git a/lib/page/index.js b/lib/page/index.js
index 711e0e1..7074780 100644
--- a/lib/page/index.js
+++ b/lib/page/index.js
@@ -84,7 +84,7 @@ Page.prototype.parse = function(opts) {
var that = this;
opts = _.defaults(opts || {}, {
-
+ linkPages: true
});
@@ -123,9 +123,10 @@ Page.prototype.parse = function(opts) {
// Normalize HTML output
.then(function() {
var pipelineOpts = _.extend({
-
// Replace links to page of summary
onRelativeLink: function(href) {
+ if (!opts.linkPages) return href;
+
var to = that.book.getPage(href);
if (to) return to.outputPath();
diff --git a/lib/utils/error.js b/lib/utils/error.js
index 5ee6a0e..883a7c6 100644
--- a/lib/utils/error.js
+++ b/lib/utils/error.js
@@ -15,18 +15,11 @@ var ParsingError = WrappedError({
message: 'Parsing Error: {origMessage}',
type: 'parse'
});
-var GenerationError = WrappedError({
- message: 'Generation Error: {origMessage}',
+var OutputError = WrappedError({
+ message: 'Output Error: {origMessage}',
type: 'generate'
});
-// Error when output generator does not exists
-var GeneratorNotFoundError = TypedError({
- type: 'generator.not-found',
- message: 'Generator "{generator}" does not exists',
- generator: null
-});
-
// A file does not exists
var FileNotFoundError = TypedError({
type: 'file.not-found',
@@ -54,11 +47,10 @@ module.exports = {
enforce: enforce,
ParsingError: ParsingError,
- GenerationError: GenerationError,
+ OutputError: OutputError,
FileNotFoundError: FileNotFoundError,
FileOutOfScopeError: FileOutOfScopeError,
- GeneratorNotFoundError: GeneratorNotFoundError,
TemplateError: TemplateError
};