summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2016-02-14 11:10:08 +0100
committerSamy Pessé <samypesse@gmail.com>2016-02-14 11:10:08 +0100
commita65f888a77c48968087d23750e5fa4d55f2a8686 (patch)
treeb88e7e5b0e98ae791726586592716cd602355abf
parent71059e3ea3ea9af156987a0dd4cb0a5457b0316c (diff)
downloadgitbook-a65f888a77c48968087d23750e5fa4d55f2a8686.zip
gitbook-a65f888a77c48968087d23750e5fa4d55f2a8686.tar.gz
gitbook-a65f888a77c48968087d23750e5fa4d55f2a8686.tar.bz2
Start moving template and conrefs on Output
-rw-r--r--lib/output/base.js13
-rw-r--r--lib/output/conrefs.js22
-rw-r--r--lib/output/website/index.js2
-rw-r--r--lib/template/index.js7
-rw-r--r--lib/utils/fs.js7
-rw-r--r--lib/utils/git.js17
-rw-r--r--test/all.js1
-rw-r--r--test/website-theme.js17
8 files changed, 79 insertions, 7 deletions
diff --git a/lib/output/base.js b/lib/output/base.js
index 853fa30..8142761 100644
--- a/lib/output/base.js
+++ b/lib/output/base.js
@@ -3,6 +3,7 @@ var Ignore = require('ignore');
var Promise = require('../utils/promise');
var PluginsManager = require('../plugins');
+var TemplateEngine = require('../template');
/*
Output is like a stream interface for a parsed book
@@ -11,15 +12,18 @@ to output "something".
The process is mostly on the behavior of "onPage" and "onAsset"
*/
-function Output(book, type) {
+function Output(book) {
_.bindAll(this);
this.book = book;
this.log = this.book.log;
- this.type = type;
+ // Create plugins manager
this.plugins = new PluginsManager(book);
+ // Create template engine
+ this.template = new TemplateEngine(this);
+
// Files to ignore in output
this.ignore = Ignore();
this.ignore.addPattern(_.compact([
@@ -130,6 +134,11 @@ Output.prototype.onOutputImage = function(page, imgFile) {
return page.relative(imgFile);
};
+// By default don;t resolve conrefs
+Output.prototype.onResolveTemplate = function(from, to) {
+
+};
+
// Finish the generation
Output.prototype.finish = function() {
diff --git a/lib/output/conrefs.js b/lib/output/conrefs.js
new file mode 100644
index 0000000..2883c7b
--- /dev/null
+++ b/lib/output/conrefs.js
@@ -0,0 +1,22 @@
+var util = require('util');
+
+var Output = require('./base');
+var Git = require('../utils/git');
+var pathUtil = require('../utils/path');
+
+/*
+Middleware for output to resolve git conrefs
+*/
+
+function ConrefsLoader() {
+ Output.apply(this, arguments);
+ this.git = new Git();
+}
+util.inherits(ConrefsLoader, Output);
+
+// Resolve an include in the template engine
+ConrefsLoader.prototype.onResolveTemplate = function(from, to) {
+
+};
+
+module.exports = ConrefsLoader;
diff --git a/lib/output/website/index.js b/lib/output/website/index.js
index e60dae2..a35cafe 100644
--- a/lib/output/website/index.js
+++ b/lib/output/website/index.js
@@ -1,6 +1,8 @@
var util = require('util');
var FolderOutput = require('../base');
+var Theme = require('./theme');
+
function WebsiteOutput() {
FolderOutput.apply(this, arguments);
}
diff --git a/lib/template/index.js b/lib/template/index.js
index b59dd04..3f74267 100644
--- a/lib/template/index.js
+++ b/lib/template/index.js
@@ -21,9 +21,10 @@ function normBlockResult(blk) {
return blk;
}
-function TemplateEngine(book) {
- this.book = book;
- this.log = book.log;
+function TemplateEngine(output) {
+ this.output = output;
+ this.book = output.book;
+ this.log = this.book.log;
// Create file loader
this.loader = new Loader(this);
diff --git a/lib/utils/fs.js b/lib/utils/fs.js
index c0ff0c9..840d1f9 100644
--- a/lib/utils/fs.js
+++ b/lib/utils/fs.js
@@ -61,6 +61,12 @@ function genTmpFile(opts) {
.get(0);
}
+// Generate temporary dir
+function genTmpDir(opts) {
+ return Promise.nfcall(tmp.dir, opts)
+ .get(0);
+}
+
// Download an image
function download(uri, dest) {
return writeStream(dest, request(uri));
@@ -101,6 +107,7 @@ module.exports = {
writeStream: writeStream,
copy: copyFile,
tmpFile: genTmpFile,
+ tmpDir: genTmpDir,
download: download,
uniqueFilename: uniqueFilename,
ensure: ensureFile
diff --git a/lib/utils/git.js b/lib/utils/git.js
index baf0fab..fc75ee3 100644
--- a/lib/utils/git.js
+++ b/lib/utils/git.js
@@ -6,11 +6,12 @@ var URI = require('urijs');
var pathUtil = require('./path');
var Promise = require('./promise');
var command = require('./command');
+var fs = require('./fs');
var GIT_PREFIX = 'git+';
function Git(tmpDir) {
- this.tmpDir = tmpDir;
+ this.tmpDir;
this.cloned = {};
}
@@ -19,11 +20,23 @@ Git.prototype.repoID = function(host, ref) {
return crc.crc32(host+'#'+(ref || '')).toString(16);
};
+// Allocate a temporary folder for cloning repos in it
+Git.prototype.allocateDir = function() {
+ var that = this;
+
+ if (this.tmpDir) return Promise();
+
+ return fs.tmpDir()
+ .then(function(dir) {
+ that.tmpDir = dir;
+ });
+};
+
// Clone a git repository if non existant
Git.prototype.clone = function(host, ref) {
var that = this;
- return Promise()
+ return this.allocateDir()
// Return or clone the git repo
.then(function() {
diff --git a/test/all.js b/test/all.js
index 242324b..35957b4 100644
--- a/test/all.js
+++ b/test/all.js
@@ -14,3 +14,4 @@ require('./template');
// Output
require('./output-json');
require('./assets-inliner');
+require('./website-theme');
diff --git a/test/website-theme.js b/test/website-theme.js
new file mode 100644
index 0000000..afbae5e
--- /dev/null
+++ b/test/website-theme.js
@@ -0,0 +1,17 @@
+
+
+describe('Website Theming', function() {
+
+// Spec proposal:
+// - Plugins can "export" a theme
+// - Theme can be overrided in the book itself
+
+
+// Themes structures
+// - _layout/ (Folder containing all the templates)
+// - page.html (Template used for generating a page)
+// - _assets/ (Assets of the theme copied to the output)
+
+
+});
+