1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-07-04 09:00:06 +01:00

Merge pull request #60 from zhuangya/images

Thanks @zhuangya! Nice work.
This commit is contained in:
hacksalot 2015-12-29 17:21:37 -05:00
commit 417d07f469
7 changed files with 50 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,42 @@
/**
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() {
this._super( 'png', 'html' );
},
/**
Generate the binary PDF.
*/
onBeforeSave: function( info ) {
png( info.mk, info.outputFile );
return null; // halt further processing
}
});
/**
Generate a PDF from HTML.
*/
function png( markup, 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')
};