1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-07-02 16:30:04 +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
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".
TODO: Refactor.
@param targInfo Information for the target resume.
@param theme A FRESHTheme or JRSTheme object.
@returns
*/
function single( targInfo, theme, finished ) {
function MDIN(txt) { // TODO: Move this
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
}
try {
if( !targInfo.fmt ) {
return;
@ -218,6 +205,27 @@ Implementation of the 'generate' verb for HackMyResume.
// JSON Resume themes have a 'render' method that needs to be called
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 globs = [ '*.css', '*.js', '*.png', '*.jpg', '*.gif', '*.bmp' ];
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)
var consoleLog = console.log;
console.log = function() { };
// Disable JRS theme chatter (console.log, console.error, etc.)
var off = ['log', 'error', 'dir'], org = off.map(function(c){
var ret = console[c]; console[c] = function(){}; return ret;
});
// Call the theme's render method
var rezDupe = rez.harden();
var rezHtml = theme.render( rezDupe );
// Freeze and render
var rezHtml = theme.render( rez.harden() );
// 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){
return MDIN( val.replace( /~@@@@/gm,'' ).replace( /@@@@~/gm,'' ) );
});
@ -250,15 +258,6 @@ Implementation of the 'generate' verb for HackMyResume.
// Return markup to the client
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) {
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.
*/
@ -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 ) {
@ -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;