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

Implement "convert" command.

This commit is contained in:
devlinjd
2015-11-20 08:29:19 -05:00
parent 16cf97e08e
commit c14176a504
4 changed files with 206 additions and 6 deletions

View File

@ -42,17 +42,40 @@ Definition of the FRESHResume class.
};
/**
Convert this object to a JSON string, sanitizing meta-properties along the
way. Don't override .toString().
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
*/
FreshResume.prototype.stringify = function() {
FreshResume.prototype.saveAs = function( filename, format ) {
this.meta.fileName = filename || this.meta.fileName;
if( format !== 'JRS' ) {
FS.writeFileSync( this.meta.fileName, this.stringify(), 'utf8' );
}
else {
var newRep = CONVERTER.toJRS( this );
FS.writeFileSync( this.meta.fileName, FreshResume.stringify( newRep ), 'utf8' );
}
return this;
}
/**
Convert the supplied object to a JSON string, sanitizing meta-properties along
the way.
*/
FreshResume.stringify = function( obj ) {
function replacer( key,value ) { // Exclude these keys from stringification
return _.some(['meta', 'warnings', 'computed', 'filt', 'ctrl', 'index',
'safe', 'result', 'isModified', 'htmlPreview', 'display_progress_bar'],
function( val ) { return key.trim() === val; }
) ? undefined : value;
}
return JSON.stringify( this, replacer, 2 );
return JSON.stringify( obj, replacer, 2 );
},
/**
Convert this object to a JSON string, sanitizing meta-properties along the
way. Don't override .toString().
*/
FreshResume.prototype.stringify = function() {
return FreshResume.stringify( this );
};
/**
@ -66,7 +89,7 @@ Definition of the FRESHResume class.
var rep = JSON.parse( stringData );
// Convert JSON Resume to FRESH if necessary
rep.basics && (rep = CONVERTER.toFRESH( rep ));
rep.basics && ( rep = CONVERTER.toFRESH( rep ) );
// Now apply the resume representation onto this object
extend( true, this, rep );

View File

@ -149,6 +149,16 @@ module.exports = function () {
});
}
/**
Convert between FRESH and JRS formats.
*/
function convert( src, dst, opts, logger ) {
_log = logger || console.log;
if( !src || src.length !== 1 ) { throw { fluenterror: 3 }; }
var sheet = (new FLUENT.FRESHResume()).open( src[ 0 ] );
sheet.saveAs( dst[0], sheet.meta.orgFormat === 'JRS' ? 'FRESH' : 'JRS' );
}
/**
Supported resume formats.
*/
@ -181,7 +191,8 @@ module.exports = function () {
return {
verbs: {
generate: gen,
validate: validate
validate: validate,
convert: convert
},
lib: require('./fluentlib'),
options: _opts,