summaryrefslogtreecommitdiffstats
path: root/lib/output/assets-inliner.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/output/assets-inliner.js')
-rw-r--r--lib/output/assets-inliner.js51
1 files changed, 41 insertions, 10 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);
+ });
};