1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +00:00
HackMyResume/dist/generators/html-png-generator.js

66 lines
1.9 KiB
JavaScript
Raw Normal View History

2016-01-27 10:29:26 +00:00
(function() {
2018-02-12 05:05:29 +00:00
/**
Definition of the HtmlPngGenerator class.
@module generators/html-png-generator
@license MIT. See LICENSE.MD for details.
*/
/**
Generate a PDF from HTML using Phantom's CLI interface.
Spawns a child process with `phantomjs <script> <source> <target>`. Phantom
must be installed and path-accessible.
TODO: If HTML generation has run, reuse that output
TODO: Local web server to ease Phantom rendering
*/
var FS, HTML, HtmlPngGenerator, PATH, SLASH, SPAWN, TemplateGenerator, phantom;
2016-01-27 10:29:26 +00:00
TemplateGenerator = require('./template-generator');
FS = require('fs-extra');
HTML = require('html');
SLASH = require('slash');
SPAWN = require('../utils/safe-spawn');
PATH = require('path');
/**
An HTML-based PNG resume generator for HackMyResume.
2018-02-12 05:05:29 +00:00
*/
module.exports = HtmlPngGenerator = class HtmlPngGenerator extends TemplateGenerator {
constructor() {
super('png', 'html');
}
2018-02-12 05:05:29 +00:00
invoke(rez, themeMarkup, cssInfo, opts) {}
2018-02-12 05:05:29 +00:00
// TODO: Not currently called or callable.
generate(rez, f, opts) {
2016-01-27 10:29:26 +00:00
var htmlFile, htmlResults;
htmlResults = opts.targets.filter(function(t) {
return t.fmt.outFormat === 'html';
});
htmlFile = htmlResults[0].final.files.filter(function(fl) {
return fl.info.ext === 'html';
});
phantom(htmlFile[0].data, f);
2018-02-12 05:05:29 +00:00
}
2016-01-27 10:29:26 +00:00
2018-02-12 05:05:29 +00:00
};
2016-01-27 10:29:26 +00:00
phantom = function(markup, fOut) {
var destPath, info, scriptPath, sourcePath, tempFile;
2018-02-12 05:05:29 +00:00
// Save the markup to a temporary file
2016-01-27 10:29:26 +00:00
tempFile = fOut.replace(/\.png$/i, '.png.html');
FS.writeFileSync(tempFile, markup, 'utf8');
scriptPath = SLASH(PATH.relative(process.cwd(), PATH.resolve(__dirname, '../utils/rasterize.js')));
sourcePath = SLASH(PATH.relative(process.cwd(), tempFile));
destPath = SLASH(PATH.relative(process.cwd(), fOut));
info = SPAWN('phantomjs', [scriptPath, sourcePath, destPath]);
};
}).call(this);
2016-02-02 02:14:36 +00:00
//# sourceMappingURL=html-png-generator.js.map