Fix test with post in blocks

This commit is contained in:
Samy Pessé
2015-02-13 08:09:28 +01:00
parent 7c83869869
commit b0fd2a67ea
3 changed files with 31 additions and 26 deletions
+3 -3
View File
@@ -93,7 +93,7 @@ TemplateEngine.prototype.processBlock = function(blk) {
});
blk.id = _.uniqueId("blk");
var toAdd = blk.parse || (blk.post != undefined);
var toAdd = (!blk.parse) || (blk.post != undefined);
// Add to global map
if (toAdd) this.blocks[blk.id] = blk;
@@ -368,7 +368,7 @@ TemplateEngine.prototype.postProcess = function(content) {
return Q(content)
.then(that.replaceBlocks)
.then(function(content) {
.then(function(_content) {
return batch.execEach(that.blocks, {
max: 20,
fn: function(blk, blkId) {
@@ -382,7 +382,7 @@ TemplateEngine.prototype.postProcess = function(content) {
});
}
})
.thenResolve(content);
.thenResolve(_content);
});
};
+1
View File
@@ -3,6 +3,7 @@ var _ = require("lodash");
// Execute a method for all element
function execEach(items, options) {
if (_.size(items) == 0) return Q();
var concurrents = 0, d = Q.defer(), pending = [];
options = _.defaults(options || {}, {
+27 -23
View File
@@ -9,6 +9,7 @@ var crc = require("crc");
var links = require('./links');
var imgUtils = require('./images');
var fs = require('./fs');
var batch = require('./batch');
// Render a cheerio dom as html
var renderDom = function($, dom, options) {
@@ -232,33 +233,36 @@ function convertImages(images, options) {
var downloaded = [];
options.book.log.debug.ln("convert ", images.length, "images to png");
return Q.all(_.map(images, function(image) {
var imgin = path.resolve(options.book.options.output, image.source);
return batch.execEach(images, {
max: 100,
fn: function(image) {
var imgin = path.resolve(options.book.options.output, image.source);
return Q()
return Q()
// Write image if need to be download
.then(function() {
if (!image.origin && !_.contains(downloaded, image.origin)) return;
options.book.log.debug("download image", image.origin, "...");
downloaded.push(image.origin);
return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin)));
})
// Write image if need to be download
.then(function() {
if (!image.origin && !_.contains(downloaded, image.origin)) return;
options.book.log.debug("download image", image.origin, "...");
downloaded.push(image.origin);
return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin)));
})
// Write svg if content
.then(function() {
if (!image.content) return;
return fs.writeFile(imgin, image.content);
})
// Write svg if content
.then(function() {
if (!image.content) return;
return fs.writeFile(imgin, image.content);
})
// Convert
.then(function() {
if (!image.dest) return;
var imgout = path.resolve(options.book.options.output, image.dest);
options.book.log.debug("convert image", image.source, "to", image.dest, "...");
return options.book.log.debug.promise(imgUtils.convertSVG(imgin, imgout));
});
}))
// Convert
.then(function() {
if (!image.dest) return;
var imgout = path.resolve(options.book.options.output, image.dest);
options.book.log.debug("convert image", image.source, "to", image.dest, "...");
return options.book.log.debug.promise(imgUtils.convertSVG(imgin, imgout));
});
}
})
.then(function() {
options.book.log.debug.ok(images.length+" images converted with success");
});