1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-04 05:17:08 +01:00

Interim changes supporting v1.3.0.

This commit is contained in:
hacksalot
2015-12-31 03:34:41 -05:00
parent 1f6d77fc28
commit 069c02ddcc
10 changed files with 234 additions and 82 deletions

View File

@ -1,11 +1,13 @@
/**
FRESH to JSON Resume conversion routiens.
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
@license MIT. See LICENSE.md for details.
@module convert.js
*/
(function(){
var _ = require('underscore');
/**
Convert between FRESH and JRS resume/CV formats.
@class FRESHConverter
@ -26,6 +28,8 @@ FRESH to JSON Resume conversion routiens.
name: src.basics.name,
imp: src.basics.imp,
info: {
label: src.basics.label,
class: src.basics.class, // <--> round-trip
@ -92,7 +96,8 @@ FRESH to JSON Resume conversion routiens.
countryCode: src.location.country,
region: src.location.region
},
profiles: social( src.social, false )
profiles: social( src.social, false ),
imp: src.imp
},
work: employment( src.employment, false ),
@ -109,12 +114,30 @@ FRESH to JSON Resume conversion routiens.
};
},
toSTRING: function( src ) {
function replacerJRS( key,value ) { // Exclude these keys from stringification
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
'safeStartDate', 'safeEndDate', 'safeDate', 'safeReleaseDate', 'result',
'isModified', 'htmlPreview', 'display_progress_bar'],
function( val ) { return key.trim() === val; }
) ? undefined : value;
}
function replacerFRESH( key,value ) { // Exclude these keys from stringification
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
'safe', 'result', 'isModified', 'htmlPreview', 'display_progress_bar'],
function( val ) { return key.trim() === val; }
) ? undefined : value;
}
return JSON.stringify( src, src.basics ? replacerJRS : replacerFRESH, 2 );
}
};
function meta( direction, obj ) {
if( !obj ) return obj; // preserve null and undefined
//if( !obj ) return obj; // preserve null and undefined
if( direction ) {
obj = obj || { };
obj.format = obj.format || "FRESH@0.1.0";
@ -151,7 +174,7 @@ FRESH to JSON Resume conversion routiens.
start: job.startDate,
end: job.endDate,
url: job.website,
keywords: "",
keywords: [],
highlights: job.highlights
};
}) : undefined
@ -164,6 +187,7 @@ FRESH to JSON Resume conversion routiens.
if( !obj ) return obj;
if( direction ) {
return obj && obj.length ? {
level: "",
history: obj.map(function(edu){
return {
institution: edu.institution,
@ -171,8 +195,8 @@ FRESH to JSON Resume conversion routiens.
end: edu.endDate,
grade: edu.gpa,
curriculum: edu.courses,
url: edu.website || edu.url || null,
summary: null,
url: edu.website || edu.url || undefined,
summary: edu.summary || "",
area: edu.area,
studyType: edu.studyType
};

View File

@ -1,6 +1,6 @@
/**
Definition of the JRSResume class.
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
@license MIT. See LICENSE.md for details.
@module jrs-resume.js
*/
@ -12,6 +12,7 @@ Definition of the JRSResume class.
, _ = require('underscore')
, PATH = require('path')
, MD = require('marked')
, CONVERTER = require('./convert')
, moment = require('moment');
/**
@ -51,6 +52,24 @@ Definition of the JRSResume class.
return this;
};
/**
Save the sheet to disk in a specific format, either FRESH or JRS.
*/
JRSResume.prototype.saveAs = function( filename, format ) {
if( format === 'JRS' ) {
this.basics.imp.fileName = filename || this.imp.fileName;
FS.writeFileSync( this.basics.imp.fileName, this.stringify(), 'utf8' );
}
else {
var newRep = CONVERTER.toFRESH( this );
var stringRep = CONVERTER.toSTRING( newRep );
FS.writeFileSync( filename, stringRep, 'utf8' );
}
return this;
};
/**
Convert this object to a JSON string, sanitizing meta-properties along the
way. Don't override .toString().
@ -92,6 +111,7 @@ Definition of the JRSResume class.
if( opts.imp === undefined || opts.imp ) {
this.basics.imp = this.basics.imp || { };
this.basics.imp.title = (opts.title || this.basics.imp.title) || this.basics.name;
this.basics.imp.orgFormat = 'JRS';
}
// Parse dates, sort dates, and calculate computed values
(opts.date === undefined || opts.date) && _parseDates.call( this );

View File

@ -1,43 +1,107 @@
/**
Core resume-loading logic for HackMyResume.
Definition of the ResumeFactory class.
@license MIT. See LICENSE.md for details.
@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 = {
var ResumeFactory = module.exports = {
/**
Load one or more resumes in a specific source format.
Load one or more resumes from disk.
*/
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 );
load: function ( sources, log, toFormat, objectify ) {
// Loop over all inputs, parsing each to JSON and then to a FRESHResume
// or JRSResume object.
var that = this;
return sources.map( function( src ) {
return that.loadOne( src, log, toFormat, objectify );
});
}
},
/**
Load a single resume from disk.
*/
loadOne: function( src, log, toFormat, objectify ) {
// Get the destination format. Can be 'fresh', 'jrs', or null/undefined.
toFormat && (toFormat = toFormat.toLowerCase().trim());
// Load and parse the resume JSON
var info = _parse( src, log, toFormat );
if( info.error ) return info;
var json = info.json;
// Determine the resume format: FRESH or JRS
var orgFormat = ( json.meta && json.meta.format &&
json.meta.format.startsWith('FRESH@') ) ?
'fresh' : 'jrs';
// Convert between formats if necessary
if( toFormat && (orgFormat !== toFormat) ) {
json = ResumeConverter[ 'to' + toFormat.toUpperCase() ]( json );
}
// Objectify the resume, that is, convert it from JSON to a FRESHResume
// or JRSResume object.
var rez;
if( objectify ) {
var ResumeClass = require('../core/' + (toFormat || orgFormat) + '-resume');
rez = new ResumeClass().parseJSON( json );
}
return {
file: src,
json: info.json,
rez: rez
};
}
};
function _parse( fileName, log, toFormat ) {
var rawData;
try {
// TODO: Core should not log
log( 'Reading '.info + /*orgFormat.toUpperCase().infoBold +*/
'resume: '.info + fileName.cyan.bold );
rawData = FS.readFileSync( fileName, 'utf8' );
return {
json: JSON.parse( rawData )
};
}
catch(ex) {
return {
error: ex,
raw: rawData
};
}
}
}());