mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 16:30:11 +00:00
Clean up handling of "meta".
This commit is contained in:
parent
ad6d2c75ca
commit
9cde39703e
@ -35,7 +35,7 @@ FRESH to JSON Resume conversion routiens.
|
|||||||
//other: [none]
|
//other: [none]
|
||||||
},
|
},
|
||||||
|
|
||||||
meta: jrs.meta,
|
meta: meta2FRESH( jrs.meta ),
|
||||||
|
|
||||||
// disposition: {
|
// disposition: {
|
||||||
// travel: 25,
|
// travel: 25,
|
||||||
@ -249,6 +249,13 @@ FRESH to JSON Resume conversion routiens.
|
|||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function meta2FRESH( obj ) {
|
||||||
|
obj = obj || { };
|
||||||
|
obj.format = obj.format || "FRESH@0.1.0";
|
||||||
|
obj.version = obj.version || "0.1.0";
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
|
||||||
function skillsToFRESH( skills ) {
|
function skillsToFRESH( skills ) {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -27,17 +27,17 @@ Definition of the FRESHResume class.
|
|||||||
consistent format. Then sort each section by startDate descending.
|
consistent format. Then sort each section by startDate descending.
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.open = function( file, title ) {
|
FreshResume.prototype.open = function( file, title ) {
|
||||||
this.meta = { fileName: file };
|
this.imp = { fileName: file };
|
||||||
this.meta.raw = FS.readFileSync( file, 'utf8' );
|
this.imp.raw = FS.readFileSync( file, 'utf8' );
|
||||||
return this.parse( this.meta.raw, title );
|
return this.parse( this.imp.raw, title );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Save the sheet to disk (for environments that have disk access).
|
Save the sheet to disk (for environments that have disk access).
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.save = function( filename ) {
|
FreshResume.prototype.save = function( filename ) {
|
||||||
this.meta.fileName = filename || this.meta.fileName;
|
this.imp.fileName = filename || this.imp.fileName;
|
||||||
FS.writeFileSync( this.meta.fileName, this.stringify(), 'utf8' );
|
FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' );
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -45,13 +45,13 @@ Definition of the FRESHResume class.
|
|||||||
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
||||||
*/
|
*/
|
||||||
FreshResume.prototype.saveAs = function( filename, format ) {
|
FreshResume.prototype.saveAs = function( filename, format ) {
|
||||||
this.meta.fileName = filename || this.meta.fileName;
|
this.imp.fileName = filename || this.imp.fileName;
|
||||||
if( format !== 'JRS' ) {
|
if( format !== 'JRS' ) {
|
||||||
FS.writeFileSync( this.meta.fileName, this.stringify(), 'utf8' );
|
FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
var newRep = CONVERTER.toJRS( this );
|
var newRep = CONVERTER.toJRS( this );
|
||||||
FS.writeFileSync( this.meta.fileName, FreshResume.stringify( newRep ), 'utf8' );
|
FS.writeFileSync( this.imp.fileName, FreshResume.stringify( newRep ), 'utf8' );
|
||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@ -62,7 +62,7 @@ Definition of the FRESHResume class.
|
|||||||
*/
|
*/
|
||||||
FreshResume.stringify = function( obj ) {
|
FreshResume.stringify = function( obj ) {
|
||||||
function replacer( key,value ) { // Exclude these keys from stringification
|
function replacer( key,value ) { // Exclude these keys from stringification
|
||||||
return _.some(['meta', 'warnings', 'computed', 'filt', 'ctrl', 'index',
|
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
|
||||||
'safe', 'result', 'isModified', 'htmlPreview', 'display_progress_bar'],
|
'safe', 'result', 'isModified', 'htmlPreview', 'display_progress_bar'],
|
||||||
function( val ) { return key.trim() === val; }
|
function( val ) { return key.trim() === val; }
|
||||||
) ? undefined : value;
|
) ? undefined : value;
|
||||||
@ -89,16 +89,20 @@ Definition of the FRESHResume class.
|
|||||||
var rep = JSON.parse( stringData );
|
var rep = JSON.parse( stringData );
|
||||||
|
|
||||||
// Convert JSON Resume to FRESH if necessary
|
// Convert JSON Resume to FRESH if necessary
|
||||||
rep.basics && ( rep = CONVERTER.toFRESH( rep ) );
|
if( rep.basics ) {
|
||||||
|
rep = CONVERTER.toFRESH( rep );
|
||||||
|
rep.imp = rep.imp || { };
|
||||||
|
rep.imp.orgFormat = 'JRS';
|
||||||
|
}
|
||||||
|
|
||||||
// Now apply the resume representation onto this object
|
// Now apply the resume representation onto this object
|
||||||
extend( true, this, rep );
|
extend( true, this, rep );
|
||||||
|
|
||||||
// Set up metadata
|
// Set up metadata
|
||||||
opts = opts || { };
|
opts = opts || { };
|
||||||
if( opts.meta === undefined || opts.meta ) {
|
if( opts.imp === undefined || opts.imp ) {
|
||||||
this.meta = this.meta || { };
|
this.imp = this.imp || { };
|
||||||
this.meta.title = (opts.title || this.meta.title) || this.name;
|
this.imp.title = (opts.title || this.imp.title) || this.name;
|
||||||
}
|
}
|
||||||
// Parse dates, sort dates, and calculate computed values
|
// Parse dates, sort dates, and calculate computed values
|
||||||
(opts.date === undefined || opts.date) && _parseDates.call( this );
|
(opts.date === undefined || opts.date) && _parseDates.call( this );
|
||||||
@ -134,7 +138,7 @@ Definition of the FRESHResume class.
|
|||||||
*/
|
*/
|
||||||
FreshResume.prototype.clear = function( clearMeta ) {
|
FreshResume.prototype.clear = function( clearMeta ) {
|
||||||
clearMeta = ((clearMeta === undefined) && true) || clearMeta;
|
clearMeta = ((clearMeta === undefined) && true) || clearMeta;
|
||||||
clearMeta && (delete this.meta);
|
clearMeta && (delete this.imp);
|
||||||
delete this.computed; // Don't use Object.keys() here
|
delete this.computed; // Don't use Object.keys() here
|
||||||
delete this.employment;
|
delete this.employment;
|
||||||
delete this.service;
|
delete this.service;
|
||||||
@ -197,8 +201,8 @@ Definition of the FRESHResume class.
|
|||||||
});
|
});
|
||||||
var ret = validate( this );
|
var ret = validate( this );
|
||||||
if( !ret ) {
|
if( !ret ) {
|
||||||
this.meta = this.meta || { };
|
this.imp = this.imp || { };
|
||||||
this.meta.validationErrors = validate.errors;
|
this.imp.validationErrors = validate.errors;
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
};
|
};
|
||||||
|
@ -30,17 +30,17 @@ Definition of the JRSResume class.
|
|||||||
consistent format. Then sort each section by startDate descending.
|
consistent format. Then sort each section by startDate descending.
|
||||||
*/
|
*/
|
||||||
JRSResume.prototype.open = function( file, title ) {
|
JRSResume.prototype.open = function( file, title ) {
|
||||||
this.meta = { fileName: file };
|
this.imp = { fileName: file };
|
||||||
this.meta.raw = FS.readFileSync( file, 'utf8' );
|
this.imp.raw = FS.readFileSync( file, 'utf8' );
|
||||||
return this.parse( this.meta.raw, title );
|
return this.parse( this.imp.raw, title );
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Save the sheet to disk (for environments that have disk access).
|
Save the sheet to disk (for environments that have disk access).
|
||||||
*/
|
*/
|
||||||
JRSResume.prototype.save = function( filename ) {
|
JRSResume.prototype.save = function( filename ) {
|
||||||
this.meta.fileName = filename || this.meta.fileName;
|
this.imp.fileName = filename || this.imp.fileName;
|
||||||
FS.writeFileSync( this.meta.fileName, this.stringify(), 'utf8' );
|
FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' );
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -69,9 +69,9 @@ Definition of the JRSResume class.
|
|||||||
var rep = JSON.parse( stringData );
|
var rep = JSON.parse( stringData );
|
||||||
extend( true, this, rep );
|
extend( true, this, rep );
|
||||||
// Set up metadata
|
// Set up metadata
|
||||||
if( opts.meta === undefined || opts.meta ) {
|
if( opts.imp === undefined || opts.imp ) {
|
||||||
this.meta = this.meta || { };
|
this.imp = this.imp || { };
|
||||||
this.meta.title = (opts.title || this.meta.title) || this.basics.name;
|
this.imp.title = (opts.title || this.imp.title) || this.basics.name;
|
||||||
}
|
}
|
||||||
// Parse dates, sort dates, and calculate computed values
|
// Parse dates, sort dates, and calculate computed values
|
||||||
(opts.date === undefined || opts.date) && _parseDates.call( this );
|
(opts.date === undefined || opts.date) && _parseDates.call( this );
|
||||||
@ -110,7 +110,7 @@ Definition of the JRSResume class.
|
|||||||
*/
|
*/
|
||||||
JRSResume.prototype.clear = function( clearMeta ) {
|
JRSResume.prototype.clear = function( clearMeta ) {
|
||||||
clearMeta = ((clearMeta === undefined) && true) || clearMeta;
|
clearMeta = ((clearMeta === undefined) && true) || clearMeta;
|
||||||
clearMeta && (delete this.meta);
|
clearMeta && (delete this.imp);
|
||||||
delete this.computed; // Don't use Object.keys() here
|
delete this.computed; // Don't use Object.keys() here
|
||||||
delete this.work;
|
delete this.work;
|
||||||
delete this.volunteer;
|
delete this.volunteer;
|
||||||
|
@ -43,8 +43,8 @@ module.exports = function () {
|
|||||||
// Merge input resumes...
|
// Merge input resumes...
|
||||||
var msg = '';
|
var msg = '';
|
||||||
rez = _.reduceRight( sheets, function( a, b, idx ) {
|
rez = _.reduceRight( sheets, function( a, b, idx ) {
|
||||||
msg += ((idx == sheets.length - 2) ? 'Merging ' + a.meta.fileName : '')
|
msg += ((idx == sheets.length - 2) ? 'Merging ' + a.imp.fileName : '')
|
||||||
+ ' onto ' + b.meta.fileName;
|
+ ' onto ' + b.imp.fileName;
|
||||||
return extend( true, b, a );
|
return extend( true, b, a );
|
||||||
});
|
});
|
||||||
msg && _log(msg);
|
msg && _log(msg);
|
||||||
@ -144,7 +144,7 @@ module.exports = function () {
|
|||||||
_log( 'Validating JSON resume: ' + res +
|
_log( 'Validating JSON resume: ' + res +
|
||||||
(valid ? ' (VALID)' : ' (INVALID)'));
|
(valid ? ' (VALID)' : ' (INVALID)'));
|
||||||
if( !valid ) {
|
if( !valid ) {
|
||||||
_log( sheet.meta.validationErrors );
|
_log( sheet.imp.validationErrors );
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -156,7 +156,7 @@ module.exports = function () {
|
|||||||
_log = logger || console.log;
|
_log = logger || console.log;
|
||||||
if( !src || src.length !== 1 ) { throw { fluenterror: 3 }; }
|
if( !src || src.length !== 1 ) { throw { fluenterror: 3 }; }
|
||||||
var sheet = (new FLUENT.FRESHResume()).open( src[ 0 ] );
|
var sheet = (new FLUENT.FRESHResume()).open( src[ 0 ] );
|
||||||
sheet.saveAs( dst[0], sheet.meta.orgFormat === 'JRS' ? 'FRESH' : 'JRS' );
|
sheet.saveAs( dst[0], sheet.imp.orgFormat === 'JRS' ? 'FRESH' : 'JRS' );
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -57,9 +57,9 @@ describe('jane-doe.json (FRESH)', function () {
|
|||||||
var result = _sheet.isValid();
|
var result = _sheet.isValid();
|
||||||
// var schemaJson = require('FRESCA');
|
// var schemaJson = require('FRESCA');
|
||||||
// var validate = validator( schemaJson, { verbose: true } );
|
// var validate = validator( schemaJson, { verbose: true } );
|
||||||
// var result = validate( JSON.parse( _sheet.meta.raw ) );
|
// var result = validate( JSON.parse( _sheet.imp.raw ) );
|
||||||
result || console.log("\n\nOops, resume didn't validate. " +
|
result || console.log("\n\nOops, resume didn't validate. " +
|
||||||
"Validation errors:\n\n", _sheet.meta.validationErrors, "\n\n");
|
"Validation errors:\n\n", _sheet.imp.validationErrors, "\n\n");
|
||||||
result.should.equal( true );
|
result.should.equal( true );
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ describe('fullstack.json (JRS)', function () {
|
|||||||
it('should validate against the JSON Resume schema', function() {
|
it('should validate against the JSON Resume schema', function() {
|
||||||
var schemaJson = require('../src/core/resume.json');
|
var schemaJson = require('../src/core/resume.json');
|
||||||
var validate = validator( schemaJson, { verbose: true } );
|
var validate = validator( schemaJson, { verbose: true } );
|
||||||
var result = validate( JSON.parse( _sheet.meta.raw ) );
|
var result = validate( JSON.parse( _sheet.imp.raw ) );
|
||||||
result || console.log("\n\nOops, resume didn't validate. " +
|
result || console.log("\n\nOops, resume didn't validate. " +
|
||||||
"Validation errors:\n\n", validate.errors, "\n\n");
|
"Validation errors:\n\n", validate.errors, "\n\n");
|
||||||
result.should.equal( true );
|
result.should.equal( true );
|
||||||
|
Loading…
Reference in New Issue
Block a user