summaryrefslogtreecommitdiffstats
path: root/lib/output/base.js
diff options
context:
space:
mode:
authorSamy Pesse <samypesse@gmail.com>2016-02-12 21:25:43 +0100
committerSamy Pesse <samypesse@gmail.com>2016-02-12 21:25:43 +0100
commit0d966fe19738089607de3927694ac5f2bd41f03f (patch)
tree92d4d3711459249e48dfc708870afff42367a3fc /lib/output/base.js
parent82f94b010f1d77957c9d1b0967dcdd5eafe73c39 (diff)
downloadgitbook-0d966fe19738089607de3927694ac5f2bd41f03f.zip
gitbook-0d966fe19738089607de3927694ac5f2bd41f03f.tar.gz
gitbook-0d966fe19738089607de3927694ac5f2bd41f03f.tar.bz2
Separate output in FolderOutput and base
Diffstat (limited to 'lib/output/base.js')
-rw-r--r--lib/output/base.js76
1 files changed, 22 insertions, 54 deletions
diff --git a/lib/output/base.js b/lib/output/base.js
index 8bc27d4..39e46c2 100644
--- a/lib/output/base.js
+++ b/lib/output/base.js
@@ -1,13 +1,19 @@
var _ = require('lodash');
var Ignore = require('ignore');
-var path = require('path');
var Promise = require('../utils/promise');
-var pathUtil = require('../utils/path');
-var fs = require('../utils/fs');
var PluginsManager = require('../plugins');
+/*
+Output is like a stream interface for a parsed book
+to output "something".
+
+The process is mostly on the behavior of "onPage" and "onAsset"
+*/
+
function Output(book, type) {
+ _.bindAll(this);
+
this.book = book;
this.log = this.book.log;
@@ -26,47 +32,6 @@ function Output(book, type) {
]));
}
-// Return path to the root folder
-Output.prototype.root = function(filename) {
- return path.resolve(process.cwd(), this.book.config.get('output'));
-};
-
-// Resolve a file in the output directory
-Output.prototype.resolve = function(filename) {
- return pathUtil.resolveInRoot.apply(null, [this.root()].concat(_.toArray(arguments)));
-};
-
-// Write a file/buffer to the output folder
-Output.prototype.writeFile = function(filename, buf) {
- var that = this;
-
- return Promise()
- .then(function() {
- filename = that.resolve(filename);
- var folder = path.dirname(filename);
-
- // Ensure fodler exists
- return fs.mkdirp(folder);
- })
-
- // Write the file
- .then(function() {
- return fs.writeFile(filename, buf);
- });
-};
-
-// Copy a file to the output
-Output.prototype.copyFile = function(from, to) {
- var that = this;
-
- return Promise()
- .then(function() {
- to = that.resolve(to);
-
- return fs.copy(from, to);
- });
-};
-
// Start the generation, for a parsed book
Output.prototype.generate = function() {
var that = this;
@@ -83,11 +48,6 @@ Output.prototype.generate = function() {
return that.plugins.load(plugins);
})
- // Create the output folder
- .then(function() {
- return fs.mkdirp(that.root());
- })
-
// Initialize the generation
.then(function() {
return that.prepare();
@@ -104,9 +64,9 @@ Output.prototype.generate = function() {
// Process file as page or asset
if (that.book.hasPage(filename)) {
- return that.writePage(that.book.getPage(filename));
+ return that.onPage(that.book.getPage(filename));
} else {
- return that.copyAsset(filename);
+ return that.onAsset(filename);
}
});
})
@@ -122,14 +82,22 @@ Output.prototype.prepare = function() {
};
+// Write a page (parsable file), ex: markdown, etc
+Output.prototype.onPage = function(page) {
+
+};
+
// Copy an asset file (non-parsable), ex: images, etc
-Output.prototype.copyAsset = function(filename) {
+Output.prototype.onAsset = function(filename) {
};
-// Write a page (parsable file), ex: markdown, etc
-Output.prototype.writePage = function(page) {
+// Resolve an HTML link
+Output.prototype.onRelativeLink = function(currentPage, href) {
+ var to = this.book.getPage(href);
+ if (to) return to.outputPath();
+ return href;
};
// Finish the generation