From 9cde39703e3f8a50aad83accac01e3c49fd3977f Mon Sep 17 00:00:00 2001 From: devlinjd Date: Fri, 20 Nov 2015 09:28:55 -0500 Subject: [PATCH] Clean up handling of "meta". --- src/core/convert.js | 9 ++++++++- src/core/fresh-resume.js | 36 ++++++++++++++++++++---------------- src/core/jrs-resume.js | 18 +++++++++--------- src/fluentcmd.js | 8 ++++---- tests/test-fresh-sheet.js | 4 ++-- tests/test-jrs-sheet.js | 2 +- 6 files changed, 44 insertions(+), 33 deletions(-) diff --git a/src/core/convert.js b/src/core/convert.js index 7e15cbf..1c0170c 100644 --- a/src/core/convert.js +++ b/src/core/convert.js @@ -35,7 +35,7 @@ FRESH to JSON Resume conversion routiens. //other: [none] }, - meta: jrs.meta, + meta: meta2FRESH( jrs.meta ), // disposition: { // 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 ) { return { diff --git a/src/core/fresh-resume.js b/src/core/fresh-resume.js index 3a30ff2..f5f702c 100644 --- a/src/core/fresh-resume.js +++ b/src/core/fresh-resume.js @@ -27,17 +27,17 @@ Definition of the FRESHResume class. consistent format. Then sort each section by startDate descending. */ FreshResume.prototype.open = function( file, title ) { - this.meta = { fileName: file }; - this.meta.raw = FS.readFileSync( file, 'utf8' ); - return this.parse( this.meta.raw, title ); + this.imp = { fileName: file }; + this.imp.raw = FS.readFileSync( file, 'utf8' ); + return this.parse( this.imp.raw, title ); }; /** Save the sheet to disk (for environments that have disk access). */ FreshResume.prototype.save = function( filename ) { - this.meta.fileName = filename || this.meta.fileName; - FS.writeFileSync( this.meta.fileName, this.stringify(), 'utf8' ); + this.imp.fileName = filename || this.imp.fileName; + FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' ); 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. */ FreshResume.prototype.saveAs = function( filename, format ) { - this.meta.fileName = filename || this.meta.fileName; + this.imp.fileName = filename || this.imp.fileName; if( format !== 'JRS' ) { - FS.writeFileSync( this.meta.fileName, this.stringify(), 'utf8' ); + FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' ); } else { 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; } @@ -62,7 +62,7 @@ Definition of the FRESHResume class. */ FreshResume.stringify = function( obj ) { 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'], function( val ) { return key.trim() === val; } ) ? undefined : value; @@ -89,16 +89,20 @@ Definition of the FRESHResume class. var rep = JSON.parse( stringData ); // 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 extend( true, this, rep ); // Set up metadata opts = opts || { }; - if( opts.meta === undefined || opts.meta ) { - this.meta = this.meta || { }; - this.meta.title = (opts.title || this.meta.title) || this.name; + if( opts.imp === undefined || opts.imp ) { + this.imp = this.imp || { }; + this.imp.title = (opts.title || this.imp.title) || this.name; } // Parse dates, sort dates, and calculate computed values (opts.date === undefined || opts.date) && _parseDates.call( this ); @@ -134,7 +138,7 @@ Definition of the FRESHResume class. */ FreshResume.prototype.clear = function( 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.employment; delete this.service; @@ -197,8 +201,8 @@ Definition of the FRESHResume class. }); var ret = validate( this ); if( !ret ) { - this.meta = this.meta || { }; - this.meta.validationErrors = validate.errors; + this.imp = this.imp || { }; + this.imp.validationErrors = validate.errors; } return ret; }; diff --git a/src/core/jrs-resume.js b/src/core/jrs-resume.js index 55e8e29..b7fed04 100644 --- a/src/core/jrs-resume.js +++ b/src/core/jrs-resume.js @@ -30,17 +30,17 @@ Definition of the JRSResume class. consistent format. Then sort each section by startDate descending. */ JRSResume.prototype.open = function( file, title ) { - this.meta = { fileName: file }; - this.meta.raw = FS.readFileSync( file, 'utf8' ); - return this.parse( this.meta.raw, title ); + this.imp = { fileName: file }; + this.imp.raw = FS.readFileSync( file, 'utf8' ); + return this.parse( this.imp.raw, title ); }; /** Save the sheet to disk (for environments that have disk access). */ JRSResume.prototype.save = function( filename ) { - this.meta.fileName = filename || this.meta.fileName; - FS.writeFileSync( this.meta.fileName, this.stringify(), 'utf8' ); + this.imp.fileName = filename || this.imp.fileName; + FS.writeFileSync( this.imp.fileName, this.stringify(), 'utf8' ); return this; }; @@ -69,9 +69,9 @@ Definition of the JRSResume class. var rep = JSON.parse( stringData ); extend( true, this, rep ); // Set up metadata - if( opts.meta === undefined || opts.meta ) { - this.meta = this.meta || { }; - this.meta.title = (opts.title || this.meta.title) || this.basics.name; + if( opts.imp === undefined || opts.imp ) { + this.imp = this.imp || { }; + this.imp.title = (opts.title || this.imp.title) || this.basics.name; } // Parse dates, sort dates, and calculate computed values (opts.date === undefined || opts.date) && _parseDates.call( this ); @@ -110,7 +110,7 @@ Definition of the JRSResume class. */ JRSResume.prototype.clear = function( 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.work; delete this.volunteer; diff --git a/src/fluentcmd.js b/src/fluentcmd.js index b25b3ac..0bed242 100644 --- a/src/fluentcmd.js +++ b/src/fluentcmd.js @@ -43,8 +43,8 @@ module.exports = function () { // Merge input resumes... var msg = ''; rez = _.reduceRight( sheets, function( a, b, idx ) { - msg += ((idx == sheets.length - 2) ? 'Merging ' + a.meta.fileName : '') - + ' onto ' + b.meta.fileName; + msg += ((idx == sheets.length - 2) ? 'Merging ' + a.imp.fileName : '') + + ' onto ' + b.imp.fileName; return extend( true, b, a ); }); msg && _log(msg); @@ -144,7 +144,7 @@ module.exports = function () { _log( 'Validating JSON resume: ' + res + (valid ? ' (VALID)' : ' (INVALID)')); if( !valid ) { - _log( sheet.meta.validationErrors ); + _log( sheet.imp.validationErrors ); } }); } @@ -156,7 +156,7 @@ module.exports = function () { _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' ); + sheet.saveAs( dst[0], sheet.imp.orgFormat === 'JRS' ? 'FRESH' : 'JRS' ); } /** diff --git a/tests/test-fresh-sheet.js b/tests/test-fresh-sheet.js index 25b829d..d7aa2f5 100644 --- a/tests/test-fresh-sheet.js +++ b/tests/test-fresh-sheet.js @@ -57,9 +57,9 @@ describe('jane-doe.json (FRESH)', function () { var result = _sheet.isValid(); // var schemaJson = require('FRESCA'); // 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. " + - "Validation errors:\n\n", _sheet.meta.validationErrors, "\n\n"); + "Validation errors:\n\n", _sheet.imp.validationErrors, "\n\n"); result.should.equal( true ); }); diff --git a/tests/test-jrs-sheet.js b/tests/test-jrs-sheet.js index 5fccb35..3afcba8 100644 --- a/tests/test-jrs-sheet.js +++ b/tests/test-jrs-sheet.js @@ -51,7 +51,7 @@ describe('fullstack.json (JRS)', function () { it('should validate against the JSON Resume schema', function() { var schemaJson = require('../src/core/resume.json'); 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. " + "Validation errors:\n\n", validate.errors, "\n\n"); result.should.equal( true );