mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-15 10:07:07 +01:00
Finish HackMyCore reshaping.
Reintroduce HackMyCore, dropping the interim submodule, and reorganize and improve tests.
This commit is contained in:
52
src/generators/html-png-generator.coffee
Normal file
52
src/generators/html-png-generator.coffee
Normal file
@ -0,0 +1,52 @@
|
||||
###*
|
||||
Definition of the HtmlPngGenerator class.
|
||||
@license MIT. See LICENSE.MD for details.
|
||||
@module html-png-generator.js
|
||||
###
|
||||
|
||||
|
||||
|
||||
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.
|
||||
###
|
||||
HtmlPngGenerator = module.exports = TemplateGenerator.extend
|
||||
|
||||
init: -> @_super 'png', 'html'
|
||||
|
||||
invoke: ( rez, themeMarkup, cssInfo, opts ) ->
|
||||
# TODO: Not currently called or callable.
|
||||
|
||||
generate: ( rez, f, opts ) ->
|
||||
htmlResults = opts.targets.filter (t) -> t.fmt.outFormat == 'html'
|
||||
htmlFile = htmlResults[0].final.files.filter (fl) ->
|
||||
fl.info.ext == 'html'
|
||||
phantom htmlFile[0].data, f
|
||||
return
|
||||
|
||||
###*
|
||||
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
|
||||
###
|
||||
|
||||
phantom = ( markup, fOut ) ->
|
||||
|
||||
# Save the markup to a temporary file
|
||||
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 ]);
|
||||
return
|
Reference in New Issue
Block a user