mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 00:10:15 +00:00
Emit correct CSS filename in generated HTML.
Instead of hard-coding the CSS file to "resume.css", base it on the input file name.
This commit is contained in:
parent
0b4522c149
commit
ce740922e9
@ -69,28 +69,36 @@ module.exports = function () {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Generate a single resume of a specific format.
|
Generate a single resume of a specific format.
|
||||||
|
@param f Full path to the destination resume to generate, for example,
|
||||||
|
"/foo/bar/resume.pdf" or "c:\foo\bar\resume.txt".
|
||||||
*/
|
*/
|
||||||
function gen( f ) {
|
function gen( f ) {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
// Load the theme template
|
// Get the output file type (pdf, html, txt, etc)
|
||||||
var fName = f.substring( f.lastIndexOf('.') + 1 );
|
var fType = path.extname( f ).trim().toLowerCase().substr(1);
|
||||||
var fObj = _fmts.filter( function(_f) { return _f.name === fName; } )[0];
|
var fName = path.basename( f, '.' + fType );
|
||||||
|
|
||||||
|
// Get the format object (if any) corresponding to that type, and assemble
|
||||||
|
// thefinal output file path for the generated resume.
|
||||||
|
var fObj = _fmts.filter( function(_f) { return _f.name === fType; } )[0];
|
||||||
var fOut = path.join( f.substring( 0, f.lastIndexOf('.') + 1 ) + fObj.ext );
|
var fOut = path.join( f.substring( 0, f.lastIndexOf('.') + 1 ) + fObj.ext );
|
||||||
console.log( 'Generating ' + fName.toUpperCase() + ' resume: ' + fOut );
|
console.log( 'Generating ' + fType.toUpperCase() + ' resume: ' + fOut );
|
||||||
|
|
||||||
|
// Load the active theme file, including CSS data if req'd
|
||||||
var themeFile = path.join( __dirname, '../../watermark/', _opts.theme,
|
var themeFile = path.join( __dirname, '../../watermark/', _opts.theme,
|
||||||
fName + '.' + (fObj.fmt || fObj.ext));
|
fType + '.' + (fObj.fmt || fObj.ext));
|
||||||
var cssData = (fName !== 'html' && fName !== 'pdf') ? null :
|
var cssData = (fType !== 'html' && fType !== 'pdf') ? null :
|
||||||
FS.readFileSync( path.join( __dirname, '../../watermark/', _opts.theme, 'html.css' ), 'utf8' );
|
FS.readFileSync( path.join( __dirname, '../../watermark/', _opts.theme, 'html.css' ), 'utf8' );
|
||||||
var mk = FS.readFileSync( themeFile, 'utf8' );
|
var mk = FS.readFileSync( themeFile, 'utf8' );
|
||||||
|
|
||||||
// Compile and invoke the template
|
// Compile and invoke the template!
|
||||||
mk = single( rez.rep, mk, fName, cssData );
|
mk = single( rez.rep, mk, fType, cssData, fName );
|
||||||
|
|
||||||
// Post-process and save the file
|
// Post-process and save the file
|
||||||
fName === 'html' && (mk = html( mk, themeFile, fOut ));
|
fType === 'html' && (mk = html( mk, themeFile, fOut ));
|
||||||
fName === 'pdf' && pdf( mk, fOut );
|
fType === 'pdf' && pdf( mk, fOut );
|
||||||
fName !== 'pdf' && FS.writeFileSync( fOut, mk, 'utf8' );
|
fType !== 'pdf' && FS.writeFileSync( fOut, mk, 'utf8' );
|
||||||
|
|
||||||
return mk;
|
return mk;
|
||||||
}
|
}
|
||||||
@ -104,7 +112,7 @@ module.exports = function () {
|
|||||||
separate function in order to expose string-based transformations to clients
|
separate function in order to expose string-based transformations to clients
|
||||||
who don't have access to filesystem resources (in-browser, etc.).
|
who don't have access to filesystem resources (in-browser, etc.).
|
||||||
*/
|
*/
|
||||||
function single( json, jst, format, styles ) {
|
function single( json, jst, format, styles, fName ) {
|
||||||
|
|
||||||
// Freeze whitespace in the template
|
// Freeze whitespace in the template
|
||||||
_opts.keepBreaks && ( jst = freeze(jst) );
|
_opts.keepBreaks && ( jst = freeze(jst) );
|
||||||
@ -129,7 +137,7 @@ module.exports = function () {
|
|||||||
json.display_progress_bar = true;
|
json.display_progress_bar = true;
|
||||||
|
|
||||||
// Compile and run the template. TODO: avoid unnecessary recompiles.
|
// Compile and run the template. TODO: avoid unnecessary recompiles.
|
||||||
jst = _.template( jst )({ r: json, css: styles, embedCss: false, filt: _opts.filters });
|
jst = _.template( jst )({ r: json, css: styles, embedCss: false, cssFile: fName, filt: _opts.filters });
|
||||||
|
|
||||||
// Unfreeze whitespace
|
// Unfreeze whitespace
|
||||||
_opts.keepBreaks && ( jst = unfreeze(jst) );
|
_opts.keepBreaks && ( jst = unfreeze(jst) );
|
||||||
|
Loading…
Reference in New Issue
Block a user