diff options
Diffstat (limited to 'lib/output')
-rw-r--r-- | lib/output/assets-inliner.js | 51 | ||||
-rw-r--r-- | lib/output/base.js | 4 | ||||
-rw-r--r-- | lib/output/folder.js | 6 |
3 files changed, 49 insertions, 12 deletions
diff --git a/lib/output/assets-inliner.js b/lib/output/assets-inliner.js index 65ecbfa..2156bef 100644 --- a/lib/output/assets-inliner.js +++ b/lib/output/assets-inliner.js @@ -3,7 +3,12 @@ var util = require('util'); var path = require('path'); var FolderOutput = require('./folder'); +var Promise = require('../utils/promise'); +var fs = require('../utils/fs'); var imagesUtil = require('../utils/images'); +var location = require('../utils/location'); + +var DEFAULT_ASSETS_FOLDER = 'assets'; /* Utility mixin to inline all the assets in a book: @@ -32,19 +37,45 @@ AssetsInliner.prototype.onOutputSVG = function(page, svg) { }; // Output an image as a file -AssetsInliner.prototype.onOutputImage = function(page, imgFile) { - if (path.extname(imgFile).toLowerCase() != '.svg') { - return imgFile; +AssetsInliner.prototype.onOutputImage = function(page, src) { + var that = this; + var isSVG = false; + var ext = path.extname(src).toLowerCase(); + if (ext == '.svg') { + isSVG = false; + ext = '.png'; } - // Convert SVG to PNG - var filename = _.uniqueId('svg_') + '.png'; - return imagesUtil.convertSVGToPNG(page.resolve(imgFile), this.resolve(filename)) + return Promise() - // Return relative path from the page - .thenResolve(function() { - return page.relative('/' + filename); - }); + // Allocate a new file + .then(function() { + + return that. + }) + + // Download file if external + .then(function() { + if (!location.isExternal(src)) return; + + return fs.download(src, ) + + }) + .then(function() { + if (path.extname(src).toLowerCase() != '.svg') { + return src; + } + + // Convert SVG to PNG + var filename = _.uniqueId('svg_') + '.png'; + return imagesUtil.convertSVGToPNG(page.resolve(src), this.resolve(filename)) + .thenResolve('/' + filename); + }) + + // Return relative path from the page + .thenResolve(function(filename) { + return page.relative('/' + filename); + }); }; diff --git a/lib/output/base.js b/lib/output/base.js index dd62cff..688ecb7 100644 --- a/lib/output/base.js +++ b/lib/output/base.js @@ -106,9 +106,9 @@ Output.prototype.onOutputSVG = function(page, svg) { }; // Output an image as a file +// Normalize the relative link Output.prototype.onOutputImage = function(page, imgFile) { - // Don't replace it - return imgFile; + return page.relative(imgFile); }; // Finish the generation diff --git a/lib/output/folder.js b/lib/output/folder.js index 4b1d9fa..aabdcc4 100644 --- a/lib/output/folder.js +++ b/lib/output/folder.js @@ -74,5 +74,11 @@ FolderOutput.prototype.writeFile = function(filename, buf) { }); }; +// Create a new unique file +// Returns its filename +FolderOutput.prototype.createNewFile = function(base, filename) { + +}; + module.exports = FolderOutput; |