From 201f39442e832117cf2c7e40c87e3503832b34db Mon Sep 17 00:00:00 2001 From: hacksalot Date: Tue, 19 Jan 2016 20:09:59 -0500 Subject: [PATCH] Add support for .ignore flag in FRESH and JRS resumes. Preliminary support for ".ignore" on any non-leaf FRESH or JRS node. Nodes (employment entries, education stints, etc.) decorated with ".ignore" will be treated by HMR as if they weren't present. --- package.json | 1 + src/core/fresh-resume.js | 21 ++++++++++++++++----- src/core/jrs-resume.js | 33 +++++++++++++++++++++++++++------ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index b41ef18..898a884 100644 --- a/package.json +++ b/package.json @@ -74,6 +74,7 @@ "slash": "^1.0.0", "string-padding": "^1.0.2", "string.prototype.startswith": "^0.2.0", + "traverse": "^0.6.6", "underscore": "^1.8.3", "webshot": "^0.16.0", "word-wrap": "^1.1.0", diff --git a/src/core/fresh-resume.js b/src/core/fresh-resume.js index 952798b..1a0f6c8 100644 --- a/src/core/fresh-resume.js +++ b/src/core/fresh-resume.js @@ -1,7 +1,7 @@ /** Definition of the FRESHResume class. -@license MIT. See LICENSE .md for details. -@module fresh-resume.js +@license MIT. See LICENSE.md for details. +@module core/fresh-resume */ @@ -48,7 +48,7 @@ Definition of the FRESHResume class. /** - Initialize the the FreshResume from string. + Initialize the the FreshResume from JSON string data. */ FreshResume.prototype.parse = function( stringData, opts ) { return this.parseJSON( JSON.parse( stringData ), opts ); @@ -66,13 +66,24 @@ Definition of the FRESHResume class. { date: Perform safe date conversion. sort: Sort resume items by date. - computer: Prepare computed resume totals. + compute: Prepare computed resume totals. } */ FreshResume.prototype.parseJSON = function( rep, opts ) { + // Ignore any element with the 'ignore: true' designator. + var that = this, traverse = require('traverse'), ignoreList = []; + var scrubbed = traverse( rep ).map( function( x ) { + if( !this.isLeaf && this.node.ignore ) { + if ( this.node.ignore === true || this.node.ignore === 'true' ) { + ignoreList.push( this.node ); + this.remove(); + } + } + }); + // Now apply the resume representation onto this object - extend( true, this, rep ); + extend( true, this, scrubbed ); // If the resume already has a .imp object, then we are being called from // the .dupe method, and there's no need to do any post processing diff --git a/src/core/jrs-resume.js b/src/core/jrs-resume.js index 5e6abc9..7b63f3f 100644 --- a/src/core/jrs-resume.js +++ b/src/core/jrs-resume.js @@ -1,7 +1,7 @@ /** Definition of the JRSResume class. @license MIT. See LICENSE.md for details. -@module jrs-resume.js +@module core/jrs-resume */ @@ -60,14 +60,35 @@ Definition of the JRSResume class. /** - Initialize the JRSResume from JSON. - Open and parse the specified JRS resume. Merge the JSON object model onto this - Sheet instance with extend() and convert sheet dates to a safe & consistent - format. Then sort each section by startDate descending. + Initialize the JRSResume object from JSON. + Open and parse the specified JRS resume. Merge the JSON object model onto + this Sheet instance with extend() and convert sheet dates to a safe & + consistent format. Then sort each section by startDate descending. + @param rep {Object} The raw JSON representation. + @param opts {Object} Resume loading and parsing options. + { + date: Perform safe date conversion. + sort: Sort resume items by date. + compute: Prepare computed resume totals. + } */ JRSResume.prototype.parseJSON = function( rep, opts ) { opts = opts || { }; - extend( true, this, rep ); + + // Ignore any element with the 'ignore: true' designator. + var that = this, traverse = require('traverse'), ignoreList = []; + var scrubbed = traverse( rep ).map( function( x ) { + if( !this.isLeaf && this.node.ignore ) { + if ( this.node.ignore === true || this.node.ignore === 'true' ) { + ignoreList.push( this.node ); + this.remove(); + } + } + }); + + // Extend resume properties onto ourself. + extend( true, this, scrubbed ); + // Set up metadata if( opts.imp === undefined || opts.imp ) { this.basics.imp = this.basics.imp || { };