1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-25 18:00:11 +00:00

add: png format

This commit is contained in:
Ya Zhuang 2015-12-29 03:29:13 +08:00
parent dfa19899b0
commit 6b0ea0c7bd
7 changed files with 56 additions and 4 deletions

View File

@ -58,6 +58,7 @@
"recursive-readdir-sync": "^1.0.6",
"simple-html-tokenizer": "^0.2.0",
"underscore": "^1.8.3",
"webshot": "^0.16.0",
"wkhtmltopdf": "^0.1.5",
"xml-escape": "^1.0.0",
"yamljs": "^0.2.4"

View File

@ -10,10 +10,12 @@
{ name: 'txt', ext: 'txt', gen: new FLUENT.TextGenerator() },
{ name: 'doc', ext: 'doc', fmt: 'xml', gen: new FLUENT.WordGenerator() },
{ name: 'pdf', ext: 'pdf', fmt: 'html', is: false, gen: new FLUENT.HtmlPdfGenerator() },
{ name: 'png', ext: 'png', fmt: 'html', is: false, gen: new FLUENT.HtmlPngGenerator() },
{ name: 'md', ext: 'md', fmt: 'txt', gen: new FLUENT.MarkdownGenerator() },
{ name: 'json', ext: 'json', gen: new FLUENT.JsonGenerator() },
{ name: 'yml', ext: 'yml', fmt: 'yml', gen: new FLUENT.JsonYamlGenerator() },
{ name: 'latex', ext: 'tex', fmt: 'latex', gen: new FLUENT.LaTeXGenerator() }
];
}());

View File

@ -102,7 +102,7 @@ Definition of the Theme class.
var portion = pathInfo.dirname.replace(tplFolder,'');
if( portion && portion.trim() ) {
if( portion[1] === '_' ) return;
var reg = /^(?:\/|\\)(html|latex|doc|pdf|partials)(?:\/|\\)?/ig;
var reg = /^(?:\/|\\)(html|latex|doc|pdf|png|partials)(?:\/|\\)?/ig;
var res = reg.exec( portion );
if( res ) {
if( res[1] !== 'partials' ) {

View File

@ -36,7 +36,7 @@ Definition of the HandlebarsGenerator class.
// Compile and run the Handlebars template.
var template = HANDLEBARS.compile(jst);
return template({
r: format === 'html' || format === 'pdf' ? json.markdownify() : json,
r: format === 'html' || format === 'pdf' || format === 'png' ? json.markdownify() : json,
RAW: json,
filt: opts.filters,
cssInfo: cssInfo,

View File

@ -35,7 +35,7 @@ Definition of the UnderscoreGenerator class.
// Compile and run the template. TODO: avoid unnecessary recompiles.
var compiled = _.template(jst);
var ret = compiled({
r: format === 'html' || format === 'pdf' ? json.markdownify() : json,
r: format === 'html' || format === 'pdf' || format === 'png' ? json.markdownify() : json,
filt: opts.filters,
XML: require('xml-escape'),
RAW: json,

View File

@ -0,0 +1,48 @@
/**
Definition of the HtmlPngGenerator class.
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
@module html-png-generator.js
*/
(function() {
var TemplateGenerator = require('./template-generator')
, FS = require('fs-extra')
, HTML = require( 'html' );
/**
An HTML-based PDF resume generator for HackMyResume.
*/
var HtmlPngGenerator = module.exports = TemplateGenerator.extend({
init: function() {
console.log('png generator init');
this._super( 'png', 'html' );
},
/**
Generate the binary PDF.
*/
onBeforeSave: function( info ) {
console.log('png generator onBeforeSave');
png( info.mk, info.outputFile );
return null; // halt further processing
}
});
/**
Generate a PDF from HTML.
*/
function png( markup, fOut ) {
console.log('>> #png()');
console.log(markup);
console.log(fOut);
require('webshot')( markup , { encoding: 'binary', siteType: 'html' } )
.pipe( FS.createWriteStream( fOut ) );
}
}());

View File

@ -18,5 +18,6 @@ module.exports = {
JsonGenerator: require('./gen/json-generator'),
YamlGenerator: require('./gen/yaml-generator'),
JsonYamlGenerator: require('./gen/json-yaml-generator'),
LaTeXGenerator: require('./gen/latex-generator')
LaTeXGenerator: require('./gen/latex-generator'),
HtmlPngGenerator: require('./gen/html-png-generator')
};