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

Refactor JRS rendering.

This commit is contained in:
hacksalot 2016-01-08 06:48:04 -05:00
parent 28c703daf7
commit fb33455bea

View File

@ -30,15 +30,6 @@ Implementation of the 'generate' verb for HackMyResume.
/**
Handle an exception.
*/
function error( ex ) {
throw ex;
}
/** /**
Given a source resume in FRESH or JRS format, a destination resume path, and a Given a source resume in FRESH or JRS format, a destination resume path, and a
theme file, generate 0..N resumes in the desired formats. theme file, generate 0..N resumes in the desired formats.
@ -153,16 +144,12 @@ Implementation of the 'generate' verb for HackMyResume.
/** /**
Generate a single target resume such as "out/rez.html" or "out/rez.doc". Generate a single target resume such as "out/rez.html" or "out/rez.doc".
TODO: Refactor.
@param targInfo Information for the target resume. @param targInfo Information for the target resume.
@param theme A FRESHTheme or JRSTheme object. @param theme A FRESHTheme or JRSTheme object.
@returns
*/ */
function single( targInfo, theme, finished ) { function single( targInfo, theme, finished ) {
function MDIN(txt) { // TODO: Move this
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
}
try { try {
if( !targInfo.fmt ) { if( !targInfo.fmt ) {
return; return;
@ -218,6 +205,27 @@ Implementation of the 'generate' verb for HackMyResume.
// JSON Resume themes have a 'render' method that needs to be called // JSON Resume themes have a 'render' method that needs to be called
if( theme.render ) { if( theme.render ) {
return renderJRSTheme( f, outFolder, theme );
}
else {
return theFormat.gen.generate( rez, f, _opts );
}
}
}
catch( ex ) {
_err( ex );
}
}
/**
Render a JSON Resume theme. JSON Resume themes have an index.js that needs
to be called to perform the render. Additionally, we need to flow Markdown
styles to the JSON Resume (to the extent possible).
*/
function renderJRSTheme( f, outFolder, theme ) {
var COPY = require('copy'); var COPY = require('copy');
var globs = [ '*.css', '*.js', '*.png', '*.jpg', '*.gif', '*.bmp' ]; var globs = [ '*.css', '*.js', '*.png', '*.jpg', '*.gif', '*.bmp' ];
COPY.sync( globs , outFolder, { COPY.sync( globs , outFolder, {
@ -228,18 +236,18 @@ Implementation of the 'generate' verb for HackMyResume.
// } // }
}); });
// Prevent JSON Resume theme .js from chattering (TODO: redirect IO) // Disable JRS theme chatter (console.log, console.error, etc.)
var consoleLog = console.log; var off = ['log', 'error', 'dir'], org = off.map(function(c){
console.log = function() { }; var ret = console[c]; console[c] = function(){}; return ret;
});
// Call the theme's render method // Freeze and render
var rezDupe = rez.harden(); var rezHtml = theme.render( rez.harden() );
var rezHtml = theme.render( rezDupe );
// Turn logging back on // Turn logging back on
console.log = consoleLog; off.forEach(function(c, idx){ console[c] = org[idx]; });
// Unharden // Unfreeze and apply Markdown
rezHtml = rezHtml.replace( /@@@@~.*?~@@@@/gm, function(val){ rezHtml = rezHtml.replace( /@@@@~.*?~@@@@/gm, function(val){
return MDIN( val.replace( /~@@@@/gm,'' ).replace( /@@@@~/gm,'' ) ); return MDIN( val.replace( /~@@@@/gm,'' ).replace( /@@@@~/gm,'' ) );
}); });
@ -250,15 +258,6 @@ Implementation of the 'generate' verb for HackMyResume.
// Return markup to the client // Return markup to the client
return rezHtml; return rezHtml;
} }
else {
return theFormat.gen.generate( rez, f, _opts );
}
}
}
catch( ex ) {
_err( ex );
}
}
@ -275,7 +274,8 @@ Implementation of the 'generate' verb for HackMyResume.
}; };
}), }),
function(t) { function(t) {
return t.format === 'all' || theme.hasFormat( parsePath( t.format ).extname.substr(1)); return t.format === 'all' ||
theme.hasFormat( parsePath( t.format ).extname.substr(1));
} }
); );
@ -342,6 +342,7 @@ Implementation of the 'generate' verb for HackMyResume.
} }
/** /**
Verify the specified theme name/path. Verify the specified theme name/path.
*/ */
@ -364,7 +365,8 @@ Implementation of the 'generate' verb for HackMyResume.
/** /**
Load the specified theme. Load the specified theme, which could be either a FRESH theme or a JSON Resume
theme.
*/ */
function load_theme( tFolder ) { function load_theme( tFolder ) {
@ -380,6 +382,21 @@ Implementation of the 'generate' verb for HackMyResume.
/**
Handle an exception. Placeholder.
*/
function error( ex ) {
throw ex;
}
function MDIN(txt) { // TODO: Move this
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
}
module.exports = build; module.exports = build;