mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 08:20:11 +00:00
Adjust CSS file handling by generators.
This commit is contained in:
parent
537bd4a7b9
commit
aa0ef4e8a4
@ -1,11 +1,14 @@
|
|||||||
/**
|
/**
|
||||||
HTML resume generator for FluentCV.
|
HTML resume generator for FluentCV.
|
||||||
@license Copyright (c) 2015 by James M. Devlin. All rights reserved.
|
@license Copyright (c) 2015 James M. Devlin / FluentDesk
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var TemplateGenerator = require('./template-generator');
|
(function() {
|
||||||
var FS = require('fs-extra');
|
|
||||||
var HTML = require( 'html' );
|
var TemplateGenerator = require('./template-generator')
|
||||||
|
, FS = require('fs-extra')
|
||||||
|
, HTML = require( 'html' )
|
||||||
|
, PATH = require('path');
|
||||||
|
|
||||||
var HtmlGenerator = module.exports = TemplateGenerator.extend({
|
var HtmlGenerator = module.exports = TemplateGenerator.extend({
|
||||||
|
|
||||||
@ -14,19 +17,24 @@ var HtmlGenerator = module.exports = TemplateGenerator.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Generate an HTML resume with optional pretty printing.
|
Copy satellite CSS files to the destination and optionally pretty-print
|
||||||
|
the HTML resume prior to saving.
|
||||||
*/
|
*/
|
||||||
onBeforeSave: function( mk, theme, outputFile ) {
|
onBeforeSave: function( info ) {
|
||||||
var themeFile = theme.getFormat('html').path;
|
var cssSrc = PATH.join( info.theme.folder, 'templates', '*.css' )
|
||||||
var cssSrc = themeFile.replace( /.html$/g, '.css' );
|
, outFolder = PATH.parse( info.outputFile ).dir, that = this;
|
||||||
var cssDst = outputFile.replace( /.html$/g, '.css' );
|
|
||||||
var that = this;
|
info.theme.cssFiles.forEach( function( f ) {
|
||||||
FS.copySync( cssSrc, cssDst, { clobber: true }, function( e ) {
|
var fi = PATH.parse( f[1].path );
|
||||||
|
FS.copySync( f[1].path, PATH.join( outFolder, fi.base ), { clobber: true }, function( e ) {
|
||||||
throw { fluenterror: that.codes.copyCss, data: [cssSrc,cssDst] };
|
throw { fluenterror: that.codes.copyCss, data: [cssSrc,cssDst] };
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return this.opts.prettify ?
|
return this.opts.prettify ?
|
||||||
HTML.prettyPrint( mk, this.opts.prettify ) : mk;
|
HTML.prettyPrint( info.mk, this.opts.prettify ) : info.mk;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
}());
|
||||||
|
@ -1,12 +1,17 @@
|
|||||||
/**
|
/**
|
||||||
HTML-based PDF resume generator for FluentCV.
|
Definition of the HtmlPdfGenerator class.
|
||||||
@license Copyright (c) 2015 by James M. Devlin. All rights reserved.
|
@license Copyright (c) 2015 James M. Devlin / FluentDesk
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var TemplateGenerator = require('./template-generator');
|
(function() {
|
||||||
var FS = require('fs-extra');
|
|
||||||
var HTML = require( 'html' );
|
|
||||||
|
|
||||||
|
var TemplateGenerator = require('./template-generator')
|
||||||
|
, FS = require('fs-extra')
|
||||||
|
, HTML = require( 'html' );
|
||||||
|
|
||||||
|
/**
|
||||||
|
An HTML-based PDF resume generator for FluentCV.
|
||||||
|
*/
|
||||||
var HtmlPdfGenerator = module.exports = TemplateGenerator.extend({
|
var HtmlPdfGenerator = module.exports = TemplateGenerator.extend({
|
||||||
|
|
||||||
init: function() {
|
init: function() {
|
||||||
@ -14,20 +19,10 @@ var HtmlPdfGenerator = module.exports = TemplateGenerator.extend({
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Generate an HTML resume with optional pretty printing.
|
Generate the binary PDF.
|
||||||
TODO: Avoid copying the CSS file to dest if we don't need to.
|
|
||||||
*/
|
*/
|
||||||
onBeforeSave: function( mk, themeFile, outputFile ) {
|
onBeforeSave: function( info ) {
|
||||||
// var cssSrc = themeFile.replace( /pdf\.html$/gi, 'html.css' );
|
pdf(info.mk, info.outputFile);
|
||||||
// var cssDst = outputFile.replace( /\.pdf$/gi, '.css' );
|
|
||||||
// var that = this;
|
|
||||||
// FS.copySync( cssSrc, cssDst, { clobber: true }, function( e ) {
|
|
||||||
// if( e ) that.err( "Couldn't copy CSS file to destination: " + e);
|
|
||||||
// });
|
|
||||||
// return true ?
|
|
||||||
// HTML.prettyPrint( mk, { indent_size: 2 } ) : mk;
|
|
||||||
|
|
||||||
pdf(mk, outputFile);
|
|
||||||
return mk;
|
return mk;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,3 +67,5 @@ function pdf( markup, fOut ) {
|
|||||||
pdfCount++;
|
pdfCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}());
|
||||||
|
@ -89,11 +89,11 @@ var TemplateGenerator = module.exports = BaseGenerator.extend({
|
|||||||
// Load theme and CSS data
|
// Load theme and CSS data
|
||||||
var tplFolder = PATH.join( tFolder, 'templates' );
|
var tplFolder = PATH.join( tFolder, 'templates' );
|
||||||
var curFmt = theme.getFormat( this.format );
|
var curFmt = theme.getFormat( this.format );
|
||||||
var ctx = { file: curFmt.css ? curFmt.cssPath : null, data: curFmt.css || null };
|
var cssInfo = { file: curFmt.css ? curFmt.cssPath : null, data: curFmt.css || null };
|
||||||
|
|
||||||
// Compile and invoke the template!
|
// Compile and invoke the template!
|
||||||
var mk = this.single( rez, curFmt.data, this.format, ctx, opts );
|
var mk = this.single( rez, curFmt.data, this.format, cssInfo, opts );
|
||||||
this.onBeforeSave && (mk = this.onBeforeSave( mk, theme, f ));
|
this.onBeforeSave && (mk = this.onBeforeSave( { mk: mk, theme: theme, outputFile: f } ));
|
||||||
FS.writeFileSync( f, mk, { encoding: 'utf8', flags: 'w' } );
|
FS.writeFileSync( f, mk, { encoding: 'utf8', flags: 'w' } );
|
||||||
|
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user