mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-10 07:47:07 +01:00
feat: support JSON Resume edge schema
This commit is contained in:
@ -94,11 +94,10 @@ class FreshResume# extends AbstractResume
|
||||
###*
|
||||
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
|
||||
safeFormat = (format || 'FRESH').trim()
|
||||
safeVersion = version || "0"
|
||||
safeFormat = (format && format.trim()) || 'FRESH'
|
||||
|
||||
# Validate against the FRESH version regex
|
||||
# freshVersionReg = require '../utils/fresh-version-regex'
|
||||
@ -106,11 +105,14 @@ class FreshResume# extends AbstractResume
|
||||
# throw badVer: safeFormat
|
||||
|
||||
parts = safeFormat.split '@'
|
||||
|
||||
if parts[0] == 'FRESH'
|
||||
@imp.file = filename || @imp.file
|
||||
FS.writeFileSync @imp.file, @stringify(), 'utf8'
|
||||
|
||||
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'
|
||||
else
|
||||
throw badVer: safeFormat
|
||||
|
@ -50,15 +50,17 @@ _convert = ( srcs, dst, opts ) ->
|
||||
targetVer = null
|
||||
if opts.format
|
||||
fmtUp = opts.format.trim().toUpperCase()
|
||||
freshVerRegex = require '../utils/fresh-version-regex'
|
||||
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
|
||||
if not _.contains ['FRESH','FRESCA','JRS','JRS@1','JRS@edge'], fmtUp
|
||||
@err HMSTATUS.invalidSchemaVersion, data: opts.format.trim(), quit: true
|
||||
targetSchema = matches[1]
|
||||
targetVer = matches[2] || '1'
|
||||
# freshVerRegex = require '../utils/fresh-version-regex'
|
||||
# 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 @hasError()
|
||||
@ -69,7 +71,7 @@ _convert = ( srcs, dst, opts ) ->
|
||||
results = _.map srcs, ( src, idx ) ->
|
||||
|
||||
# Convert each resume in turn
|
||||
r = _convertOne.call @, src, dst, idx, targetSchema, targetVer
|
||||
r = _convertOne.call @, src, dst, idx, fmtUp
|
||||
|
||||
# Handle conversion errors
|
||||
if r.fluenterror
|
||||
@ -88,7 +90,7 @@ _convert = ( srcs, dst, opts ) ->
|
||||
|
||||
|
||||
###* Private workhorse method. Convert a single resume. ###
|
||||
_convertOne = (src, dst, idx, targetSchema, targetVer) ->
|
||||
_convertOne = (src, dst, idx, targetSchema) ->
|
||||
|
||||
# Load the resume
|
||||
rinfo = ResumeFactory.loadOne src,
|
||||
@ -132,7 +134,7 @@ _convertOne = (src, dst, idx, targetSchema, targetVer) ->
|
||||
|
||||
# Save it to the destination format
|
||||
try
|
||||
rez.saveAs dst[idx], targetFormat, targetVer
|
||||
rez.saveAs dst[idx], targetFormat
|
||||
catch err
|
||||
if err.badVer
|
||||
return fluenterror: HMSTATUS.invalidSchemaVersion, quit: true, data: err.badVer
|
||||
|
Reference in New Issue
Block a user