mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-15 10:07:07 +01:00
Add baseline support for local generation of JSON Resume themes.
This commit is contained in:
43
src/core/resume-factory.js
Normal file
43
src/core/resume-factory.js
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
Core resume-loading logic for HackMyResume.
|
||||
@module resume-factory.js
|
||||
*/
|
||||
|
||||
(function(){
|
||||
|
||||
require('string.prototype.startswith');
|
||||
var FS = require('fs');
|
||||
var ResumeConverter = require('./convert');
|
||||
|
||||
/**
|
||||
A simple factory class for FRESH and JSON Resumes.
|
||||
@class ResumeFactory
|
||||
*/
|
||||
module.exports = {
|
||||
|
||||
/**
|
||||
Load one or more resumes in a specific source format.
|
||||
*/
|
||||
load: function ( src, log, fn, toFormat ) {
|
||||
|
||||
toFormat = toFormat && (toFormat.toLowerCase().trim()) || 'fresh';
|
||||
var ResumeClass = require('../core/' + toFormat + '-resume');
|
||||
|
||||
return src.map( function( res ) {
|
||||
var rezJson = JSON.parse( FS.readFileSync( res ) );
|
||||
var orgFormat = ( rezJson.meta && rezJson.meta.format &&
|
||||
rezJson.meta.format.startsWith('FRESH@') ) ?
|
||||
'fresh' : 'jrs';
|
||||
if(orgFormat !== toFormat) {
|
||||
rezJson = ResumeConverter[ 'to' + toFormat.toUpperCase() ]( rezJson );
|
||||
}
|
||||
// TODO: Core should not log
|
||||
log( 'Reading '.info + orgFormat.toUpperCase().infoBold + ' resume: '.info + res.cyan.bold );
|
||||
return (fn && fn(res)) || (new ResumeClass()).parseJSON( rezJson );
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}());
|
Reference in New Issue
Block a user