1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-24 01:10:11 +00:00

feat: support JSON Resume edge schema

This commit is contained in:
hacksalot 2018-02-10 01:10:20 -05:00
parent 7cfdb95a04
commit 7196bff27c
No known key found for this signature in database
GPG Key ID: 2F343EC247CA4B06
4 changed files with 31 additions and 35 deletions

View File

@ -109,22 +109,18 @@ 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, version) { FreshResume.prototype.saveAs = function(filename, format) {
var freshVersionReg, newRep, parts, safeFormat, safeVersion; var newRep, parts, safeFormat, useEdgeSchema;
safeFormat = (format || 'FRESH').trim(); safeFormat = (format && format.trim()) || 'FRESH';
safeVersion = version || "0";
freshVersionReg = require('../utils/fresh-version-regex');
if (!freshVersionReg().test(safeFormat)) {
throw {
badVer: safeFormat
};
}
parts = safeFormat.split('@'); parts = safeFormat.split('@');
if (parts[0] === 'FRESH') { if (parts[0] === 'FRESH') {
this.imp.file = filename || this.imp.file; this.imp.file = filename || this.imp.file;
FS.writeFileSync(this.imp.file, this.stringify(), 'utf8'); FS.writeFileSync(this.imp.file, this.stringify(), 'utf8');
} else if (parts[0] === 'JRS') { } else if (parts[0] === 'JRS') {
newRep = CONVERTER.toJRS(this, null, parts.length > 1 ? parts[1] : "1.0.0"); useEdgeSchema = parts.length > 1 ? parts[1] === '1' : false;
newRep = CONVERTER.toJRS(this, {
edge: useEdgeSchema
});
FS.writeFileSync(filename, JRSResume.stringify(newRep), 'utf8'); FS.writeFileSync(filename, JRSResume.stringify(newRep), 'utf8');
} else { } else {
throw { throw {

14
dist/verbs/convert.js vendored
View File

@ -39,7 +39,7 @@ Implementation of the 'convert' verb for HackMyResume.
*/ */
_convert = function(srcs, dst, opts) { _convert = function(srcs, dst, opts) {
var fmtUp, freshVerRegex, matches, results, targetSchema, targetVer; var fmtUp, results, targetVer;
if (!srcs || !srcs.length) { if (!srcs || !srcs.length) {
this.err(HMSTATUS.resumeNotFound, { this.err(HMSTATUS.resumeNotFound, {
quit: true quit: true
@ -68,16 +68,12 @@ Implementation of the 'convert' verb for HackMyResume.
targetVer = null; targetVer = null;
if (opts.format) { if (opts.format) {
fmtUp = opts.format.trim().toUpperCase(); fmtUp = opts.format.trim().toUpperCase();
freshVerRegex = require('../utils/fresh-version-regex'); if (!_.contains(['FRESH', 'FRESCA', 'JRS', 'JRS@1', 'JRS@edge'], fmtUp)) {
matches = fmtUp.match(freshVerRegex());
if (!matches) {
this.err(HMSTATUS.invalidSchemaVersion, { this.err(HMSTATUS.invalidSchemaVersion, {
data: opts.format.trim(), data: opts.format.trim(),
quit: true quit: true
}); });
} }
targetSchema = matches[1];
targetVer = matches[2] || '1';
} }
if (this.hasError()) { if (this.hasError()) {
this.reject(this.errorCode); this.reject(this.errorCode);
@ -85,7 +81,7 @@ Implementation of the 'convert' verb for HackMyResume.
} }
results = _.map(srcs, function(src, idx) { results = _.map(srcs, function(src, idx) {
var r; var r;
r = _convertOne.call(this, src, dst, idx, targetSchema, targetVer); r = _convertOne.call(this, src, dst, idx, fmtUp);
if (r.fluenterror) { if (r.fluenterror) {
r.quit = opts.assert; r.quit = opts.assert;
this.err(r.fluenterror, r); this.err(r.fluenterror, r);
@ -103,7 +99,7 @@ Implementation of the 'convert' verb for HackMyResume.
/** Private workhorse method. Convert a single resume. */ /** Private workhorse method. Convert a single resume. */
_convertOne = function(src, dst, idx, targetSchema, targetVer) { _convertOne = function(src, dst, idx, targetSchema) {
var err, rez, rinfo, srcFmt, targetFormat; var err, rez, rinfo, srcFmt, targetFormat;
rinfo = ResumeFactory.loadOne(src, { rinfo = ResumeFactory.loadOne(src, {
format: null, format: null,
@ -140,7 +136,7 @@ Implementation of the 'convert' verb for HackMyResume.
dstFmt: targetFormat dstFmt: targetFormat
}); });
try { try {
rez.saveAs(dst[idx], targetFormat, targetVer); rez.saveAs(dst[idx], targetFormat);
} catch (_error) { } catch (_error) {
err = _error; err = _error;
if (err.badVer) { if (err.badVer) {

View File

@ -94,11 +94,10 @@ class FreshResume# extends AbstractResume
###* ###*
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.
### ###
saveAs: ( filename, format, version ) -> saveAs: ( filename, format ) ->
# If format isn't specified, default to FRESH # If format isn't specified, default to FRESH
safeFormat = (format || 'FRESH').trim() safeFormat = (format && format.trim()) || 'FRESH'
safeVersion = version || "0"
# Validate against the FRESH version regex # Validate against the FRESH version regex
# freshVersionReg = require '../utils/fresh-version-regex' # freshVersionReg = require '../utils/fresh-version-regex'
@ -106,11 +105,14 @@ class FreshResume# extends AbstractResume
# throw badVer: safeFormat # throw badVer: safeFormat
parts = safeFormat.split '@' parts = safeFormat.split '@'
if parts[0] == 'FRESH' if parts[0] == 'FRESH'
@imp.file = filename || @imp.file @imp.file = filename || @imp.file
FS.writeFileSync @imp.file, @stringify(), 'utf8' FS.writeFileSync @imp.file, @stringify(), 'utf8'
else if parts[0] == 'JRS' else if parts[0] == 'JRS'
newRep = CONVERTER.toJRS @, null, if parts.length > 1 then parts[1] else "1" useEdgeSchema = if parts.length > 1 then parts[1] == '1' else false
newRep = CONVERTER.toJRS @, edge: useEdgeSchema
FS.writeFileSync filename, JRSResume.stringify( newRep ), 'utf8' FS.writeFileSync filename, JRSResume.stringify( newRep ), 'utf8'
else else
throw badVer: safeFormat throw badVer: safeFormat

View File

@ -50,15 +50,17 @@ _convert = ( srcs, dst, opts ) ->
targetVer = null targetVer = null
if opts.format if opts.format
fmtUp = opts.format.trim().toUpperCase() fmtUp = opts.format.trim().toUpperCase()
freshVerRegex = require '../utils/fresh-version-regex' if not _.contains ['FRESH','FRESCA','JRS','JRS@1','JRS@edge'], fmtUp
matches = fmtUp.match freshVerRegex()
# null
# [ 'JRS@1.0', 'JRS', '1.0', index: 0, input: 'FRESH' ]
# [ 'FRESH', 'FRESH', undefined, index: 0, input: 'FRESH' ]
if not matches
@err HMSTATUS.invalidSchemaVersion, data: opts.format.trim(), quit: true @err HMSTATUS.invalidSchemaVersion, data: opts.format.trim(), quit: true
targetSchema = matches[1] # freshVerRegex = require '../utils/fresh-version-regex'
targetVer = matches[2] || '1' # matches = fmtUp.match freshVerRegex()
# # null
# # [ 'JRS@1.0', 'JRS', '1.0', index: 0, input: 'FRESH' ]
# # [ 'FRESH', 'FRESH', undefined, index: 0, input: 'FRESH' ]
# if not matches
# @err HMSTATUS.invalidSchemaVersion, data: opts.format.trim(), quit: true
# targetSchema = matches[1]
# targetVer = matches[2] || '1'
# If any errors have occurred this early, we're done. # If any errors have occurred this early, we're done.
if @hasError() if @hasError()
@ -69,7 +71,7 @@ _convert = ( srcs, dst, opts ) ->
results = _.map srcs, ( src, idx ) -> results = _.map srcs, ( src, idx ) ->
# Convert each resume in turn # Convert each resume in turn
r = _convertOne.call @, src, dst, idx, targetSchema, targetVer r = _convertOne.call @, src, dst, idx, fmtUp
# Handle conversion errors # Handle conversion errors
if r.fluenterror if r.fluenterror
@ -88,7 +90,7 @@ _convert = ( srcs, dst, opts ) ->
###* Private workhorse method. Convert a single resume. ### ###* Private workhorse method. Convert a single resume. ###
_convertOne = (src, dst, idx, targetSchema, targetVer) -> _convertOne = (src, dst, idx, targetSchema) ->
# Load the resume # Load the resume
rinfo = ResumeFactory.loadOne src, rinfo = ResumeFactory.loadOne src,
@ -132,7 +134,7 @@ _convertOne = (src, dst, idx, targetSchema, targetVer) ->
# Save it to the destination format # Save it to the destination format
try try
rez.saveAs dst[idx], targetFormat, targetVer rez.saveAs dst[idx], targetFormat
catch err catch err
if err.badVer if err.badVer
return fluenterror: HMSTATUS.invalidSchemaVersion, quit: true, data: err.badVer return fluenterror: HMSTATUS.invalidSchemaVersion, quit: true, data: err.badVer