mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-12-26 14:57:23 +00:00
Relocate internal sources to HackMyAPI.
Move internal sources and related tests to: https://github.com/hacksalot/HackMyAPI
This commit is contained in:
parent
fa29f9794d
commit
d3194fba19
21
package.json
21
package.json
@ -53,33 +53,14 @@
|
||||
"copy": "^0.1.3",
|
||||
"extend": "^3.0.0",
|
||||
"fresca": "~0.6.0",
|
||||
"fresh-jrs-converter": "^0.2.0",
|
||||
"fresh-resume-starter": "^0.2.2",
|
||||
"fresh-themes": "~0.13.0-beta",
|
||||
"fs-extra": "^0.24.0",
|
||||
"hackmyapi": "file:..\\HackMyAPI",
|
||||
"handlebars": "^4.0.5",
|
||||
"html": "0.0.10",
|
||||
"is-my-json-valid": "^2.12.2",
|
||||
"json-lint": "^0.1.0",
|
||||
"jst": "0.0.13",
|
||||
"lodash": "^3.10.1",
|
||||
"marked": "^0.3.5",
|
||||
"mkdirp": "^0.5.1",
|
||||
"moment": "^2.10.6",
|
||||
"parse-filepath": "^0.6.3",
|
||||
"path-exists": "^2.1.0",
|
||||
"printf": "^0.2.3",
|
||||
"recursive-readdir-sync": "^1.0.6",
|
||||
"simple-html-tokenizer": "^0.2.0",
|
||||
"slash": "^1.0.0",
|
||||
"string-padding": "^1.0.2",
|
||||
"string.prototype.endswith": "^0.2.0",
|
||||
"string.prototype.startswith": "^0.2.0",
|
||||
"traverse": "^0.6.6",
|
||||
"underscore": "^1.8.3",
|
||||
"webshot": "^0.16.0",
|
||||
"word-wrap": "^1.1.0",
|
||||
"xml-escape": "^1.0.0",
|
||||
"yamljs": "^0.2.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
@ -10,18 +10,18 @@ Error-handling routines for HackMyResume.
|
||||
|
||||
|
||||
|
||||
var HMSTATUS = require('../core/status-codes')
|
||||
var HMSTATUS = require('hackmyapi/src/core/status-codes')
|
||||
, PKG = require('../../package.json')
|
||||
, FS = require('fs')
|
||||
, FCMD = require('../hackmyapi')
|
||||
, FCMD = require('hackmyapi')
|
||||
, PATH = require('path')
|
||||
, WRAP = require('word-wrap')
|
||||
, M2C = require('../utils/md2chalk.js')
|
||||
, M2C = require('hackmyapi/src/utils/md2chalk.js')
|
||||
, chalk = require('chalk')
|
||||
, extend = require('extend')
|
||||
, YAML = require('yamljs')
|
||||
, printf = require('printf')
|
||||
, SyntaxErrorEx = require('../utils/syntax-error-ex');
|
||||
, SyntaxErrorEx = require('hackmyapi/src/utils/syntax-error-ex');
|
||||
require('string.prototype.startswith');
|
||||
|
||||
|
||||
|
@ -10,16 +10,16 @@ Definition of the `main` function.
|
||||
|
||||
|
||||
|
||||
var HMR = require( '../hackmyapi')
|
||||
var HMR = require( 'hackmyapi')
|
||||
, PKG = require('../../package.json')
|
||||
, FS = require('fs')
|
||||
, EXTEND = require('extend')
|
||||
, chalk = require('chalk')
|
||||
, PATH = require('path')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, HME = require('../core/event-codes')
|
||||
, safeLoadJSON = require('../utils/safe-json-loader')
|
||||
, StringUtils = require('../utils/string.js')
|
||||
, HMSTATUS = require('hackmyapi/src/core/status-codes')
|
||||
, HME = require('hackmyapi/src/core/event-codes')
|
||||
, safeLoadJSON = require('hackmyapi/src/utils/safe-json-loader')
|
||||
, StringUtils = require('hackmyapi/src/utils/string.js')
|
||||
, _ = require('underscore')
|
||||
, OUTPUT = require('./out')
|
||||
, PAD = require('string-padding')
|
||||
@ -143,8 +143,8 @@ Definition of the `main` function.
|
||||
_out.log(chalk.cyan(PAD(' Node.js:',25, null, PAD.RIGHT)) + chalk.cyan.bold( process.version ));
|
||||
_out.log(chalk.cyan(PAD(' HackMyResume:',25, null, PAD.RIGHT)) + chalk.cyan.bold('v' + PKG.version ));
|
||||
_out.log(chalk.cyan(PAD(' FRESCA:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies.fresca ));
|
||||
_out.log(chalk.cyan(PAD(' fresh-themes:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-themes'] ));
|
||||
_out.log(chalk.cyan(PAD(' fresh-jrs-converter:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-jrs-converter'] ));
|
||||
//_out.log(chalk.cyan(PAD(' fresh-themes:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-themes'] ));
|
||||
//_out.log(chalk.cyan(PAD(' fresh-jrs-converter:',25, null, PAD.RIGHT)) + chalk.cyan.bold( PKG.dependencies['fresh-jrs-converter'] ));
|
||||
_out.log('');
|
||||
}
|
||||
|
||||
|
@ -11,10 +11,10 @@ Output routines for HackMyResume.
|
||||
|
||||
|
||||
var chalk = require('chalk')
|
||||
, HME = require('../core/event-codes')
|
||||
, HME = require('hackmyapi/src/core/event-codes')
|
||||
, _ = require('underscore')
|
||||
, Class = require('../utils/class.js')
|
||||
, M2C = require('../utils/md2chalk.js')
|
||||
, Class = require('hackmyapi/src/utils/class.js')
|
||||
, M2C = require('hackmyapi/src/utils/md2chalk.js')
|
||||
, PATH = require('path')
|
||||
, LO = require('lodash')
|
||||
, FS = require('fs')
|
||||
|
@ -1,21 +0,0 @@
|
||||
(function(){
|
||||
|
||||
/**
|
||||
Supported resume formats.
|
||||
*/
|
||||
|
||||
module.exports = [
|
||||
|
||||
{ name: 'html', ext: 'html', gen: new (require('../generators/html-generator'))() },
|
||||
{ name: 'txt', ext: 'txt', gen: new (require('../generators/text-generator'))() },
|
||||
{ name: 'doc', ext: 'doc', fmt: 'xml', gen: new (require('../generators/word-generator'))() },
|
||||
{ name: 'pdf', ext: 'pdf', fmt: 'html', is: false, gen: new (require('../generators/html-pdf-cli-generator'))() },
|
||||
{ name: 'png', ext: 'png', fmt: 'html', is: false, gen: new (require('../generators/html-png-generator'))() },
|
||||
{ name: 'md', ext: 'md', fmt: 'txt', gen: new (require('../generators/markdown-generator'))() },
|
||||
{ name: 'json', ext: 'json', gen: new (require('../generators/json-generator'))() },
|
||||
{ name: 'yml', ext: 'yml', fmt: 'yml', gen: new (require('../generators/json-yaml-generator'))() },
|
||||
{ name: 'latex', ext: 'tex', fmt: 'latex', gen: new (require('../generators/latex-generator'))() }
|
||||
|
||||
];
|
||||
|
||||
}());
|
@ -1,13 +0,0 @@
|
||||
(function(){
|
||||
|
||||
module.exports = {
|
||||
theme: 'modern',
|
||||
prettify: { // ← See https://github.com/beautify-web/js-beautify#options
|
||||
indent_size: 2,
|
||||
unformatted: ['em','strong'],
|
||||
max_char: 80, // ← See lib/html.js in above-linked repo
|
||||
//wrap_line_length: 120, ← Don't use this
|
||||
}
|
||||
};
|
||||
|
||||
}());
|
@ -1,77 +0,0 @@
|
||||
{
|
||||
"basics": {
|
||||
"name": "",
|
||||
"label": "",
|
||||
"picture": "",
|
||||
"email": "",
|
||||
"phone": "",
|
||||
"degree": "",
|
||||
"website": "",
|
||||
"summary": "",
|
||||
"location": {
|
||||
"address": "",
|
||||
"postalCode": "",
|
||||
"city": "",
|
||||
"countryCode": "",
|
||||
"region": ""
|
||||
},
|
||||
"profiles": [{
|
||||
"network": "",
|
||||
"username": "",
|
||||
"url": ""
|
||||
}]
|
||||
},
|
||||
|
||||
"work": [{
|
||||
"company": "",
|
||||
"position": "",
|
||||
"website": "",
|
||||
"startDate": "",
|
||||
"endDate": "",
|
||||
"summary": "",
|
||||
"highlights": [
|
||||
""
|
||||
]
|
||||
}],
|
||||
|
||||
"awards": [{
|
||||
"title": "",
|
||||
"date": "",
|
||||
"awarder": "",
|
||||
"summary": ""
|
||||
}],
|
||||
|
||||
"education": [{
|
||||
"institution": "",
|
||||
"area": "",
|
||||
"studyType": "",
|
||||
"startDate": "",
|
||||
"endDate": "",
|
||||
"gpa": "",
|
||||
"courses": [ "" ]
|
||||
}],
|
||||
|
||||
"publications": [{
|
||||
"name": "",
|
||||
"publisher": "",
|
||||
"releaseDate": "",
|
||||
"website": "",
|
||||
"summary": ""
|
||||
}],
|
||||
|
||||
"volunteer": [{
|
||||
"organization": "",
|
||||
"position": "",
|
||||
"website": "",
|
||||
"startDate": "",
|
||||
"endDate": "",
|
||||
"summary": "",
|
||||
"highlights": [ "" ]
|
||||
}],
|
||||
|
||||
"skills": [{
|
||||
"name": "",
|
||||
"level": "",
|
||||
"keywords": [""]
|
||||
}]
|
||||
}
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
Event code definitions.
|
||||
@module event-codes.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function(){
|
||||
|
||||
var val = 0;
|
||||
|
||||
module.exports = {
|
||||
|
||||
error: -1,
|
||||
success: 0,
|
||||
begin: 1,
|
||||
end: 2,
|
||||
beforeRead: 3,
|
||||
afterRead: 4,
|
||||
beforeCreate: 5,
|
||||
afterCreate: 6,
|
||||
beforeTheme: 7,
|
||||
afterTheme: 8,
|
||||
beforeMerge: 9,
|
||||
afterMerge: 10,
|
||||
beforeGenerate: 11,
|
||||
afterGenerate: 12,
|
||||
beforeAnalyze: 13,
|
||||
afterAnalyze: 14,
|
||||
beforeConvert: 15,
|
||||
afterConvert: 16,
|
||||
verifyOutputs: 17,
|
||||
beforeParse: 18,
|
||||
afterParse: 19,
|
||||
beforePeek: 20,
|
||||
afterPeek: 21,
|
||||
beforeInlineConvert: 22,
|
||||
afterInlineConvert: 23,
|
||||
beforeValidate: 24,
|
||||
afterValidate: 25
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,95 +0,0 @@
|
||||
/**
|
||||
The HackMyResume date representation.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module core/fluent-date
|
||||
*/
|
||||
|
||||
(function(){
|
||||
|
||||
var moment = require('moment');
|
||||
|
||||
/**
|
||||
Create a FluentDate from a string or Moment date object. There are a few date
|
||||
formats to be aware of here.
|
||||
1. The words "Present" and "Now", referring to the current date
|
||||
2. The default "YYYY-MM-DD" format used in JSON Resume ("2015-02-10")
|
||||
3. Year-and-month only ("2015-04")
|
||||
4. Year-only "YYYY" ("2015")
|
||||
5. The friendly HackMyResume "mmm YYYY" format ("Mar 2015" or "Dec 2008")
|
||||
6. Empty dates ("", " ")
|
||||
7. Any other date format that Moment.js can parse from
|
||||
Note: Moment can transparently parse all or most of these, without requiring us
|
||||
to specify a date format...but for maximum parsing safety and to avoid Moment
|
||||
deprecation warnings, it's recommended to either a) explicitly specify the date
|
||||
format or b) use an ISO format. For clarity, we handle these cases explicitly.
|
||||
@class FluentDate
|
||||
*/
|
||||
function FluentDate( dt ) {
|
||||
this.rep = this.fmt( dt );
|
||||
}
|
||||
|
||||
FluentDate/*.prototype*/.fmt = function( dt, throws ) {
|
||||
|
||||
throws = (throws === undefined || throws === null) || throws;
|
||||
|
||||
if( (typeof dt === 'string' || dt instanceof String) ) {
|
||||
dt = dt.toLowerCase().trim();
|
||||
if( /^(present|now|current)$/.test(dt) ) { // "Present", "Now"
|
||||
return moment();
|
||||
}
|
||||
else if( /^\D+\s+\d{4}$/.test(dt) ) { // "Mar 2015"
|
||||
var parts = dt.split(' ');
|
||||
var month = (months[parts[0]] || abbr[parts[0]]);
|
||||
var temp = parts[1] + '-' + (month < 10 ? '0' + month : month.toString());
|
||||
return moment( temp, 'YYYY-MM' );
|
||||
}
|
||||
else if( /^\d{4}-\d{1,2}$/.test(dt) ) { // "2015-03", "1998-4"
|
||||
return moment( dt, 'YYYY-MM' );
|
||||
}
|
||||
else if( /^\s*\d{4}\s*$/.test(dt) ) { // "2015"
|
||||
return moment( dt, 'YYYY' );
|
||||
}
|
||||
else if( /^\s*$/.test(dt) ) { // "", " "
|
||||
var defTime = {
|
||||
isNull: true,
|
||||
isBefore: function( other ) {
|
||||
return( other && !other.isNull ) ? true : false;
|
||||
},
|
||||
isAfter: function( other ) {
|
||||
return( other && !other.isNull ) ? false : false;
|
||||
},
|
||||
unix: function() { return 0; },
|
||||
format: function() { return ''; },
|
||||
diff: function() { return 0; }
|
||||
};
|
||||
return defTime;
|
||||
}
|
||||
else {
|
||||
var mt = moment( dt );
|
||||
if(mt.isValid())
|
||||
return mt;
|
||||
if( throws )
|
||||
throw 'Invalid date format encountered.';
|
||||
return null;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if( !dt ) {
|
||||
return moment();
|
||||
}
|
||||
else if( dt.isValid && dt.isValid() )
|
||||
return dt;
|
||||
if( throws )
|
||||
throw 'Unknown date object encountered.';
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
var months = {}, abbr = {};
|
||||
moment.months().forEach(function(m,idx){months[m.toLowerCase()]=idx+1;});
|
||||
moment.monthsShort().forEach(function(m,idx){abbr[m.toLowerCase()]=idx+1;});
|
||||
abbr.sept = 9;
|
||||
|
||||
module.exports = FluentDate;
|
||||
|
||||
}());
|
@ -1,526 +0,0 @@
|
||||
/**
|
||||
Definition of the FRESHResume class.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module core/fresh-resume
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var FS = require('fs')
|
||||
, extend = require('extend')
|
||||
, validator = require('is-my-json-valid')
|
||||
, _ = require('underscore')
|
||||
, __ = require('lodash')
|
||||
, PATH = require('path')
|
||||
, moment = require('moment')
|
||||
, XML = require('xml-escape')
|
||||
, MD = require('marked')
|
||||
, CONVERTER = require('fresh-jrs-converter')
|
||||
, JRSResume = require('./jrs-resume');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
A FRESH resume or CV. FRESH resumes are backed by JSON, and each FreshResume
|
||||
object is an instantiation of that JSON decorated with utility methods.
|
||||
@constructor
|
||||
*/
|
||||
function FreshResume() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Initialize the FreshResume from file.
|
||||
*/
|
||||
FreshResume.prototype.open = function( file, opts ) {
|
||||
var raw = FS.readFileSync( file, 'utf8' );
|
||||
var ret = this.parse( raw, opts );
|
||||
this.imp.file = file;
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Initialize the the FreshResume from JSON string data.
|
||||
*/
|
||||
FreshResume.prototype.parse = function( stringData, opts ) {
|
||||
return this.parseJSON( JSON.parse( stringData ), opts );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Initialize the FreshResume from JSON.
|
||||
Open and parse the specified FRESH 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.
|
||||
}
|
||||
*/
|
||||
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, 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
|
||||
if( !this.imp ) {
|
||||
// Set up metadata TODO: Clean up metadata on the object model.
|
||||
opts = opts || { };
|
||||
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 );
|
||||
(opts.sort === undefined || opts.sort) && this.sort();
|
||||
(opts.compute === undefined || opts.compute) && (this.computed = {
|
||||
numYears: this.duration(),
|
||||
keywords: this.keywords()
|
||||
});
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Save the sheet to disk (for environments that have disk access).
|
||||
*/
|
||||
FreshResume.prototype.save = function( filename ) {
|
||||
this.imp.file = filename || this.imp.file;
|
||||
FS.writeFileSync( this.imp.file, this.stringify(), 'utf8' );
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Save the sheet to disk in a specific format, either FRESH or JSON Resume.
|
||||
*/
|
||||
FreshResume.prototype.saveAs = function( filename, format ) {
|
||||
|
||||
if( format !== 'JRS' ) {
|
||||
this.imp.file = filename || this.imp.file;
|
||||
FS.writeFileSync( this.imp.file, this.stringify(), 'utf8' );
|
||||
}
|
||||
else {
|
||||
var newRep = CONVERTER.toJRS( this );
|
||||
FS.writeFileSync( filename, JRSResume.stringify( newRep ), 'utf8' );
|
||||
}
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Duplicate this FreshResume instance.
|
||||
This method first extend()s this object onto an empty, creating a deep copy,
|
||||
and then passes the result into a new FreshResume instance via .parseJSON.
|
||||
We do it this way to create a true clone of the object without re-running any
|
||||
of the associated processing.
|
||||
*/
|
||||
FreshResume.prototype.dupe = function() {
|
||||
var jso = extend( true, { }, this );
|
||||
var rnew = new FreshResume();
|
||||
rnew.parseJSON( jso, { } );
|
||||
return rnew;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Convert the supplied FreshResume to a JSON string, sanitizing meta-properties
|
||||
along the way.
|
||||
*/
|
||||
FreshResume.stringify = function( obj ) {
|
||||
function replacer( key,value ) { // Exclude these keys from stringification
|
||||
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
|
||||
'safe', 'result', 'isModified', 'htmlPreview', 'display_progress_bar'],
|
||||
function( val ) { return key.trim() === val; }
|
||||
) ? undefined : value;
|
||||
}
|
||||
return JSON.stringify( obj, replacer, 2 );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Convert this object to a JSON string, sanitizing meta-properties along the
|
||||
way.
|
||||
*/
|
||||
FreshResume.prototype.stringify = function() {
|
||||
return FreshResume.stringify( this );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Create a copy of this resume in which all string fields have been run through
|
||||
a transformation function (such as a Markdown filter or XML encoder).
|
||||
TODO: Move this out of FRESHResume.
|
||||
*/
|
||||
FreshResume.prototype.transformStrings = function( filt, transformer ) {
|
||||
var ret = this.dupe();
|
||||
var trx = require('../utils/string-transformer');
|
||||
return trx( ret, filt, transformer );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Create a copy of this resume in which all fields have been interpreted as
|
||||
Markdown.
|
||||
*/
|
||||
FreshResume.prototype.markdownify = function() {
|
||||
|
||||
function MDIN( txt ){
|
||||
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
||||
}
|
||||
|
||||
function trx(key, val) {
|
||||
if( key === 'summary' ) {
|
||||
return MD(val);
|
||||
}
|
||||
return MDIN(val);
|
||||
}
|
||||
|
||||
return this.transformStrings( ['skills','url','start','end','date'], trx );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Create a copy of this resume in which all fields have been interpreted as
|
||||
Markdown.
|
||||
*/
|
||||
FreshResume.prototype.xmlify = function() {
|
||||
function trx(key, val) {
|
||||
return XML(val);
|
||||
}
|
||||
return this.transformStrings( [], trx );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return the resume format.
|
||||
*/
|
||||
FreshResume.prototype.format = function() {
|
||||
return 'FRESH';
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return internal metadata. Create if it doesn't exist.
|
||||
*/
|
||||
FreshResume.prototype.i = function() {
|
||||
this.imp = (this.imp || { });
|
||||
return this.imp;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return a unique list of all keywords across all skills.
|
||||
*/
|
||||
FreshResume.prototype.keywords = function() {
|
||||
var flatSkills = [];
|
||||
if( this.skills ) {
|
||||
if( this.skills.sets ) {
|
||||
flatSkills = this.skills.sets.map(function(sk) { return sk.skills; })
|
||||
.reduce(function(a,b) { return a.concat(b); });
|
||||
}
|
||||
else if( this.skills.list ) {
|
||||
flatSkills = flatSkills.concat( this.skills.list.map(function(sk) {
|
||||
return sk.name;
|
||||
}));
|
||||
}
|
||||
flatSkills = _.uniq( flatSkills );
|
||||
}
|
||||
return flatSkills;
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Reset the sheet to an empty state. TODO: refactor/review
|
||||
*/
|
||||
FreshResume.prototype.clear = function( clearMeta ) {
|
||||
clearMeta = ((clearMeta === undefined) && true) || clearMeta;
|
||||
clearMeta && (delete this.imp);
|
||||
delete this.computed; // Don't use Object.keys() here
|
||||
delete this.employment;
|
||||
delete this.service;
|
||||
delete this.education;
|
||||
delete this.recognition;
|
||||
delete this.reading;
|
||||
delete this.writing;
|
||||
delete this.interests;
|
||||
delete this.skills;
|
||||
delete this.social;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Get a safe count of the number of things in a section.
|
||||
*/
|
||||
FreshResume.prototype.count = function( obj ) {
|
||||
if( !obj ) return 0;
|
||||
if( obj.history ) return obj.history.length;
|
||||
if( obj.sets ) return obj.sets.length;
|
||||
return obj.length || 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Get the default (starter) sheet.
|
||||
*/
|
||||
FreshResume.default = function() {
|
||||
return new FreshResume().parseJSON( require('fresh-resume-starter') );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Add work experience to the sheet.
|
||||
*/
|
||||
FreshResume.prototype.add = function( moniker ) {
|
||||
var defSheet = FreshResume.default();
|
||||
var newObject = defSheet[moniker].history ?
|
||||
$.extend( true, {}, defSheet[ moniker ].history[0] ) :
|
||||
(moniker === 'skills' ?
|
||||
$.extend( true, {}, defSheet.skills.sets[0] ) :
|
||||
$.extend( true, {}, defSheet[ moniker ][0] ));
|
||||
this[ moniker ] = this[ moniker ] || [];
|
||||
if( this[ moniker ].history )
|
||||
this[ moniker ].history.push( newObject );
|
||||
else if( moniker === 'skills' )
|
||||
this.skills.sets.push( newObject );
|
||||
else
|
||||
this[ moniker ].push( newObject );
|
||||
return newObject;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Determine if the sheet includes a specific social profile (eg, GitHub).
|
||||
*/
|
||||
FreshResume.prototype.hasProfile = function( socialNetwork ) {
|
||||
socialNetwork = socialNetwork.trim().toLowerCase();
|
||||
return this.social && _.some( this.social, function(p) {
|
||||
return p.network.trim().toLowerCase() === socialNetwork;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return the specified network profile.
|
||||
*/
|
||||
FreshResume.prototype.getProfile = function( socialNetwork ) {
|
||||
socialNetwork = socialNetwork.trim().toLowerCase();
|
||||
return this.social && _.find( this.social, function(sn) {
|
||||
return sn.network.trim().toLowerCase() === socialNetwork;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return an array of profiles for the specified network, for when the user
|
||||
has multiple eg. GitHub accounts.
|
||||
*/
|
||||
FreshResume.prototype.getProfiles = function( socialNetwork ) {
|
||||
socialNetwork = socialNetwork.trim().toLowerCase();
|
||||
return this.social && _.filter( this.social, function(sn){
|
||||
return sn.network.trim().toLowerCase() === socialNetwork;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Determine if the sheet includes a specific skill.
|
||||
*/
|
||||
FreshResume.prototype.hasSkill = function( skill ) {
|
||||
skill = skill.trim().toLowerCase();
|
||||
return this.skills && _.some( this.skills, function(sk) {
|
||||
return sk.keywords && _.some( sk.keywords, function(kw) {
|
||||
return kw.trim().toLowerCase() === skill;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Validate the sheet against the FRESH Resume schema.
|
||||
*/
|
||||
FreshResume.prototype.isValid = function( info ) {
|
||||
var schemaObj = require('fresca');
|
||||
var validator = require('is-my-json-valid');
|
||||
var validate = validator( schemaObj, { // See Note [1].
|
||||
formats: { date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/ }
|
||||
});
|
||||
var ret = validate( this );
|
||||
if( !ret ) {
|
||||
this.imp = this.imp || { };
|
||||
this.imp.validationErrors = validate.errors;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Calculate the total duration of the sheet. Assumes this.work has been sorted
|
||||
by start date descending, perhaps via a call to Sheet.sort().
|
||||
@returns The total duration of the sheet's work history, that is, the number
|
||||
of years between the start date of the earliest job on the resume and the
|
||||
*latest end date of all jobs in the work history*. This last condition is for
|
||||
sheets that have overlapping jobs.
|
||||
*/
|
||||
FreshResume.prototype.duration = function(unit) {
|
||||
unit = unit || 'years';
|
||||
var empHist = __.get(this, 'employment.history');
|
||||
if( empHist && empHist.length ) {
|
||||
var firstJob = _.last( empHist );
|
||||
var careerStart = firstJob.start ? firstJob.safe.start : '';
|
||||
if ((typeof careerStart === 'string' || careerStart instanceof String) &&
|
||||
!careerStart.trim())
|
||||
return 0;
|
||||
var careerLast = _.max( empHist, function( w ) {
|
||||
return( w.safe && w.safe.end ) ? w.safe.end.unix() : moment().unix();
|
||||
});
|
||||
return careerLast.safe.end.diff( careerStart, unit );
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Sort dated things on the sheet by start date descending. Assumes that dates
|
||||
on the sheet have been processed with _parseDates().
|
||||
*/
|
||||
FreshResume.prototype.sort = function( ) {
|
||||
|
||||
function byDateDesc(a,b) {
|
||||
return( a.safe.start.isBefore(b.safe.start) ) ? 1
|
||||
: ( a.safe.start.isAfter(b.safe.start) && -1 ) || 0;
|
||||
}
|
||||
|
||||
function sortSection( key ) {
|
||||
var ar = __.get(this, key);
|
||||
if( ar && ar.length ) {
|
||||
var datedThings = obj.filter( function(o) { return o.start; } );
|
||||
datedThings.sort( byDateDesc );
|
||||
}
|
||||
}
|
||||
|
||||
sortSection( 'employment.history' );
|
||||
sortSection( 'education.history' );
|
||||
sortSection( 'service.history' );
|
||||
sortSection( 'projects' );
|
||||
|
||||
// this.awards && this.awards.sort( function(a, b) {
|
||||
// return( a.safeDate.isBefore(b.safeDate) ) ? 1
|
||||
// : ( a.safeDate.isAfter(b.safeDate) && -1 ) || 0;
|
||||
// });
|
||||
this.writing && this.writing.sort( function(a, b) {
|
||||
return( a.safe.date.isBefore(b.safe.date) ) ? 1
|
||||
: ( a.safe.date.isAfter(b.safe.date) && -1 ) || 0;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Convert human-friendly dates into formal Moment.js dates for all collections.
|
||||
We don't want to lose the raw textual date as entered by the user, so we store
|
||||
the Moment-ified date as a separate property with a prefix of .safe. For ex:
|
||||
job.startDate is the date as entered by the user. job.safeStartDate is the
|
||||
parsed Moment.js date that we actually use in processing.
|
||||
*/
|
||||
function _parseDates() {
|
||||
|
||||
var _fmt = require('./fluent-date').fmt;
|
||||
var that = this;
|
||||
|
||||
// TODO: refactor recursion
|
||||
function replaceDatesInObject( obj ) {
|
||||
|
||||
if( !obj ) return;
|
||||
if( Object.prototype.toString.call( obj ) === '[object Array]' ) {
|
||||
obj.forEach(function(elem){
|
||||
replaceDatesInObject( elem );
|
||||
});
|
||||
}
|
||||
else if (typeof obj === 'object') {
|
||||
if( obj._isAMomentObject || obj.safe )
|
||||
return;
|
||||
Object.keys( obj ).forEach(function(key) {
|
||||
replaceDatesInObject( obj[key] );
|
||||
});
|
||||
['start','end','date'].forEach( function(val) {
|
||||
if( (obj[val] !== undefined) && (!obj.safe || !obj.safe[val] )) {
|
||||
obj.safe = obj.safe || { };
|
||||
obj.safe[ val ] = _fmt( obj[val] );
|
||||
if( obj[val] && (val === 'start') && !obj.end ) {
|
||||
obj.safe.end = _fmt('current');
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Object.keys( this ).forEach(function(member){
|
||||
replaceDatesInObject( that[ member ] );
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Export the Sheet function/ctor.
|
||||
*/
|
||||
module.exports = FreshResume;
|
||||
|
||||
|
||||
|
||||
}());
|
||||
|
||||
// Note 1: Adjust default date validation to allow YYYY and YYYY-MM formats
|
||||
// in addition to YYYY-MM-DD. The original regex:
|
||||
//
|
||||
// /^\d{4}-(?:0[0-9]{1}|1[0-2]{1})-[0-9]{2}$/
|
||||
//
|
@ -1,338 +0,0 @@
|
||||
/**
|
||||
Definition of the FRESHTheme class.
|
||||
@module fresh-theme.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var FS = require('fs')
|
||||
, validator = require('is-my-json-valid')
|
||||
, _ = require('underscore')
|
||||
, PATH = require('path')
|
||||
, parsePath = require('parse-filepath')
|
||||
, pathExists = require('path-exists').sync
|
||||
, EXTEND = require('extend')
|
||||
, HMSTATUS = require('./status-codes')
|
||||
, moment = require('moment')
|
||||
, loadSafeJson = require('../utils/safe-json-loader')
|
||||
, READFILES = require('recursive-readdir-sync');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
The FRESHTheme class is a representation of a FRESH theme
|
||||
asset. See also: JRSTheme.
|
||||
@class FRESHTheme
|
||||
*/
|
||||
function FRESHTheme() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Open and parse the specified theme.
|
||||
*/
|
||||
FRESHTheme.prototype.open = function( themeFolder ) {
|
||||
|
||||
this.folder = themeFolder;
|
||||
|
||||
// Open the [theme-name].json file; should have the same name as folder
|
||||
var pathInfo = parsePath( themeFolder );
|
||||
|
||||
// Set up a formats hash for the theme
|
||||
var formatsHash = { };
|
||||
|
||||
// Load the theme
|
||||
var themeFile = PATH.join( themeFolder, 'theme.json' );
|
||||
var themeInfo = loadSafeJson( themeFile );
|
||||
if( themeInfo.ex ) throw {
|
||||
fluenterror: themeInfo.ex.operation === 'parse' ?
|
||||
HMSTATUS.parseError : HMSTATUS.readError,
|
||||
inner: themeInfo.ex.inner
|
||||
};
|
||||
|
||||
var that = this;
|
||||
|
||||
// Move properties from the theme JSON file to the theme object
|
||||
EXTEND( true, this, themeInfo.json );
|
||||
|
||||
// Check for an "inherits" entry in the theme JSON.
|
||||
if( this.inherits ) {
|
||||
var cached = { };
|
||||
_.each( this.inherits, function(th, key) {
|
||||
var themesFolder = require.resolve('fresh-themes');
|
||||
var d = parsePath( themeFolder ).dirname;
|
||||
var themePath = PATH.join(d, th);
|
||||
cached[ th ] = cached[th] || new FRESHTheme().open( themePath );
|
||||
formatsHash[ key ] = cached[ th ].getFormat( key );
|
||||
});
|
||||
}
|
||||
|
||||
// Check for an explicit "formats" entry in the theme JSON. If it has one,
|
||||
// then this theme declares its files explicitly.
|
||||
if( !!this.formats ) {
|
||||
formatsHash = loadExplicit.call( this, formatsHash );
|
||||
this.explicit = true;
|
||||
}
|
||||
else {
|
||||
formatsHash = loadImplicit.call( this, formatsHash );
|
||||
}
|
||||
|
||||
// Cache
|
||||
this.formats = formatsHash;
|
||||
|
||||
// Set the official theme name
|
||||
this.name = parsePath( this.folder ).name;
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Determine if the theme supports the specified output format.
|
||||
*/
|
||||
FRESHTheme.prototype.hasFormat = function( fmt ) {
|
||||
return _.has( this.formats, fmt );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Determine if the theme supports the specified output format.
|
||||
*/
|
||||
FRESHTheme.prototype.getFormat = function( fmt ) {
|
||||
return this.formats[ fmt ];
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Load the theme implicitly, by scanning the theme folder for
|
||||
files. TODO: Refactor duplicated code with loadExplicit.
|
||||
*/
|
||||
function loadImplicit(formatsHash) {
|
||||
|
||||
// Set up a hash of formats supported by this theme.
|
||||
var that = this;
|
||||
var major = false;
|
||||
|
||||
// Establish the base theme folder
|
||||
var tplFolder = PATH.join( this.folder, 'src' );
|
||||
|
||||
// Iterate over all files in the theme folder, producing an array, fmts,
|
||||
// containing info for each file. While we're doing that, also build up
|
||||
// the formatsHash object.
|
||||
var fmts = READFILES(tplFolder).map( function(absPath) {
|
||||
|
||||
// If this file lives in a specific format folder within the theme,
|
||||
// such as "/latex" or "/html", then that format is the output format
|
||||
// for all files within the folder.
|
||||
var pathInfo = parsePath(absPath);
|
||||
var outFmt = '', isMajor = false;
|
||||
var portion = pathInfo.dirname.replace(tplFolder,'');
|
||||
if( portion && portion.trim() ) {
|
||||
if( portion[1] === '_' ) return;
|
||||
var reg = /^(?:\/|\\)(html|latex|doc|pdf|png|partials)(?:\/|\\)?/ig;
|
||||
var res = reg.exec( portion );
|
||||
if( res ) {
|
||||
if( res[1] !== 'partials' ) {
|
||||
outFmt = res[1];
|
||||
}
|
||||
else {
|
||||
that.partials = that.partials || [];
|
||||
that.partials.push( { name: pathInfo.name, path: absPath } );
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, the output format is inferred from the filename, as in
|
||||
// compact-[outputformat].[extension], for ex, compact-pdf.html.
|
||||
if( !outFmt ) {
|
||||
var idx = pathInfo.name.lastIndexOf('-');
|
||||
outFmt = (idx === -1) ? pathInfo.name : pathInfo.name.substr(idx + 1);
|
||||
isMajor = true;
|
||||
}
|
||||
|
||||
// We should have a valid output format now.
|
||||
formatsHash[ outFmt ] = formatsHash[outFmt] || {
|
||||
outFormat: outFmt,
|
||||
files: []
|
||||
};
|
||||
|
||||
// Create the file representation object.
|
||||
var obj = {
|
||||
action: 'transform',
|
||||
path: absPath,
|
||||
major: isMajor,
|
||||
orgPath: PATH.relative(tplFolder, absPath),
|
||||
ext: pathInfo.extname.slice(1),
|
||||
title: friendlyName( outFmt ),
|
||||
pre: outFmt,
|
||||
// outFormat: outFmt || pathInfo.name,
|
||||
data: FS.readFileSync( absPath, 'utf8' ),
|
||||
css: null
|
||||
};
|
||||
|
||||
// Add this file to the list of files for this format type.
|
||||
formatsHash[ outFmt ].files.push( obj );
|
||||
return obj;
|
||||
});
|
||||
|
||||
// Now, get all the CSS files...
|
||||
(this.cssFiles = fmts.filter(function( fmt ){
|
||||
return fmt && (fmt.ext === 'css');
|
||||
}))
|
||||
|
||||
// For each CSS file, get its corresponding HTML file. It's possible that
|
||||
// a theme can have a CSS file but *no* HTML file, as when a theme author
|
||||
// creates a pure CSS override of an existing theme.
|
||||
.forEach(function( cssf ) {
|
||||
|
||||
var idx = _.findIndex(fmts, function( fmt ) {
|
||||
return fmt && fmt.pre === cssf.pre && fmt.ext === 'html';
|
||||
});
|
||||
cssf.major = false;
|
||||
if( idx > -1) {
|
||||
fmts[ idx ].css = cssf.data;
|
||||
fmts[ idx ].cssPath = cssf.path;
|
||||
}
|
||||
else {
|
||||
if( that.inherits ) {
|
||||
// Found a CSS file without an HTML file in a theme that inherits
|
||||
// from another theme. This is the override CSS file.
|
||||
that.overrides = { file: cssf.path, data: cssf.data };
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return formatsHash;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Load the theme explicitly, by following the 'formats' hash
|
||||
in the theme's JSON settings file.
|
||||
*/
|
||||
function loadExplicit(formatsHash) {
|
||||
|
||||
// Housekeeping
|
||||
var tplFolder = PATH.join( this.folder, 'src' );
|
||||
var act = null;
|
||||
var that = this;
|
||||
|
||||
// Iterate over all files in the theme folder, producing an array, fmts,
|
||||
// containing info for each file. While we're doing that, also build up
|
||||
// the formatsHash object.
|
||||
var fmts = READFILES( tplFolder ).map( function( absPath ) {
|
||||
|
||||
act = null;
|
||||
// If this file is mentioned in the theme's JSON file under "transforms"
|
||||
var pathInfo = parsePath(absPath);
|
||||
var absPathSafe = absPath.trim().toLowerCase();
|
||||
var outFmt = _.find(
|
||||
Object.keys( that.formats ),
|
||||
function( fmtKey ) {
|
||||
var fmtVal = that.formats[ fmtKey ];
|
||||
return _.some( fmtVal.transform, function(fpath) {
|
||||
var absPathB = PATH.join( that.folder, fpath )
|
||||
.trim().toLowerCase();
|
||||
return absPathB === absPathSafe;
|
||||
});
|
||||
});
|
||||
if( outFmt ) {
|
||||
act = 'transform';
|
||||
}
|
||||
|
||||
// If this file lives in a specific format folder within the theme,
|
||||
// such as "/latex" or "/html", then that format is the output format
|
||||
// for all files within the folder.
|
||||
if( !outFmt ) {
|
||||
var portion = pathInfo.dirname.replace(tplFolder,'');
|
||||
if( portion && portion.trim() ) {
|
||||
var reg = /^(?:\/|\\)(html|latex|doc|pdf)(?:\/|\\)?/ig;
|
||||
var res = reg.exec( portion );
|
||||
res && (outFmt = res[1]);
|
||||
}
|
||||
}
|
||||
|
||||
// Otherwise, the output format is inferred from the filename, as in
|
||||
// compact-[outputformat].[extension], for ex, compact-pdf.html.
|
||||
if( !outFmt ) {
|
||||
var idx = pathInfo.name.lastIndexOf('-');
|
||||
outFmt = (idx === -1) ? pathInfo.name : pathInfo.name.substr(idx + 1);
|
||||
}
|
||||
|
||||
// We should have a valid output format now.
|
||||
formatsHash[ outFmt ] =
|
||||
formatsHash[ outFmt ] || {
|
||||
outFormat: outFmt,
|
||||
files: [],
|
||||
symLinks: that.formats[ outFmt ].symLinks
|
||||
};
|
||||
|
||||
// Create the file representation object.
|
||||
var obj = {
|
||||
action: act,
|
||||
orgPath: PATH.relative(that.folder, absPath),
|
||||
path: absPath,
|
||||
ext: pathInfo.extname.slice(1),
|
||||
title: friendlyName( outFmt ),
|
||||
pre: outFmt,
|
||||
// outFormat: outFmt || pathInfo.name,
|
||||
data: FS.readFileSync( absPath, 'utf8' ),
|
||||
css: null
|
||||
};
|
||||
|
||||
// Add this file to the list of files for this format type.
|
||||
formatsHash[ outFmt ].files.push( obj );
|
||||
return obj;
|
||||
});
|
||||
|
||||
// Now, get all the CSS files...
|
||||
(this.cssFiles = fmts.filter(function( fmt ){
|
||||
return fmt.ext === 'css';
|
||||
}))
|
||||
|
||||
// For each CSS file, get its corresponding HTML file
|
||||
.forEach(function( cssf ) {
|
||||
// For each CSS file, get its corresponding HTML file
|
||||
var idx = _.findIndex(fmts, function( fmt ) {
|
||||
return fmt.pre === cssf.pre && fmt.ext === 'html';
|
||||
});
|
||||
fmts[ idx ].css = cssf.data;
|
||||
fmts[ idx ].cssPath = cssf.path;
|
||||
});
|
||||
|
||||
// Remove CSS files from the formats array
|
||||
fmts = fmts.filter( function( fmt) {
|
||||
return fmt.ext !== 'css';
|
||||
});
|
||||
|
||||
return formatsHash;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return a more friendly name for certain formats.
|
||||
TODO: Refactor
|
||||
*/
|
||||
function friendlyName( val ) {
|
||||
val = val.trim().toLowerCase();
|
||||
var friendly = { yml: 'yaml', md: 'markdown', txt: 'text' };
|
||||
return friendly[val] || val;
|
||||
}
|
||||
|
||||
|
||||
|
||||
module.exports = FRESHTheme;
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,454 +0,0 @@
|
||||
/**
|
||||
Definition of the JRSResume class.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module core/jrs-resume
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var FS = require('fs')
|
||||
, extend = require('extend')
|
||||
, validator = require('is-my-json-valid')
|
||||
, _ = require('underscore')
|
||||
, PATH = require('path')
|
||||
, MD = require('marked')
|
||||
, CONVERTER = require('fresh-jrs-converter')
|
||||
, moment = require('moment');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
A JRS resume or CV. JRS resumes are backed by JSON, and each JRSResume object
|
||||
is an instantiation of that JSON decorated with utility methods.
|
||||
@class JRSResume
|
||||
*/
|
||||
function JRSResume() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Initialize the JSResume from file.
|
||||
*/
|
||||
JRSResume.prototype.open = function( file, title ) {
|
||||
//this.imp = { fileName: file }; <-- schema violation, tuck it into .basics
|
||||
this.basics = {
|
||||
imp: {
|
||||
file: file,
|
||||
raw: FS.readFileSync( file, 'utf8' )
|
||||
}
|
||||
};
|
||||
return this.parse( this.basics.imp.raw, title );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Initialize the the JSResume from string.
|
||||
*/
|
||||
JRSResume.prototype.parse = function( stringData, opts ) {
|
||||
opts = opts || { };
|
||||
var rep = JSON.parse( stringData );
|
||||
return this.parseJSON( rep, opts );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
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 || { };
|
||||
|
||||
// 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 || { };
|
||||
this.basics.imp.title =
|
||||
(opts.title || this.basics.imp.title) || this.basics.name;
|
||||
this.basics.imp.orgFormat = 'JRS';
|
||||
}
|
||||
// Parse dates, sort dates, and calculate computed values
|
||||
(opts.date === undefined || opts.date) && _parseDates.call( this );
|
||||
(opts.sort === undefined || opts.sort) && this.sort();
|
||||
(opts.compute === undefined || opts.compute) && (this.basics.computed = {
|
||||
numYears: this.duration(),
|
||||
keywords: this.keywords()
|
||||
});
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Save the sheet to disk (for environments that have disk access).
|
||||
*/
|
||||
JRSResume.prototype.save = function( filename ) {
|
||||
this.basics.imp.file = filename || this.basics.imp.file;
|
||||
FS.writeFileSync(this.basics.imp.file, this.stringify( this ), 'utf8');
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Save the sheet to disk in a specific format, either FRESH or JRS.
|
||||
*/
|
||||
JRSResume.prototype.saveAs = function( filename, format ) {
|
||||
|
||||
if( format === 'JRS' ) {
|
||||
this.basics.imp.file = filename || this.basics.imp.file;
|
||||
FS.writeFileSync( this.basics.imp.file, this.stringify(), 'utf8' );
|
||||
}
|
||||
else {
|
||||
var newRep = CONVERTER.toFRESH( this );
|
||||
var stringRep = CONVERTER.toSTRING( newRep );
|
||||
FS.writeFileSync( filename, stringRep, 'utf8' );
|
||||
}
|
||||
return this;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return the resume format.
|
||||
*/
|
||||
JRSResume.prototype.format = function() {
|
||||
return 'JRS';
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Convert this object to a JSON string, sanitizing meta-properties along the
|
||||
way. Don't override .toString().
|
||||
*/
|
||||
JRSResume.stringify = function( obj ) {
|
||||
function replacer( key,value ) { // Exclude these keys from stringification
|
||||
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
|
||||
'safeStartDate', 'safeEndDate', 'safeDate', 'safeReleaseDate', 'result',
|
||||
'isModified', 'htmlPreview', 'display_progress_bar'],
|
||||
function( val ) { return key.trim() === val; }
|
||||
) ? undefined : value;
|
||||
}
|
||||
return JSON.stringify( obj, replacer, 2 );
|
||||
};
|
||||
|
||||
|
||||
|
||||
JRSResume.prototype.stringify = function() {
|
||||
return JRSResume.stringify( this );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return a unique list of all keywords across all skills.
|
||||
*/
|
||||
JRSResume.prototype.keywords = function() {
|
||||
var flatSkills = [];
|
||||
if( this.skills && this.skills.length ) {
|
||||
this.skills.forEach( function( s ) {
|
||||
flatSkills = _.union( flatSkills, s.keywords );
|
||||
});
|
||||
}
|
||||
return flatSkills;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return internal metadata. Create if it doesn't exist.
|
||||
JSON Resume v0.0.0 doesn't allow additional properties at the root level,
|
||||
so tuck this into the .basic sub-object.
|
||||
*/
|
||||
JRSResume.prototype.i = function() {
|
||||
this.basics = this.basics || { };
|
||||
this.basics.imp = this.basics.imp || { };
|
||||
return this.basics.imp;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Reset the sheet to an empty state.
|
||||
*/
|
||||
JRSResume.prototype.clear = function( clearMeta ) {
|
||||
clearMeta = ((clearMeta === undefined) && true) || clearMeta;
|
||||
clearMeta && (delete this.imp);
|
||||
delete this.basics.computed; // Don't use Object.keys() here
|
||||
delete this.work;
|
||||
delete this.volunteer;
|
||||
delete this.education;
|
||||
delete this.awards;
|
||||
delete this.publications;
|
||||
delete this.interests;
|
||||
delete this.skills;
|
||||
delete this.basics.profiles;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Get the default (empty) sheet.
|
||||
*/
|
||||
JRSResume.default = function() {
|
||||
return new JRSResume().open(
|
||||
PATH.join( __dirname, 'empty-jrs.json'), 'Empty'
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Add work experience to the sheet.
|
||||
*/
|
||||
JRSResume.prototype.add = function( moniker ) {
|
||||
var defSheet = JRSResume.default();
|
||||
var newObject = $.extend( true, {}, defSheet[ moniker ][0] );
|
||||
this[ moniker ] = this[ moniker ] || [];
|
||||
this[ moniker ].push( newObject );
|
||||
return newObject;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Determine if the sheet includes a specific social profile (eg, GitHub).
|
||||
*/
|
||||
JRSResume.prototype.hasProfile = function( socialNetwork ) {
|
||||
socialNetwork = socialNetwork.trim().toLowerCase();
|
||||
return this.basics.profiles && _.some( this.basics.profiles, function(p) {
|
||||
return p.network.trim().toLowerCase() === socialNetwork;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Determine if the sheet includes a specific skill.
|
||||
*/
|
||||
JRSResume.prototype.hasSkill = function( skill ) {
|
||||
skill = skill.trim().toLowerCase();
|
||||
return this.skills && _.some( this.skills, function(sk) {
|
||||
return sk.keywords && _.some( sk.keywords, function(kw) {
|
||||
return kw.trim().toLowerCase() === skill;
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Validate the sheet against the JSON Resume schema.
|
||||
*/
|
||||
JRSResume.prototype.isValid = function( ) { // TODO: ↓ fix this path ↓
|
||||
var schema = FS.readFileSync( PATH.join( __dirname, 'resume.json' ),'utf8');
|
||||
var schemaObj = JSON.parse( schema );
|
||||
var validator = require('is-my-json-valid');
|
||||
var validate = validator( schemaObj, { // Note [1]
|
||||
formats: { date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/ }
|
||||
});
|
||||
var ret = validate( this );
|
||||
if( !ret ) {
|
||||
this.basics.imp = this.basics.imp || { };
|
||||
this.basics.imp.validationErrors = validate.errors;
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Calculate the total duration of the sheet. Assumes this.work has been sorted
|
||||
by start date descending, perhaps via a call to Sheet.sort().
|
||||
@returns The total duration of the sheet's work history, that is, the number
|
||||
of years between the start date of the earliest job on the resume and the
|
||||
*latest end date of all jobs in the work history*. This last condition is for
|
||||
sheets that have overlapping jobs.
|
||||
*/
|
||||
JRSResume.prototype.duration = function( unit ) {
|
||||
unit = unit || 'years';
|
||||
if( this.work && this.work.length ) {
|
||||
var careerStart = this.work[ this.work.length - 1].safeStartDate;
|
||||
if ((typeof careerStart === 'string' || careerStart instanceof String) &&
|
||||
!careerStart.trim())
|
||||
return 0;
|
||||
var careerLast = _.max( this.work, function( w ) {
|
||||
return w.safeEndDate.unix();
|
||||
}).safeEndDate;
|
||||
return careerLast.diff( careerStart, unit );
|
||||
}
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Sort dated things on the sheet by start date descending. Assumes that dates
|
||||
on the sheet have been processed with _parseDates().
|
||||
*/
|
||||
JRSResume.prototype.sort = function( ) {
|
||||
|
||||
this.work && this.work.sort( byDateDesc );
|
||||
this.education && this.education.sort( byDateDesc );
|
||||
this.volunteer && this.volunteer.sort( byDateDesc );
|
||||
|
||||
this.awards && this.awards.sort( function(a, b) {
|
||||
return( a.safeDate.isBefore(b.safeDate) ) ? 1
|
||||
: ( a.safeDate.isAfter(b.safeDate) && -1 ) || 0;
|
||||
});
|
||||
this.publications && this.publications.sort( function(a, b) {
|
||||
return( a.safeReleaseDate.isBefore(b.safeReleaseDate) ) ? 1
|
||||
: ( a.safeReleaseDate.isAfter(b.safeReleaseDate) && -1 ) || 0;
|
||||
});
|
||||
|
||||
function byDateDesc(a,b) {
|
||||
return( a.safeStartDate.isBefore(b.safeStartDate) ) ? 1
|
||||
: ( a.safeStartDate.isAfter(b.safeStartDate) && -1 ) || 0;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
JRSResume.prototype.dupe = function() {
|
||||
var rnew = new JRSResume();
|
||||
rnew.parse( this.stringify(), { } );
|
||||
return rnew;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Create a copy of this resume in which all fields have been interpreted as
|
||||
Markdown.
|
||||
*/
|
||||
JRSResume.prototype.harden = function() {
|
||||
|
||||
var that = this;
|
||||
var ret = this.dupe();
|
||||
|
||||
function HD(txt) {
|
||||
return '@@@@~' + txt + '~@@@@';
|
||||
}
|
||||
|
||||
function HDIN(txt){
|
||||
//return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
||||
return HD(txt);
|
||||
}
|
||||
|
||||
// TODO: refactor recursion
|
||||
function hardenStringsInObject( obj, inline ) {
|
||||
|
||||
if( !obj ) return;
|
||||
inline = inline === undefined || inline;
|
||||
|
||||
|
||||
if( Object.prototype.toString.call( obj ) === '[object Array]' ) {
|
||||
obj.forEach(function(elem, idx, ar){
|
||||
if( typeof elem === 'string' || elem instanceof String )
|
||||
ar[idx] = inline ? HDIN(elem) : HD( elem );
|
||||
else
|
||||
hardenStringsInObject( elem );
|
||||
});
|
||||
}
|
||||
else if (typeof obj === 'object') {
|
||||
Object.keys( obj ).forEach(function(key) {
|
||||
var sub = obj[key];
|
||||
if( typeof sub === 'string' || sub instanceof String ) {
|
||||
if( _.contains(['skills','url','website','startDate','endDate',
|
||||
'releaseDate','date','phone','email','address','postalCode',
|
||||
'city','country','region'], key) )
|
||||
return;
|
||||
if( key === 'summary' )
|
||||
obj[key] = HD( obj[key] );
|
||||
else
|
||||
obj[key] = inline ? HDIN( obj[key] ) : HD( obj[key] );
|
||||
}
|
||||
else
|
||||
hardenStringsInObject( sub );
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object.keys( ret ).forEach(function(member){
|
||||
hardenStringsInObject( ret[ member ] );
|
||||
});
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Convert human-friendly dates into formal Moment.js dates for all collections.
|
||||
We don't want to lose the raw textual date as entered by the user, so we store
|
||||
the Moment-ified date as a separate property with a prefix of .safe. For ex:
|
||||
job.startDate is the date as entered by the user. job.safeStartDate is the
|
||||
parsed Moment.js date that we actually use in processing.
|
||||
*/
|
||||
function _parseDates() {
|
||||
|
||||
var _fmt = require('./fluent-date').fmt;
|
||||
|
||||
this.work && this.work.forEach( function(job) {
|
||||
job.safeStartDate = _fmt( job.startDate );
|
||||
job.safeEndDate = _fmt( job.endDate );
|
||||
});
|
||||
this.education && this.education.forEach( function(edu) {
|
||||
edu.safeStartDate = _fmt( edu.startDate );
|
||||
edu.safeEndDate = _fmt( edu.endDate );
|
||||
});
|
||||
this.volunteer && this.volunteer.forEach( function(vol) {
|
||||
vol.safeStartDate = _fmt( vol.startDate );
|
||||
vol.safeEndDate = _fmt( vol.endDate );
|
||||
});
|
||||
this.awards && this.awards.forEach( function(awd) {
|
||||
awd.safeDate = _fmt( awd.date );
|
||||
});
|
||||
this.publications && this.publications.forEach( function(pub) {
|
||||
pub.safeReleaseDate = _fmt( pub.releaseDate );
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Export the JRSResume function/ctor.
|
||||
*/
|
||||
module.exports = JRSResume;
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,108 +0,0 @@
|
||||
/**
|
||||
Definition of the JRSTheme class.
|
||||
@module jrs-theme.js
|
||||
@license MIT. See LICENSE.MD for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var _ = require('underscore')
|
||||
, PATH = require('path')
|
||||
, parsePath = require('parse-filepath')
|
||||
, pathExists = require('path-exists').sync;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
The JRSTheme class is a representation of a JSON Resume theme asset.
|
||||
@class JRSTheme
|
||||
*/
|
||||
function JRSTheme() {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Open and parse the specified theme.
|
||||
@method open
|
||||
*/
|
||||
JRSTheme.prototype.open = function( thFolder ) {
|
||||
|
||||
this.folder = thFolder;
|
||||
|
||||
// Open the [theme-name].json file; should have the same
|
||||
// name as folder
|
||||
var pathInfo = parsePath( thFolder );
|
||||
|
||||
// Open and parse the theme's package.json file.
|
||||
var pkgJsonPath = PATH.join( thFolder, 'package.json' );
|
||||
if( pathExists( pkgJsonPath )) {
|
||||
|
||||
var thApi = require( thFolder )
|
||||
, thPkg = require( pkgJsonPath );
|
||||
|
||||
this.name = thPkg.name;
|
||||
this.render = (thApi && thApi.render) || undefined;
|
||||
this.engine = 'jrs';
|
||||
|
||||
// Create theme formats (HTML and PDF). Just add the bare minimum mix of
|
||||
// properties necessary to allow JSON Resume themes to share a rendering
|
||||
// path with FRESH themes.
|
||||
this.formats = {
|
||||
html: { outFormat: 'html', files: [
|
||||
{
|
||||
action: 'transform',
|
||||
render: this.render,
|
||||
major: true,
|
||||
ext: 'html',
|
||||
css: null
|
||||
}
|
||||
]},
|
||||
pdf: { outFormat: 'pdf', files: [
|
||||
{
|
||||
action: 'transform',
|
||||
render: this.render,
|
||||
major: true,
|
||||
ext: 'pdf',
|
||||
css: null
|
||||
}
|
||||
]}
|
||||
};
|
||||
}
|
||||
else {
|
||||
throw { fluenterror: HACKMYSTATUS.missingPackageJSON };
|
||||
}
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Determine if the theme supports the output format.
|
||||
@method hasFormat
|
||||
*/
|
||||
JRSTheme.prototype.hasFormat = function( fmt ) {
|
||||
return _.has( this.formats, fmt );
|
||||
};
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Return the requested output format.
|
||||
@method getFormat
|
||||
*/
|
||||
JRSTheme.prototype.getFormat = function( fmt ) {
|
||||
return this.formats[ fmt ];
|
||||
};
|
||||
|
||||
|
||||
|
||||
module.exports = JRSTheme;
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,138 +0,0 @@
|
||||
/**
|
||||
Definition of the ResumeFactory class.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module resume-factory.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
|
||||
var FS = require('fs'),
|
||||
HACKMYSTATUS = require('./status-codes'),
|
||||
HME = require('./event-codes'),
|
||||
ResumeConverter = require('fresh-jrs-converter'),
|
||||
chalk = require('chalk'),
|
||||
SyntaxErrorEx = require('../utils/syntax-error-ex'),
|
||||
_ = require('underscore');
|
||||
require('string.prototype.startswith');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
A simple factory class for FRESH and JSON Resumes.
|
||||
@class ResumeFactory
|
||||
*/
|
||||
var ResumeFactory = module.exports = {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Load one or more resumes from disk.
|
||||
|
||||
@param {Object} opts An options object with settings for the factory as well
|
||||
as passthrough settings for FRESHResume or JRSResume. Structure:
|
||||
|
||||
{
|
||||
format: 'FRESH', // Format to open as. ('FRESH', 'JRS', null)
|
||||
objectify: true, // FRESH/JRSResume or raw JSON?
|
||||
inner: { // Passthru options for FRESH/JRSResume
|
||||
sort: false
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
load: function ( sources, opts, emitter ) {
|
||||
|
||||
return sources.map( function( src ) {
|
||||
return this.loadOne( src, opts, emitter );
|
||||
}, this);
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Load a single resume from disk.
|
||||
*/
|
||||
loadOne: function( src, opts, emitter ) {
|
||||
|
||||
var toFormat = opts.format; // Can be null
|
||||
var objectify = opts.objectify;
|
||||
|
||||
// Get the destination format. Can be 'fresh', 'jrs', or null/undefined.
|
||||
toFormat && (toFormat = toFormat.toLowerCase().trim());
|
||||
|
||||
// Load and parse the resume JSON
|
||||
var info = _parse( src, opts, emitter );
|
||||
if( info.fluenterror ) return info;
|
||||
|
||||
// Determine the resume format: FRESH or JRS
|
||||
var json = info.json;
|
||||
var orgFormat = ( json.meta && json.meta.format &&
|
||||
json.meta.format.startsWith('FRESH@') ) ?
|
||||
'fresh' : 'jrs';
|
||||
|
||||
// Convert between formats if necessary
|
||||
if( toFormat && (orgFormat !== toFormat) ) {
|
||||
json = ResumeConverter[ 'to' + toFormat.toUpperCase() ]( json );
|
||||
}
|
||||
|
||||
// Objectify the resume, that is, convert it from JSON to a FRESHResume
|
||||
// or JRSResume object.
|
||||
var rez;
|
||||
if( objectify ) {
|
||||
var ResumeClass = require('../core/' + (toFormat || orgFormat) + '-resume');
|
||||
rez = new ResumeClass().parseJSON( json, opts.inner );
|
||||
rez.i().file = src;
|
||||
}
|
||||
|
||||
return {
|
||||
file: src,
|
||||
json: info.json,
|
||||
rez: rez
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
function _parse( fileName, opts, eve ) {
|
||||
|
||||
var rawData;
|
||||
try {
|
||||
|
||||
// Read the file
|
||||
eve && eve.stat( HME.beforeRead, { file: fileName });
|
||||
rawData = FS.readFileSync( fileName, 'utf8' );
|
||||
eve && eve.stat( HME.afterRead, { file: fileName, data: rawData });
|
||||
|
||||
// Parse the file
|
||||
eve && eve.stat( HME.beforeParse, { data: rawData });
|
||||
var ret = { json: JSON.parse( rawData ) };
|
||||
var orgFormat = ( ret.json.meta && ret.json.meta.format &&
|
||||
ret.json.meta.format.startsWith('FRESH@') ) ?
|
||||
'fresh' : 'jrs';
|
||||
eve && eve.stat( HME.afterParse, { file: fileName, data: ret.json, fmt: orgFormat } );
|
||||
|
||||
return ret;
|
||||
}
|
||||
catch( e ) {
|
||||
// Can be ENOENT, EACCES, SyntaxError, etc.
|
||||
var ex = {
|
||||
fluenterror: rawData ? HACKMYSTATUS.parseError : HACKMYSTATUS.readError,
|
||||
inner: e, raw: rawData, file: fileName, shouldExit: false
|
||||
};
|
||||
opts.quit && (ex.quit = true);
|
||||
eve && eve.err( ex.fluenterror, ex );
|
||||
if( opts.throw ) throw ex;
|
||||
return ex;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,380 +0,0 @@
|
||||
{
|
||||
"$schema": "http://json-schema.org/draft-04/schema#",
|
||||
"title": "Resume Schema",
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"basics": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string"
|
||||
},
|
||||
"label": {
|
||||
"type": "string",
|
||||
"description": "e.g. Web Developer"
|
||||
},
|
||||
"picture": {
|
||||
"type": "string",
|
||||
"description": "URL (as per RFC 3986) to a picture in JPEG or PNG format"
|
||||
},
|
||||
"email": {
|
||||
"type": "string",
|
||||
"description": "e.g. thomas@gmail.com",
|
||||
"format": "email"
|
||||
},
|
||||
"phone": {
|
||||
"type": "string",
|
||||
"description": "Phone numbers are stored as strings so use any format you like, e.g. 712-117-2923"
|
||||
},
|
||||
"website": {
|
||||
"type": "string",
|
||||
"description": "URL (as per RFC 3986) to your website, e.g. personal homepage",
|
||||
"format": "uri"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string",
|
||||
"description": "Write a short 2-3 sentence biography about yourself"
|
||||
},
|
||||
"location": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"address": {
|
||||
"type": "string",
|
||||
"description": "To add multiple address lines, use \n. For example, 1234 Glücklichkeit Straße\nHinterhaus 5. Etage li."
|
||||
},
|
||||
"postalCode": {
|
||||
"type": "string"
|
||||
},
|
||||
"city": {
|
||||
"type": "string"
|
||||
},
|
||||
"countryCode": {
|
||||
"type": "string",
|
||||
"description": "code as per ISO-3166-1 ALPHA-2, e.g. US, AU, IN"
|
||||
},
|
||||
"region": {
|
||||
"type": "string",
|
||||
"description": "The general region where you live. Can be a US state, or a province, for instance."
|
||||
}
|
||||
}
|
||||
},
|
||||
"profiles": {
|
||||
"type": "array",
|
||||
"description": "Specify any number of social networks that you participate in",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"network": {
|
||||
"type": "string",
|
||||
"description": "e.g. Facebook or Twitter"
|
||||
},
|
||||
"username": {
|
||||
"type": "string",
|
||||
"description": "e.g. neutralthoughts"
|
||||
},
|
||||
"url": {
|
||||
"type": "string",
|
||||
"description": "e.g. http://twitter.com/neutralthoughts"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"work": {
|
||||
"type": "array",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"company": {
|
||||
"type": "string",
|
||||
"description": "e.g. Facebook"
|
||||
},
|
||||
"position": {
|
||||
"type": "string",
|
||||
"description": "e.g. Software Engineer"
|
||||
},
|
||||
"website": {
|
||||
"type": "string",
|
||||
"description": "e.g. http://facebook.com",
|
||||
"format": "uri"
|
||||
},
|
||||
"startDate": {
|
||||
"type": "string",
|
||||
"description": "resume.json uses the ISO 8601 date standard e.g. 2014-06-29",
|
||||
"format": "date"
|
||||
},
|
||||
"endDate": {
|
||||
"type": "string",
|
||||
"description": "e.g. 2012-06-29",
|
||||
"format": "date"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string",
|
||||
"description": "Give an overview of your responsibilities at the company"
|
||||
},
|
||||
"highlights": {
|
||||
"type": "array",
|
||||
"description": "Specify multiple accomplishments",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "string",
|
||||
"description": "e.g. Increased profits by 20% from 2011-2012 through viral advertising"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
"volunteer": {
|
||||
"type": "array",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"organization": {
|
||||
"type": "string",
|
||||
"description": "e.g. Facebook"
|
||||
},
|
||||
"position": {
|
||||
"type": "string",
|
||||
"description": "e.g. Software Engineer"
|
||||
},
|
||||
"website": {
|
||||
"type": "string",
|
||||
"description": "e.g. http://facebook.com",
|
||||
"format": "uri"
|
||||
},
|
||||
"startDate": {
|
||||
"type": "string",
|
||||
"description": "resume.json uses the ISO 8601 date standard e.g. 2014-06-29",
|
||||
"format": "date"
|
||||
},
|
||||
"endDate": {
|
||||
"type": "string",
|
||||
"description": "e.g. 2012-06-29",
|
||||
"format": "date"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string",
|
||||
"description": "Give an overview of your responsibilities at the company"
|
||||
},
|
||||
"highlights": {
|
||||
"type": "array",
|
||||
"description": "Specify multiple accomplishments",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "string",
|
||||
"description": "e.g. Increased profits by 20% from 2011-2012 through viral advertising"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
"education": {
|
||||
"type": "array",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"institution": {
|
||||
"type": "string",
|
||||
"description": "e.g. Massachusetts Institute of Technology"
|
||||
},
|
||||
"area": {
|
||||
"type": "string",
|
||||
"description": "e.g. Arts"
|
||||
},
|
||||
"studyType": {
|
||||
"type": "string",
|
||||
"description": "e.g. Bachelor"
|
||||
},
|
||||
"startDate": {
|
||||
"type": "string",
|
||||
"description": "e.g. 2014-06-29",
|
||||
"format": "date"
|
||||
},
|
||||
"endDate": {
|
||||
"type": "string",
|
||||
"description": "e.g. 2012-06-29",
|
||||
"format": "date"
|
||||
},
|
||||
"gpa": {
|
||||
"type": "string",
|
||||
"description": "grade point average, e.g. 3.67/4.0"
|
||||
},
|
||||
"courses": {
|
||||
"type": "array",
|
||||
"description": "List notable courses/subjects",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "string",
|
||||
"description": "e.g. H1302 - Introduction to American history"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
},
|
||||
"awards": {
|
||||
"type": "array",
|
||||
"description": "Specify any awards you have received throughout your professional career",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"title": {
|
||||
"type": "string",
|
||||
"description": "e.g. One of the 100 greatest minds of the century"
|
||||
},
|
||||
"date": {
|
||||
"type": "string",
|
||||
"description": "e.g. 1989-06-12",
|
||||
"format": "date"
|
||||
},
|
||||
"awarder": {
|
||||
"type": "string",
|
||||
"description": "e.g. Time Magazine"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string",
|
||||
"description": "e.g. Received for my work with Quantum Physics"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"publications": {
|
||||
"type": "array",
|
||||
"description": "Specify your publications through your career",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "e.g. The World Wide Web"
|
||||
},
|
||||
"publisher": {
|
||||
"type": "string",
|
||||
"description": "e.g. IEEE, Computer Magazine"
|
||||
},
|
||||
"releaseDate": {
|
||||
"type": "string",
|
||||
"description": "e.g. 1990-08-01"
|
||||
},
|
||||
"website": {
|
||||
"type": "string",
|
||||
"description": "e.g. http://www.computer.org/csdl/mags/co/1996/10/rx069-abs.html"
|
||||
},
|
||||
"summary": {
|
||||
"type": "string",
|
||||
"description": "Short summary of publication. e.g. Discussion of the World Wide Web, HTTP, HTML."
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"skills": {
|
||||
"type": "array",
|
||||
"description": "List out your professional skill-set",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "e.g. Web Development"
|
||||
},
|
||||
"level": {
|
||||
"type": "string",
|
||||
"description": "e.g. Master"
|
||||
},
|
||||
"keywords": {
|
||||
"type": "array",
|
||||
"description": "List some keywords pertaining to this skill",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "string",
|
||||
"description": "e.g. HTML"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"languages": {
|
||||
"type": "array",
|
||||
"description": "List any other languages you speak",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"language": {
|
||||
"type": "string",
|
||||
"description": "e.g. English, Spanish"
|
||||
},
|
||||
"fluency": {
|
||||
"type": "string",
|
||||
"description": "e.g. Fluent, Beginner"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"interests": {
|
||||
"type": "array",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "e.g. Philosophy"
|
||||
},
|
||||
"keywords": {
|
||||
"type": "array",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "string",
|
||||
"description": "e.g. Friedrich Nietzsche"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
},
|
||||
"references": {
|
||||
"type": "array",
|
||||
"description": "List references you have received",
|
||||
"additionalItems": false,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": true,
|
||||
"properties": {
|
||||
"name": {
|
||||
"type": "string",
|
||||
"description": "e.g. Timothy Cook"
|
||||
},
|
||||
"reference": {
|
||||
"type": "string",
|
||||
"description": "e.g. Joe blogs was a great employee, who turned up to work at least once a week. He exceeded my expectations when it came to doing nothing."
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/**
|
||||
Status codes for HackMyResume.
|
||||
@module status-codes.js
|
||||
@license MIT. See LICENSE.MD for details.
|
||||
*/
|
||||
|
||||
(function(){
|
||||
|
||||
module.exports = {
|
||||
success: 0,
|
||||
themeNotFound: 1,
|
||||
copyCss: 2,
|
||||
resumeNotFound: 3,
|
||||
missingCommand: 4,
|
||||
invalidCommand: 5,
|
||||
resumeNotFoundAlt: 6,
|
||||
inputOutputParity: 7,
|
||||
createNameMissing: 8,
|
||||
pdfgeneration: 9,
|
||||
missingPackageJSON: 10,
|
||||
invalid: 11,
|
||||
invalidFormat: 12,
|
||||
notOnPath: 13,
|
||||
readError: 14,
|
||||
parseError: 15,
|
||||
fileSaveError: 16,
|
||||
generateError: 17,
|
||||
invalidHelperUse: 18,
|
||||
mixedMerge: 19,
|
||||
invokeTemplate: 20,
|
||||
compileTemplate: 21,
|
||||
themeLoad: 22,
|
||||
invalidParamCount: 23,
|
||||
missingParam: 24
|
||||
};
|
||||
|
||||
}());
|
@ -1,39 +0,0 @@
|
||||
/**
|
||||
Definition of the BaseGenerator class.
|
||||
@module base-generator.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
// Use J. Resig's nifty class implementation
|
||||
var Class = require( '../utils/class' );
|
||||
|
||||
/**
|
||||
The BaseGenerator class is the root of the generator hierarchy. Functionality
|
||||
common to ALL generators lives here.
|
||||
*/
|
||||
|
||||
var BaseGenerator = module.exports = Class.extend({
|
||||
|
||||
/**
|
||||
Base-class initialize.
|
||||
*/
|
||||
init: function( outputFormat ) {
|
||||
this.format = outputFormat;
|
||||
},
|
||||
|
||||
/**
|
||||
Status codes.
|
||||
*/
|
||||
codes: require('../core/status-codes'),
|
||||
|
||||
/**
|
||||
Generator options.
|
||||
*/
|
||||
opts: {
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
}());
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
Definition of the HTMLGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module html-generator.js
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
var TemplateGenerator = require('./template-generator')
|
||||
, FS = require('fs-extra')
|
||||
, HTML = require( 'html' )
|
||||
, PATH = require('path');
|
||||
require('string.prototype.endswith');
|
||||
|
||||
var HtmlGenerator = module.exports = TemplateGenerator.extend({
|
||||
|
||||
init: function() {
|
||||
this._super( 'html' );
|
||||
},
|
||||
|
||||
/**
|
||||
Copy satellite CSS files to the destination and optionally pretty-print
|
||||
the HTML resume prior to saving.
|
||||
*/
|
||||
onBeforeSave: function( info ) {
|
||||
if( info.outputFile.endsWith('.css') )
|
||||
return info.mk;
|
||||
return this.opts.prettify ?
|
||||
HTML.prettyPrint( info.mk, this.opts.prettify ) : info.mk;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}());
|
@ -1,113 +0,0 @@
|
||||
/**
|
||||
Definition of the HtmlPdfCLIGenerator class.
|
||||
@module html-pdf-generator.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var TemplateGenerator = require('./template-generator')
|
||||
, FS = require('fs-extra')
|
||||
, HTML = require( 'html' )
|
||||
, PATH = require('path')
|
||||
, SPAWN = require('../utils/safe-spawn')
|
||||
, SLASH = require('slash');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
An HTML-driven PDF resume generator for HackMyResume. Talks to Phantom,
|
||||
wkhtmltopdf, and other PDF engines over a CLI (command-line interface).
|
||||
If an engine isn't installed for a particular platform, error out gracefully.
|
||||
*/
|
||||
var HtmlPdfCLIGenerator = module.exports = TemplateGenerator.extend({
|
||||
|
||||
|
||||
|
||||
init: function() {
|
||||
this._super( 'pdf', 'html' );
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Generate the binary PDF.
|
||||
*/
|
||||
onBeforeSave: function( info ) {
|
||||
|
||||
try {
|
||||
var safe_eng = info.opts.pdf || 'wkhtmltopdf';
|
||||
if( safe_eng !== 'none' )
|
||||
engines[ safe_eng ].call( this, info.mk, info.outputFile );
|
||||
return null; // halt further processing
|
||||
}
|
||||
catch(ex) {
|
||||
// { [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', ... }
|
||||
// { [Error: ENOENT] }
|
||||
throw ( ex.inner && ex.inner.code === 'ENOENT' ) ?
|
||||
{ fluenterror: this.codes.notOnPath, inner: ex.inner, engine: ex.cmd,
|
||||
stack: ex.inner && ex.inner.stack } :
|
||||
{ fluenterror: this.codes.pdfGeneration, inner: ex, stack: ex.stack };
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
// TODO: Move each engine to a separate module
|
||||
var engines = {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Generate a PDF from HTML using wkhtmltopdf's CLI interface.
|
||||
Spawns a child process with `wkhtmltopdf <source> <target>`. wkhtmltopdf
|
||||
must be installed and path-accessible.
|
||||
TODO: If HTML generation has run, reuse that output
|
||||
TODO: Local web server to ease wkhtmltopdf rendering
|
||||
*/
|
||||
wkhtmltopdf: function(markup, fOut) {
|
||||
|
||||
// Save the markup to a temporary file
|
||||
var tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
|
||||
FS.writeFileSync( tempFile, markup, 'utf8' );
|
||||
var info = SPAWN( 'wkhtmltopdf', [ tempFile, fOut ] );
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Generate a PDF from HTML using Phantom's CLI interface.
|
||||
Spawns a child process with `phantomjs <script> <source> <target>`. Phantom
|
||||
must be installed and path-accessible.
|
||||
TODO: If HTML generation has run, reuse that output
|
||||
TODO: Local web server to ease Phantom rendering
|
||||
*/
|
||||
phantom: function( markup, fOut ) {
|
||||
|
||||
// Save the markup to a temporary file
|
||||
var tempFile = fOut.replace(/\.pdf$/i, '.pdf.html');
|
||||
FS.writeFileSync( tempFile, markup, 'utf8' );
|
||||
var scriptPath = SLASH( PATH.relative( process.cwd(),
|
||||
PATH.resolve( __dirname, '../utils/rasterize.js' ) ) );
|
||||
var sourcePath = SLASH( PATH.relative( process.cwd(), tempFile) );
|
||||
var destPath = SLASH( PATH.relative( process.cwd(), fOut) );
|
||||
var info = SPAWN('phantomjs', [ scriptPath, sourcePath, destPath ]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,66 +0,0 @@
|
||||
/**
|
||||
Definition of the HtmlPngGenerator class.
|
||||
@license MIT. See LICENSE.MD for details.
|
||||
@module html-png-generator.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var TemplateGenerator = require('./template-generator')
|
||||
, FS = require('fs-extra')
|
||||
, HTML = require( 'html' );
|
||||
|
||||
|
||||
|
||||
/**
|
||||
An HTML-based PNG resume generator for HackMyResume.
|
||||
*/
|
||||
var HtmlPngGenerator = module.exports = TemplateGenerator.extend({
|
||||
|
||||
|
||||
|
||||
init: function() {
|
||||
this._super( 'png', 'html' );
|
||||
},
|
||||
|
||||
|
||||
|
||||
invoke: function( rez, themeMarkup, cssInfo, opts ) {
|
||||
// TODO: Not currently called or callable.
|
||||
},
|
||||
|
||||
|
||||
|
||||
generate: function( rez, f, opts ) {
|
||||
var htmlResults = opts.targets.filter(function(t){
|
||||
return t.fmt.outFormat === 'html';
|
||||
});
|
||||
var htmlFile = htmlResults[0].final.files.filter(function(fl){
|
||||
return fl.info.ext === 'html';
|
||||
});
|
||||
png( htmlFile[0].data, f );
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Generate a PNG from HTML.
|
||||
*/
|
||||
function png( markup, fOut ) {
|
||||
// TODO: Which Webshot syntax?
|
||||
// require('webshot')( markup , { encoding: 'binary', siteType: 'html' } )
|
||||
// .pipe( FS.createWriteStream( fOut ) );
|
||||
require('webshot')( markup , fOut, { siteType: 'html' }, function(err) { } );
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,36 +0,0 @@
|
||||
/**
|
||||
Definition of the JsonGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module json-generator.js
|
||||
*/
|
||||
|
||||
var BaseGenerator = require('./base-generator');
|
||||
var FS = require('fs');
|
||||
var _ = require('underscore');
|
||||
|
||||
/**
|
||||
The JsonGenerator generates a JSON resume directly.
|
||||
*/
|
||||
var JsonGenerator = module.exports = BaseGenerator.extend({
|
||||
|
||||
init: function(){
|
||||
this._super( 'json' );
|
||||
},
|
||||
|
||||
invoke: function( rez ) {
|
||||
// TODO: merge with FCVD
|
||||
function replacer( key,value ) { // Exclude these keys from stringification
|
||||
return _.some(['imp', 'warnings', 'computed', 'filt', 'ctrl', 'index',
|
||||
'safeStartDate', 'safeEndDate', 'safeDate', 'safeReleaseDate', 'result',
|
||||
'isModified', 'htmlPreview', 'safe' ],
|
||||
function( val ) { return key.trim() === val; }
|
||||
) ? undefined : value;
|
||||
}
|
||||
return JSON.stringify( rez, replacer, 2 );
|
||||
},
|
||||
|
||||
generate: function( rez, f ) {
|
||||
FS.writeFileSync( f, this.invoke(rez), 'utf8' );
|
||||
}
|
||||
|
||||
});
|
@ -1,37 +0,0 @@
|
||||
/**
|
||||
Definition of the JsonYamlGenerator class.
|
||||
@module json-yaml-generator.js
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
var BaseGenerator = require('./base-generator');
|
||||
var FS = require('fs');
|
||||
var YAML = require('yamljs');
|
||||
|
||||
/**
|
||||
JsonYamlGenerator takes a JSON resume object and translates it directly to
|
||||
JSON without a template, producing an equivalent YAML-formatted resume. See
|
||||
also YamlGenerator (yaml-generator.js).
|
||||
*/
|
||||
|
||||
var JsonYamlGenerator = module.exports = BaseGenerator.extend({
|
||||
|
||||
init: function(){
|
||||
this._super( 'yml' );
|
||||
},
|
||||
|
||||
invoke: function( rez, themeMarkup, cssInfo, opts ) {
|
||||
return YAML.stringify( JSON.parse( rez.stringify() ), Infinity, 2 );
|
||||
},
|
||||
|
||||
generate: function( rez, f, opts ) {
|
||||
var data = YAML.stringify( JSON.parse( rez.stringify() ), Infinity, 2 );
|
||||
FS.writeFileSync( f, data, 'utf8' );
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
}());
|
@ -1,18 +0,0 @@
|
||||
/**
|
||||
Definition of the LaTeXGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module latex-generator.js
|
||||
*/
|
||||
|
||||
var TemplateGenerator = require('./template-generator');
|
||||
|
||||
/**
|
||||
LaTeXGenerator generates a LaTeX resume via TemplateGenerator.
|
||||
*/
|
||||
var LaTeXGenerator = module.exports = TemplateGenerator.extend({
|
||||
|
||||
init: function(){
|
||||
this._super( 'latex', 'tex' );
|
||||
}
|
||||
|
||||
});
|
@ -1,18 +0,0 @@
|
||||
/**
|
||||
Definition of the MarkdownGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module markdown-generator.js
|
||||
*/
|
||||
|
||||
var TemplateGenerator = require('./template-generator');
|
||||
|
||||
/**
|
||||
MarkdownGenerator generates a Markdown-formatted resume via TemplateGenerator.
|
||||
*/
|
||||
var MarkdownGenerator = module.exports = TemplateGenerator.extend({
|
||||
|
||||
init: function(){
|
||||
this._super( 'md', 'txt' );
|
||||
}
|
||||
|
||||
});
|
@ -1,244 +0,0 @@
|
||||
/**
|
||||
Definition of the TemplateGenerator class. TODO: Refactor
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module template-generator.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var FS = require( 'fs-extra' )
|
||||
, _ = require( 'underscore' )
|
||||
, MD = require( 'marked' )
|
||||
, XML = require( 'xml-escape' )
|
||||
, PATH = require('path')
|
||||
, parsePath = require('parse-filepath')
|
||||
, MKDIRP = require('mkdirp')
|
||||
, BaseGenerator = require( './base-generator' )
|
||||
, EXTEND = require('extend')
|
||||
, FRESHTheme = require('../core/fresh-theme')
|
||||
, JRSTheme = require('../core/jrs-theme');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
TemplateGenerator performs resume generation via local Handlebar or Underscore
|
||||
style template expansion and is appropriate for text-based formats like HTML,
|
||||
plain text, and XML versions of Microsoft Word, Excel, and OpenOffice.
|
||||
@class TemplateGenerator
|
||||
*/
|
||||
var TemplateGenerator = module.exports = BaseGenerator.extend({
|
||||
|
||||
|
||||
|
||||
/** Constructor. Set the output format and template format for this
|
||||
generator. Will usually be called by a derived generator such as
|
||||
HTMLGenerator or MarkdownGenerator. */
|
||||
|
||||
init: function( outputFormat, templateFormat, cssFile ){
|
||||
this._super( outputFormat );
|
||||
this.tplFormat = templateFormat || outputFormat;
|
||||
},
|
||||
|
||||
|
||||
|
||||
/** Generate a resume using string-based inputs and outputs without touching
|
||||
the filesystem.
|
||||
@method invoke
|
||||
@param rez A FreshResume object.
|
||||
@param opts Generator options.
|
||||
@returns {Array} An array of objects representing the generated output
|
||||
files. */
|
||||
|
||||
invoke: function( rez, opts ) {
|
||||
|
||||
opts = opts ?
|
||||
(this.opts = EXTEND( true, { }, _defaultOpts, opts )) :
|
||||
this.opts;
|
||||
|
||||
// Sort such that CSS files are processed before others
|
||||
var curFmt = opts.themeObj.getFormat( this.format );
|
||||
curFmt.files = _.sortBy( curFmt.files, function(fi) {
|
||||
return fi.ext !== 'css';
|
||||
});
|
||||
|
||||
// Run the transformation!
|
||||
var results = curFmt.files.map( function( tplInfo, idx ) {
|
||||
var trx = this.single( rez, tplInfo.data, this.format, opts, opts.themeObj, curFmt );
|
||||
if( tplInfo.ext === 'css' ) { curFmt.files[idx].data = trx; }
|
||||
else if( tplInfo.ext === 'html' ) {
|
||||
//tplInfo.css contains the CSS data loaded by theme
|
||||
//tplInfo.cssPath contains the absolute path to the source CSS File
|
||||
}
|
||||
return { info: tplInfo, data: trx };
|
||||
}, this);
|
||||
|
||||
return {
|
||||
files: results
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
/** Generate a resume using file-based inputs and outputs. Requires access
|
||||
to the local filesystem.
|
||||
@method generate
|
||||
@param rez A FreshResume object.
|
||||
@param f Full path to the output resume file to generate.
|
||||
@param opts Generator options. */
|
||||
|
||||
generate: function( rez, f, opts ) {
|
||||
|
||||
// Prepare
|
||||
this.opts = EXTEND( true, { }, _defaultOpts, opts );
|
||||
|
||||
// Call the string-based generation method to perform the generation.
|
||||
var genInfo = this.invoke( rez, null );
|
||||
|
||||
var outFolder = parsePath( f ).dirname;
|
||||
var curFmt = opts.themeObj.getFormat( this.format );
|
||||
|
||||
// Process individual files within this format. For example, the HTML
|
||||
// output format for a theme may have multiple HTML files, CSS files,
|
||||
// etc. Process them here.
|
||||
genInfo.files.forEach(function( file ){
|
||||
|
||||
// Pre-processing
|
||||
file.info.orgPath = file.info.orgPath || ''; // <-- For JRS themes
|
||||
var thisFilePath = PATH.join( outFolder, file.info.orgPath );
|
||||
if( this.onBeforeSave ) {
|
||||
file.data = this.onBeforeSave({
|
||||
theme: opts.themeObj,
|
||||
outputFile: (file.info.major ? f : thisFilePath),
|
||||
mk: file.data,
|
||||
opts: this.opts
|
||||
});
|
||||
if( !file.data ) return; // PDF etc
|
||||
}
|
||||
|
||||
// Write the file
|
||||
var fileName = file.info.major ? f : thisFilePath;
|
||||
MKDIRP.sync( PATH.dirname( fileName ) );
|
||||
FS.writeFileSync( fileName, file.data,
|
||||
{ encoding: 'utf8', flags: 'w' } );
|
||||
|
||||
// Post-processing
|
||||
this.onAfterSave && this.onAfterSave(
|
||||
{ outputFile: fileName, mk: file.data, opts: this.opts } );
|
||||
|
||||
}, this);
|
||||
|
||||
// Some themes require a symlink structure. If so, create it.
|
||||
if( curFmt.symLinks ) {
|
||||
Object.keys( curFmt.symLinks ).forEach( function(loc) {
|
||||
var absLoc = PATH.join(outFolder, loc);
|
||||
var absTarg = PATH.join(PATH.dirname(absLoc), curFmt.symLinks[loc]);
|
||||
// 'file', 'dir', or 'junction' (Windows only)
|
||||
var type = parsePath( absLoc ).extname ? 'file' : 'junction';
|
||||
FS.symlinkSync( absTarg, absLoc, type);
|
||||
});
|
||||
}
|
||||
|
||||
return genInfo;
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
/** Perform a single resume resume transformation using string-based inputs
|
||||
and outputs without touching the local file system.
|
||||
@param json A FRESH or JRS resume object.
|
||||
@param jst The stringified template data
|
||||
@param format The format name, such as "html" or "latex"
|
||||
@param cssInfo Needs to be refactored.
|
||||
@param opts Options and passthrough data. */
|
||||
|
||||
single: function( json, jst, format, opts, theme, curFmt ) {
|
||||
this.opts.freezeBreaks && ( jst = freeze(jst) );
|
||||
|
||||
var eng = require( '../renderers/' + theme.engine + '-generator' );
|
||||
var result = eng.generate( json, jst, format, curFmt, opts, theme );
|
||||
|
||||
this.opts.freezeBreaks && ( result = unfreeze(result) );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/** Export the TemplateGenerator function/ctor. */
|
||||
module.exports = TemplateGenerator;
|
||||
|
||||
|
||||
|
||||
|
||||
/** Freeze newlines for protection against errant JST parsers. */
|
||||
function freeze( markup ) {
|
||||
return markup
|
||||
.replace( _reg.regN, _defaultOpts.nSym )
|
||||
.replace( _reg.regR, _defaultOpts.rSym );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Unfreeze newlines when the coast is clear. */
|
||||
function unfreeze( markup ) {
|
||||
return markup
|
||||
.replace( _reg.regSymR, '\r' )
|
||||
.replace( _reg.regSymN, '\n' );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Default template generator options. */
|
||||
var _defaultOpts = {
|
||||
engine: 'underscore',
|
||||
keepBreaks: true,
|
||||
freezeBreaks: false,
|
||||
nSym: '&newl;', // newline entity
|
||||
rSym: '&retn;', // return entity
|
||||
template: {
|
||||
interpolate: /\{\{(.+?)\}\}/g,
|
||||
escape: /\{\{\=(.+?)\}\}/g,
|
||||
evaluate: /\{\%(.+?)\%\}/g,
|
||||
comment: /\{\#(.+?)\#\}/g
|
||||
},
|
||||
filters: {
|
||||
out: function( txt ) { return txt; },
|
||||
raw: function( txt ) { return txt; },
|
||||
xml: function( txt ) { return XML(txt); },
|
||||
md: function( txt ) { return MD( txt || '' ); },
|
||||
mdin: function( txt ) {
|
||||
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
||||
},
|
||||
lower: function( txt ) { return txt.toLowerCase(); },
|
||||
link: function( name, url ) { return url ?
|
||||
'<a href="' + url + '">' + name + '</a>' : name; }
|
||||
},
|
||||
prettify: { // ← See https://github.com/beautify-web/js-beautify#options
|
||||
indent_size: 2,
|
||||
unformatted: ['em','strong','a'],
|
||||
max_char: 80, // ← See lib/html.js in above-linked repo
|
||||
//wrap_line_length: 120, <-- Don't use this
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/** Regexes for linebreak preservation. */
|
||||
var _reg = {
|
||||
regN: new RegExp( '\n', 'g' ),
|
||||
regR: new RegExp( '\r', 'g' ),
|
||||
regSymN: new RegExp( _defaultOpts.nSym, 'g' ),
|
||||
regSymR: new RegExp( _defaultOpts.rSym, 'g' )
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,20 +0,0 @@
|
||||
/**
|
||||
Definition of the TextGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module text-generator.js
|
||||
*/
|
||||
|
||||
var TemplateGenerator = require('./template-generator');
|
||||
|
||||
/**
|
||||
The TextGenerator generates a plain-text resume via the TemplateGenerator.
|
||||
*/
|
||||
var TextGenerator = TemplateGenerator.extend({
|
||||
|
||||
init: function(){
|
||||
this._super( 'txt' );
|
||||
},
|
||||
|
||||
});
|
||||
|
||||
module.exports = TextGenerator;
|
@ -1,19 +0,0 @@
|
||||
/**
|
||||
Definition of the WordGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module word-generator.js
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
var TemplateGenerator = require('./template-generator');
|
||||
var WordGenerator = module.exports = TemplateGenerator.extend({
|
||||
|
||||
init: function(){
|
||||
this._super( 'doc', 'xml' );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
}());
|
@ -1,18 +0,0 @@
|
||||
/**
|
||||
Definition of the XMLGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module xml-generator.js
|
||||
*/
|
||||
|
||||
var BaseGenerator = require('./base-generator');
|
||||
|
||||
/**
|
||||
The XmlGenerator generates an XML resume via the TemplateGenerator.
|
||||
*/
|
||||
var XMLGenerator = module.exports = BaseGenerator.extend({
|
||||
|
||||
init: function(){
|
||||
this._super( 'xml' );
|
||||
},
|
||||
|
||||
});
|
@ -1,24 +0,0 @@
|
||||
/**
|
||||
Definition of the YAMLGenerator class.
|
||||
@module yaml-generator.js
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
*/
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
var TemplateGenerator = require('./template-generator');
|
||||
|
||||
/**
|
||||
YamlGenerator generates a YAML-formatted resume via TemplateGenerator.
|
||||
*/
|
||||
|
||||
var YAMLGenerator = module.exports = TemplateGenerator.extend({
|
||||
|
||||
init: function(){
|
||||
this._super( 'yml', 'yml' );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}());
|
@ -1,51 +0,0 @@
|
||||
/**
|
||||
External API surface for HackMyResume.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module hackmyapi.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
The formal HackMyResume API.
|
||||
*/
|
||||
var HackMyAPI = module.exports = {
|
||||
verbs: {
|
||||
build: require('./verbs/build'),
|
||||
analyze: require('./verbs/analyze'),
|
||||
validate: require('./verbs/validate'),
|
||||
convert: require('./verbs/convert'),
|
||||
new: require('./verbs/create'),
|
||||
peek: require('./verbs/peek')
|
||||
},
|
||||
alias: {
|
||||
generate: require('./verbs/build'),
|
||||
create: require('./verbs/create')
|
||||
},
|
||||
options: require('./core/default-options'),
|
||||
formats: require('./core/default-formats'),
|
||||
Sheet: require('./core/fresh-resume'),
|
||||
FRESHResume: require('./core/fresh-resume'),
|
||||
JRSResume: require('./core/jrs-resume'),
|
||||
FRESHTheme: require('./core/fresh-theme'),
|
||||
JRSTheme: require('./core/jrs-theme'),
|
||||
FluentDate: require('./core/fluent-date'),
|
||||
HtmlGenerator: require('./generators/html-generator'),
|
||||
TextGenerator: require('./generators/text-generator'),
|
||||
HtmlPdfCliGenerator: require('./generators/html-pdf-cli-generator'),
|
||||
WordGenerator: require('./generators/word-generator'),
|
||||
MarkdownGenerator: require('./generators/markdown-generator'),
|
||||
JsonGenerator: require('./generators/json-generator'),
|
||||
YamlGenerator: require('./generators/yaml-generator'),
|
||||
JsonYamlGenerator: require('./generators/json-yaml-generator'),
|
||||
LaTeXGenerator: require('./generators/latex-generator'),
|
||||
HtmlPngGenerator: require('./generators/html-png-generator')
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,67 +0,0 @@
|
||||
/**
|
||||
Generic template helper definitions for command-line output.
|
||||
@module console-helpers.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var PAD = require('string-padding')
|
||||
, LO = require('lodash')
|
||||
, CHALK = require('chalk')
|
||||
, _ = require('underscore');
|
||||
require('../utils/string');
|
||||
|
||||
|
||||
|
||||
var consoleFormatHelpers = module.exports = {
|
||||
|
||||
v: function( val, defaultVal, padding, style ) {
|
||||
retVal = ( val === null || val === undefined ) ? defaultVal : val;
|
||||
var spaces = 0;
|
||||
if( String.is(padding) ) {
|
||||
spaces = parseInt( padding, 10 );
|
||||
if( isNaN(spaces) ) spaces = 0;
|
||||
}
|
||||
else if( _.isNumber(padding) ) {
|
||||
spaces = padding;
|
||||
}
|
||||
|
||||
if( spaces !== 0 )
|
||||
retVal = PAD( retVal, Math.abs(spaces), null, spaces > 0 ? PAD.LEFT : PAD.RIGHT );
|
||||
|
||||
if( style && String.is( style )) {
|
||||
retVal = LO.get( CHALK, style )( retVal );
|
||||
}
|
||||
|
||||
return retVal;
|
||||
},
|
||||
|
||||
gapLength: function(val) {
|
||||
if( val < 35 )
|
||||
return CHALK.green.bold(val);
|
||||
else if( val < 95 )
|
||||
return CHALK.yellow.bold(val);
|
||||
else
|
||||
return CHALK.red.bold(val);
|
||||
},
|
||||
|
||||
style: function( val, style ) {
|
||||
return LO.get( CHALK, style )( val );
|
||||
},
|
||||
|
||||
isPlural: function( val, options ) {
|
||||
if( val > 1 )
|
||||
return options.fn(this);
|
||||
},
|
||||
|
||||
pad: function( val, spaces ) {
|
||||
return PAD(val, Math.abs(spaces), null, spaces > 0 ? PAD.LEFT : PAD.RIGHT );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,609 +0,0 @@
|
||||
/**
|
||||
Generic template helper definitions for HackMyResume / FluentCV.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module helpers/generic-helpers
|
||||
*/
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
var MD = require('marked')
|
||||
, H2W = require('../utils/html-to-wpml')
|
||||
, XML = require('xml-escape')
|
||||
, FluentDate = require('../core/fluent-date')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, moment = require('moment')
|
||||
, FS = require('fs')
|
||||
, LO = require('lodash')
|
||||
, PATH = require('path')
|
||||
, printf = require('printf')
|
||||
, _ = require('underscore')
|
||||
, unused = require('../utils/string');
|
||||
|
||||
/** Generic template helper function definitions. */
|
||||
var GenericHelpers = module.exports = {
|
||||
|
||||
/**
|
||||
Convert the input date to a specified format through Moment.js.
|
||||
If date is invalid, will return the time provided by the user,
|
||||
or default to the fallback param or 'Present' if that is set to true
|
||||
@method formatDate
|
||||
*/
|
||||
formatDate: function(datetime, format, fallback) {
|
||||
if (moment) {
|
||||
var momentDate = moment( datetime );
|
||||
if (momentDate.isValid()) return momentDate.format(format);
|
||||
}
|
||||
|
||||
return datetime || (typeof fallback == 'string' ? fallback : (fallback === true ? 'Present' : null));
|
||||
},
|
||||
|
||||
/**
|
||||
Given a resume sub-object with a start/end date, format a representation of
|
||||
the date range.
|
||||
@method dateRange
|
||||
*/
|
||||
dateRange: function( obj, fmt, sep, fallback, options ) {
|
||||
if( !obj ) return '';
|
||||
return _fromTo( obj.start, obj.end, fmt, sep, fallback, options );
|
||||
},
|
||||
|
||||
/**
|
||||
Format a from/to date range for display.
|
||||
@method toFrom
|
||||
*/
|
||||
fromTo: function() {
|
||||
return _fromTo.apply( this, arguments );
|
||||
},
|
||||
|
||||
/**
|
||||
Return a named color value as an RRGGBB string.
|
||||
@method toFrom
|
||||
*/
|
||||
color: function( colorName, colorDefault ) {
|
||||
// Key must be specified
|
||||
if( !( colorName && colorName.trim()) ) {
|
||||
_reportError( HMSTATUS.invalidHelperUse, {
|
||||
helper: 'fontList', error: HMSTATUS.missingParam, expected: 'name'
|
||||
});
|
||||
}
|
||||
else {
|
||||
if( !GenericHelpers.theme.colors ) return colorDefault;
|
||||
var ret = GenericHelpers.theme.colors[ colorName ];
|
||||
if( !(ret && ret.trim()) )
|
||||
return colorDefault;
|
||||
return ret;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
Return true if the section is present on the resume and has at least one
|
||||
element.
|
||||
@method section
|
||||
*/
|
||||
section: function( title, options ) {
|
||||
title = title.trim().toLowerCase();
|
||||
var obj = LO.get( this.r, title );
|
||||
if( _.isArray( obj ) ) {
|
||||
return obj.length ? options.fn(this) : undefined;
|
||||
}
|
||||
else if( _.isObject( obj )) {
|
||||
return ( (obj.history && obj.history.length) ||
|
||||
( obj.sets && obj.sets.length ) ) ?
|
||||
options.fn(this) : undefined;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
Emit the size of the specified named font.
|
||||
@param key {String} A named style from the "fonts" section of the theme's
|
||||
theme.json file. For example: 'default' or 'heading1'.
|
||||
*/
|
||||
fontSize: function( key, defSize, units ){
|
||||
|
||||
var ret = ''
|
||||
, hasDef = defSize && ( String.is( defSize ) || _.isNumber( defSize ));
|
||||
|
||||
// Key must be specified
|
||||
if( !( key && key.trim()) ) {
|
||||
_reportError( HMSTATUS.invalidHelperUse, {
|
||||
helper: 'fontSize', error: HMSTATUS.missingParam, expected: 'key'
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
else if ( GenericHelpers.theme.fonts ) {
|
||||
var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key );
|
||||
if( !fontSpec ) {
|
||||
// Check for an "all" format
|
||||
if( GenericHelpers.theme.fonts.all )
|
||||
fontSpec = GenericHelpers.theme.fonts.all[ key ];
|
||||
}
|
||||
if( fontSpec ) {
|
||||
// fontSpec can be a string, an array, or an object
|
||||
if( String.is( fontSpec )) {
|
||||
// No font size was specified, only a font family.
|
||||
}
|
||||
else if( _.isArray( fontSpec )) {
|
||||
// An array of fonts were specified. Each one could be a string
|
||||
// or an object
|
||||
if( !String.is( fontSpec[0] )) {
|
||||
ret = fontSpec[0].size;
|
||||
}
|
||||
}
|
||||
else {
|
||||
// A font description object.
|
||||
ret = fontSpec.size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We weren't able to lookup the specified key. Default to defFont.
|
||||
if( !ret ) {
|
||||
if( hasDef )
|
||||
ret = defSize;
|
||||
else {
|
||||
_reportError( HMSTATUS.invalidHelperUse, {
|
||||
helper: 'fontSize', error: HMSTATUS.missingParam,
|
||||
expected: 'defSize'});
|
||||
ret = '';
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
Emit the font face (such as 'Helvetica' or 'Calibri') associated with the
|
||||
provided key.
|
||||
@param key {String} A named style from the "fonts" section of the theme's
|
||||
theme.json file. For example: 'default' or 'heading1'.
|
||||
@param defFont {String} The font to use if the specified key isn't present.
|
||||
Can be any valid font-face name such as 'Helvetica Neue' or 'Calibri'.
|
||||
*/
|
||||
fontFace: function( key, defFont ) {
|
||||
|
||||
var ret = ''
|
||||
, hasDef = defFont && String.is( defFont );
|
||||
|
||||
// Key must be specified
|
||||
if( !( key && key.trim()) ) {
|
||||
_reportError( HMSTATUS.invalidHelperUse, {
|
||||
helper: 'fontFace', error: HMSTATUS.missingParam, expected: 'key'
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
|
||||
// If the theme has a "fonts" section, lookup the font face.
|
||||
else if( GenericHelpers.theme.fonts ) {
|
||||
var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key );
|
||||
if( !fontSpec ) {
|
||||
// Check for an "all" format
|
||||
if( GenericHelpers.theme.fonts.all )
|
||||
fontSpec = GenericHelpers.theme.fonts.all[ key ];
|
||||
}
|
||||
if( fontSpec ) {
|
||||
// fontSpec can be a string, an array, or an object
|
||||
if( String.is( fontSpec )) {
|
||||
ret = fontSpec;
|
||||
}
|
||||
else if( _.isArray( fontSpec )) {
|
||||
// An array of fonts were specified. Each one could be a string
|
||||
// or an object
|
||||
ret = String.is( fontSpec[0] ) ? fontSpec[0] : fontSpec[0].name;
|
||||
}
|
||||
else {
|
||||
// A font description object.
|
||||
ret = fontSpec.name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// We weren't able to lookup the specified key. Default to defFont.
|
||||
if( !(ret && ret.trim()) ) {
|
||||
ret = defFont;
|
||||
if( !hasDef ) {
|
||||
_reportError( HMSTATUS.invalidHelperUse, {
|
||||
helper: 'fontFace', error: HMSTATUS.missingParam,
|
||||
expected: 'defFont'});
|
||||
ret = '';
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
||||
/**
|
||||
Emit a comma-delimited list of font names suitable associated with the
|
||||
provided key.
|
||||
@param key {String} A named style from the "fonts" section of the theme's
|
||||
theme.json file. For example: 'default' or 'heading1'.
|
||||
@param defFontList {Array} The font list to use if the specified key isn't
|
||||
present. Can be an array of valid font-face name such as 'Helvetica Neue'
|
||||
or 'Calibri'.
|
||||
@param sep {String} The default separator to use in the rendered output.
|
||||
Defaults to ", " (comma with a space).
|
||||
*/
|
||||
fontList: function( key, defFontList, sep ) {
|
||||
|
||||
var ret = ''
|
||||
, hasDef = defFontList && String.is( defFontList );
|
||||
|
||||
// Key must be specified
|
||||
if( !( key && key.trim()) ) {
|
||||
_reportError( HMSTATUS.invalidHelperUse, {
|
||||
helper: 'fontList', error: HMSTATUS.missingParam, expected: 'key'
|
||||
});
|
||||
}
|
||||
|
||||
// If the theme has a "fonts" section, lookup the font list.
|
||||
else if( GenericHelpers.theme.fonts ) {
|
||||
var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key );
|
||||
if( !fontSpec ) {
|
||||
if( GenericHelpers.theme.fonts.all )
|
||||
fontSpec = GenericHelpers.theme.fonts.all[ key ];
|
||||
}
|
||||
|
||||
if( fontSpec ) {
|
||||
// fontSpec can be a string, an array, or an object
|
||||
if( String.is( fontSpec )) {
|
||||
ret = fontSpec;
|
||||
}
|
||||
else if( _.isArray( fontSpec )) {
|
||||
// An array of fonts were specified. Each one could be a string
|
||||
// or an object
|
||||
fontSpec = fontSpec.map( function( ff ) {
|
||||
return "'" + (String.is( ff ) ? ff : ff.name) + "'";
|
||||
});
|
||||
ret = fontSpec.join( sep === undefined ? ', ' : (sep || '') );
|
||||
}
|
||||
else {
|
||||
// A font description object.
|
||||
ret = fontSpec.name;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// The key wasn't found in the "fonts" section. Default to defFont.
|
||||
if( !(ret && ret.trim()) ) {
|
||||
if( !hasDef ) {
|
||||
_reportError( HMSTATUS.invalidHelperUse, {
|
||||
helper: 'fontList', error: HMSTATUS.missingParam,
|
||||
expected: 'defFontList'});
|
||||
ret = '';
|
||||
}
|
||||
else {
|
||||
ret = defFontList;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
|
||||
/**
|
||||
Capitalize the first letter of the word.
|
||||
@method section
|
||||
*/
|
||||
camelCase: function(val) {
|
||||
val = (val && val.trim()) || '';
|
||||
return val ? (val.charAt(0).toUpperCase() + val.slice(1)) : val;
|
||||
},
|
||||
|
||||
/**
|
||||
Return true if the context has the property or subpropery.
|
||||
@method has
|
||||
*/
|
||||
has: function( title, options ) {
|
||||
title = title && title.trim().toLowerCase();
|
||||
if( LO.get( this.r, title ) ) {
|
||||
return options.fn(this);
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
Generic template helper function to display a user-overridable section
|
||||
title for a FRESH resume theme. Use this in lieue of hard-coding section
|
||||
titles.
|
||||
|
||||
Usage:
|
||||
|
||||
{{sectionTitle "sectionName"}}
|
||||
{{sectionTitle "sectionName" "sectionTitle"}}
|
||||
|
||||
Example:
|
||||
|
||||
{{sectionTitle "Education"}}
|
||||
{{sectionTitle "Employment" "Project History"}}
|
||||
|
||||
@param sect_name The name of the section being title. Must be one of the
|
||||
top-level FRESH resume sections ("info", "education", "employment", etc.).
|
||||
@param sect_title The theme-specified section title. May be replaced by the
|
||||
user.
|
||||
@method sectionTitle
|
||||
*/
|
||||
sectionTitle: function( sname, stitle ) {
|
||||
|
||||
// If not provided by the user, stitle should default to sname. ps.
|
||||
// Handlebars silently passes in the options object to the last param,
|
||||
// where in Underscore stitle will be null/undefined, so we check both.
|
||||
stitle = (stitle && String.is(stitle) && stitle) || sname;
|
||||
|
||||
// If there's a section title override, use it.
|
||||
return ( this.opts.stitles &&
|
||||
this.opts.stitles[ sname.toLowerCase().trim() ] ) ||
|
||||
stitle;
|
||||
},
|
||||
|
||||
/**
|
||||
Convert inline Markdown to inline WordProcessingML.
|
||||
@method wpml
|
||||
*/
|
||||
wpml: function( txt, inline ) {
|
||||
if(!txt) return '';
|
||||
inline = (inline && !inline.hash) || false;
|
||||
txt = XML(txt.trim());
|
||||
txt = inline ?
|
||||
MD(txt).replace(/^\s*<p>|<\/p>\s*$/gi, '') :
|
||||
MD(txt);
|
||||
txt = H2W( txt );
|
||||
return txt;
|
||||
},
|
||||
|
||||
/**
|
||||
Emit a conditional link.
|
||||
@method link
|
||||
*/
|
||||
link: function( text, url ) {
|
||||
return url && url.trim() ?
|
||||
('<a href="' + url + '">' + text + '</a>') : text;
|
||||
},
|
||||
|
||||
/**
|
||||
Return the last word of the specified text.
|
||||
@method lastWord
|
||||
*/
|
||||
lastWord: function( txt ) {
|
||||
return txt && txt.trim() ? _.last( txt.split(' ') ) : '';
|
||||
},
|
||||
|
||||
/**
|
||||
Convert a skill level to an RGB color triplet. TODO: refactor
|
||||
@method skillColor
|
||||
@param lvl Input skill level. Skill level can be expressed as a string
|
||||
("beginner", "intermediate", etc.), as an integer (1,5,etc), as a string
|
||||
integer ("1", "5", etc.), or as an RRGGBB color triplet ('#C00000',
|
||||
'#FFFFAA').
|
||||
*/
|
||||
skillColor: function( lvl ) {
|
||||
var idx = skillLevelToIndex( lvl );
|
||||
var skillColors = (this.theme && this.theme.palette &&
|
||||
this.theme.palette.skillLevels) ||
|
||||
[ '#FFFFFF', '#5CB85C', '#F1C40F', '#428BCA', '#C00000' ];
|
||||
return skillColors[idx];
|
||||
},
|
||||
|
||||
/**
|
||||
Return an appropriate height. TODO: refactor
|
||||
@method lastWord
|
||||
*/
|
||||
skillHeight: function( lvl ) {
|
||||
var idx = skillLevelToIndex( lvl );
|
||||
return ['38.25', '30', '16', '8', '0'][idx];
|
||||
},
|
||||
|
||||
/**
|
||||
Return all but the last word of the input text.
|
||||
@method initialWords
|
||||
*/
|
||||
initialWords: function( txt ) {
|
||||
return txt && txt.trim() ? _.initial( txt.split(' ') ).join(' ') : '';
|
||||
},
|
||||
|
||||
/**
|
||||
Trim the protocol (http or https) from a URL/
|
||||
@method trimURL
|
||||
*/
|
||||
trimURL: function( url ) {
|
||||
return url && url.trim() ? url.trim().replace(/^https?:\/\//i, '') : '';
|
||||
},
|
||||
|
||||
/**
|
||||
Convert text to lowercase.
|
||||
@method toLower
|
||||
*/
|
||||
toLower: function( txt ) {
|
||||
return txt && txt.trim() ? txt.toLowerCase() : '';
|
||||
},
|
||||
|
||||
/**
|
||||
Convert text to lowercase.
|
||||
@method toLower
|
||||
*/
|
||||
toUpper: function( txt ) {
|
||||
return txt && txt.trim() ? txt.toUpperCase() : '';
|
||||
},
|
||||
|
||||
/**
|
||||
Return true if either value is truthy.
|
||||
@method either
|
||||
*/
|
||||
either: function( lhs, rhs, options ) {
|
||||
if (lhs || rhs) return options.fn(this);
|
||||
},
|
||||
|
||||
/**
|
||||
Conditional stylesheet link. Creates a link to the specified stylesheet with
|
||||
<link> or embeds the styles inline with <style></style>, depending on the
|
||||
theme author's and user's preferences.
|
||||
@param url {String} The path to the CSS file.
|
||||
@param linkage {String} The default link method. Can be either `embed` or
|
||||
`link`. If omitted, defaults to `embed`. Can be overridden by the `--css`
|
||||
command-line switch.
|
||||
*/
|
||||
|
||||
styleSheet: function( url, linkage ) {
|
||||
|
||||
// Establish the linkage style
|
||||
linkage = this.opts.css || linkage || 'embed';
|
||||
|
||||
// Create the <link> or <style> tag
|
||||
var ret = '';
|
||||
if( linkage === 'link' ) {
|
||||
ret = printf('<link href="%s" rel="stylesheet" type="text/css">', url);
|
||||
}
|
||||
else {
|
||||
var rawCss = FS.readFileSync(
|
||||
PATH.join( this.opts.themeObj.folder, '/src/', url ), 'utf8' );
|
||||
var renderedCss = this.engine.generateSimple( this, rawCss );
|
||||
ret = printf('<style>%s</style>', renderedCss );
|
||||
}
|
||||
|
||||
// If the currently-executing template is inherited, append styles
|
||||
if( this.opts.themeObj.inherits &&
|
||||
this.opts.themeObj.inherits.html &&
|
||||
this.format === 'html' ) {
|
||||
ret += (linkage === 'link') ?
|
||||
'<link href="' + this.opts.themeObj.overrides.path +
|
||||
'" rel="stylesheet" type="text/css">' :
|
||||
'<style>' + this.opts.themeObj.overrides.data + '</style>';
|
||||
}
|
||||
|
||||
// TODO: It would be nice to use Handlebar.SafeString here, but these
|
||||
// are supposed to be generic helpers. Provide an equivalent, or expose
|
||||
// it when Handlebars is the chosen engine, which is most of the time.
|
||||
return ret;
|
||||
},
|
||||
|
||||
/**
|
||||
Perform a generic comparison.
|
||||
See: http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates
|
||||
@method compare
|
||||
*/
|
||||
compare: function(lvalue, rvalue, options) {
|
||||
if (arguments.length < 3)
|
||||
throw new Error("Handlerbars Helper 'compare' needs 2 parameters");
|
||||
var operator = options.hash.operator || "==";
|
||||
var operators = {
|
||||
'==': function(l,r) { return l == r; },
|
||||
'===': function(l,r) { return l === r; },
|
||||
'!=': function(l,r) { return l != r; },
|
||||
'<': function(l,r) { return l < r; },
|
||||
'>': function(l,r) { return l > r; },
|
||||
'<=': function(l,r) { return l <= r; },
|
||||
'>=': function(l,r) { return l >= r; },
|
||||
'typeof': function(l,r) { return typeof l == r; }
|
||||
};
|
||||
if (!operators[operator])
|
||||
throw new Error("Handlerbars Helper 'compare' doesn't know the operator "+operator);
|
||||
var result = operators[operator](lvalue,rvalue);
|
||||
return result ? options.fn(this) : options.inverse(this);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
Report an error to the outside world without throwing an exception. Currently
|
||||
relies on kludging the running verb into. opts.
|
||||
*/
|
||||
function _reportError( code, params ) {
|
||||
GenericHelpers.opts.errHandler.err( code, params );
|
||||
}
|
||||
|
||||
/**
|
||||
Format a from/to date range for display.
|
||||
*/
|
||||
function _fromTo( dateA, dateB, fmt, sep, fallback ) {
|
||||
|
||||
// Prevent accidental use of safe.start, safe.end, safe.date
|
||||
// The dateRange helper is for raw dates only
|
||||
if( moment.isMoment( dateA ) || moment.isMoment( dateB ) ) {
|
||||
_reportError( HMSTATUS.invalidHelperUse, { helper: 'dateRange' } );
|
||||
return '';
|
||||
}
|
||||
|
||||
var dateFrom, dateTo, dateTemp;
|
||||
|
||||
// Check for 'current', 'present', 'now', '', null, and undefined
|
||||
dateA = dateA || '';
|
||||
dateB = dateB || '';
|
||||
var dateATrim = dateA.trim().toLowerCase();
|
||||
var dateBTrim = dateB.trim().toLowerCase();
|
||||
var reserved = ['current','present','now', ''];
|
||||
|
||||
fmt = (fmt && String.is(fmt) && fmt) || 'YYYY-MM';
|
||||
sep = (sep && String.is(sep) && sep) || ' — ';
|
||||
|
||||
if( _.contains( reserved, dateATrim )) {
|
||||
dateFrom = fallback || '???';
|
||||
}
|
||||
else {
|
||||
dateTemp = FluentDate.fmt( dateA );
|
||||
dateFrom = dateTemp.format( fmt );
|
||||
}
|
||||
|
||||
if( _.contains( reserved, dateBTrim )) {
|
||||
dateTo = fallback || 'Current';
|
||||
}
|
||||
else {
|
||||
dateTemp = FluentDate.fmt( dateB );
|
||||
dateTo = dateTemp.format( fmt );
|
||||
}
|
||||
|
||||
if( dateFrom && dateTo ) {
|
||||
return dateFrom + sep + dateTo;
|
||||
}
|
||||
else if( dateFrom || dateTo ) {
|
||||
return dateFrom || dateTo;
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
function skillLevelToIndex( lvl ) {
|
||||
var idx = 0;
|
||||
if( String.is( lvl ) ) {
|
||||
lvl = lvl.trim().toLowerCase();
|
||||
var intVal = parseInt( lvl );
|
||||
if( isNaN( intVal ) ) {
|
||||
switch( lvl ) {
|
||||
case 'beginner': idx = 1; break;
|
||||
case 'intermediate': idx = 2; break;
|
||||
case 'advanced': idx = 3; break;
|
||||
case 'master': idx = 4; break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
idx = Math.min( intVal / 2, 4 );
|
||||
idx = Math.max( 0, idx );
|
||||
}
|
||||
}
|
||||
else {
|
||||
idx = Math.min( lvl / 2, 4 );
|
||||
idx = Math.max( 0, idx );
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
}());
|
||||
|
||||
// Note [1] --------------------------------------------------------------------
|
||||
// Make sure it's precisely a string or array since some template engines jam
|
||||
// their options/context object into the last parameter and we are allowing the
|
||||
// defFont parameter to be omitted in certain cases. This is a little kludgy,
|
||||
// but works fine for this case. If we start doing this regularly, we should
|
||||
// rebind these parameters.
|
||||
|
||||
// Note [2]: -------------------------------------------------------------------
|
||||
// If execution reaches here, some sort of cosmic ray or sunspot has landed on
|
||||
// HackMyResume, or a theme author is deliberately messing with us by doing
|
||||
// something like:
|
||||
//
|
||||
// "fonts": {
|
||||
// "default": "",
|
||||
// "heading1": null
|
||||
// }
|
||||
//
|
||||
// Rather than sort it out, we'll just fall back to defFont.
|
@ -1,26 +0,0 @@
|
||||
/**
|
||||
Template helper definitions for Handlebars.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module handlebars-helpers.js
|
||||
*/
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
var HANDLEBARS = require('handlebars')
|
||||
, _ = require('underscore')
|
||||
, helpers = require('./generic-helpers');
|
||||
|
||||
/**
|
||||
Register useful Handlebars helpers.
|
||||
@method registerHelpers
|
||||
*/
|
||||
module.exports = function( theme, opts ) {
|
||||
|
||||
helpers.theme = theme;
|
||||
helpers.opts = opts;
|
||||
HANDLEBARS.registerHelper( helpers );
|
||||
|
||||
};
|
||||
|
||||
}());
|
@ -1,34 +0,0 @@
|
||||
/**
|
||||
Template helper definitions for Underscore.
|
||||
@license MIT. Copyright (c) 2016 hacksalot (https://github.com/hacksalot)
|
||||
@module handlebars-helpers.js
|
||||
*/
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
var HANDLEBARS = require('handlebars')
|
||||
, _ = require('underscore')
|
||||
, helpers = require('./generic-helpers');
|
||||
|
||||
/**
|
||||
Register useful Underscore helpers.
|
||||
@method registerHelpers
|
||||
*/
|
||||
module.exports = function( theme, opts, cssInfo, ctx, eng ) {
|
||||
|
||||
helpers.theme = theme;
|
||||
helpers.opts = opts;
|
||||
helpers.cssInfo = cssInfo;
|
||||
helpers.engine = eng;
|
||||
ctx.h = helpers;
|
||||
|
||||
_.each( helpers, function( hVal, hKey ) {
|
||||
if( _.isFunction( hVal )) {
|
||||
_.bind( hVal, ctx );
|
||||
}
|
||||
}, this);
|
||||
|
||||
};
|
||||
|
||||
}());
|
@ -1,166 +0,0 @@
|
||||
/**
|
||||
Employment gap analysis for HackMyResume.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module inspectors/gap-inspector
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var _ = require('underscore');
|
||||
var FluentDate = require('../core/fluent-date');
|
||||
var moment = require('moment');
|
||||
var LO = require('lodash');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Identify gaps in the candidate's employment history.
|
||||
*/
|
||||
var gapInspector = module.exports = {
|
||||
|
||||
|
||||
|
||||
moniker: 'gap-inspector',
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Run the Gap Analyzer on a resume.
|
||||
@method run
|
||||
@return {Array} An array of object representing gaps in the candidate's
|
||||
employment history. Each object provides the start, end, and duration of the
|
||||
gap:
|
||||
{ <-- gap
|
||||
start: // A Moment.js date
|
||||
end: // A Moment.js date
|
||||
duration: // Gap length
|
||||
}
|
||||
*/
|
||||
run: function( rez ) {
|
||||
|
||||
// This is what we'll return
|
||||
var coverage = {
|
||||
gaps: [],
|
||||
overlaps: [],
|
||||
duration: {
|
||||
total: 0,
|
||||
work: 0,
|
||||
gaps: 0
|
||||
},
|
||||
pct: '0%'
|
||||
};
|
||||
|
||||
// Missing employment section? Bye bye.
|
||||
var hist = LO.get( rez, 'employment.history' );
|
||||
if( !hist || !hist.length ) { return coverage; }
|
||||
|
||||
// Convert the candidate's employment history to an array of dates,
|
||||
// where each element in the array is a start date or an end date of a
|
||||
// job -- it doesn't matter which.
|
||||
var new_e = hist.map( function( job ){
|
||||
var obj = _.pick( job, ['start', 'end'] );
|
||||
if( obj && (obj.start || obj.end)) {
|
||||
obj = _.pairs( obj );
|
||||
obj[0][1] = FluentDate.fmt( obj[0][1] );
|
||||
if( obj.length > 1 )
|
||||
obj[1][1] = FluentDate.fmt( obj[1][1] );
|
||||
}
|
||||
return obj;
|
||||
});
|
||||
|
||||
|
||||
// Flatten the array, remove empties, and sort
|
||||
new_e = _.filter( _.flatten( new_e, true ), function(v) {
|
||||
return ( v && v.length && v[0] && v[0].length );
|
||||
});
|
||||
if( !new_e || !new_e.length ) return coverage;
|
||||
new_e = _.sortBy( new_e, function( elem ) { return elem[1].unix(); });
|
||||
|
||||
// Iterate over elements in the array. Each time a start date is found,
|
||||
// increment a reference count. Each time an end date is found, decrement
|
||||
// the reference count. When the reference count reaches 0, we have a gap.
|
||||
// When the reference count is > 0, the candidate is employed. When the
|
||||
// reference count reaches 2, the candidate is overlapped.
|
||||
|
||||
var num_gaps = 0, ref_count = 0, total_gap_days = 0, gap_start;
|
||||
|
||||
new_e.forEach( function(point) {
|
||||
|
||||
var inc = point[0] === 'start' ? 1 : -1;
|
||||
ref_count += inc;
|
||||
|
||||
// If the ref count just reached 0, start a new GAP
|
||||
if( ref_count === 0 ) {
|
||||
coverage.gaps.push( { start: point[1], end: null });
|
||||
}
|
||||
|
||||
// If the ref count reached 1 by rising, end the last GAP
|
||||
else if( ref_count === 1 && inc === 1 ) {
|
||||
var lastGap = _.last( coverage.gaps );
|
||||
if( lastGap ) {
|
||||
lastGap.end = point[1];
|
||||
lastGap.duration = lastGap.end.diff( lastGap.start, 'days' );
|
||||
total_gap_days += lastGap.duration;
|
||||
}
|
||||
}
|
||||
|
||||
// If the ref count reaches 2 by rising, start a new OVERLAP
|
||||
else if( ref_count === 2 && inc === 1 ) {
|
||||
coverage.overlaps.push( { start: point[1], end: null });
|
||||
}
|
||||
|
||||
// If the ref count reaches 1 by falling, end the last OVERLAP
|
||||
else if( ref_count === 1 && inc === -1 ) {
|
||||
var lastOver = _.last( coverage.overlaps );
|
||||
if( lastOver ) {
|
||||
lastOver.end = point[1];
|
||||
lastOver.duration = lastOver.end.diff( lastOver.start, 'days' );
|
||||
if( lastOver.duration === 0 ) {
|
||||
coverage.overlaps.pop();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// It's possible that the last gap/overlap didn't have an explicit .end
|
||||
// date.If so, set the end date to the present date and compute the
|
||||
// duration normally.
|
||||
if( coverage.overlaps.length ) {
|
||||
var o = _.last( coverage.overlaps );
|
||||
if( o && !o.end ) {
|
||||
o.end = moment();
|
||||
o.duration = o.end.diff( o.start, 'days' );
|
||||
}
|
||||
}
|
||||
if( coverage.gaps.length ) {
|
||||
var g = _.last( coverage.gaps );
|
||||
if( g && !g.end ) {
|
||||
g.end = moment();
|
||||
g.duration = g.end.diff( g.start, 'days' );
|
||||
}
|
||||
}
|
||||
|
||||
// Package data for return to the client
|
||||
var tdur = rez.duration('days');
|
||||
var dur = {
|
||||
total: tdur,
|
||||
work: tdur - total_gap_days,
|
||||
gaps: total_gap_days
|
||||
};
|
||||
coverage.pct = ( dur.total > 0 && dur.work > 0 ) ?
|
||||
((((dur.total - dur.gaps) / dur.total) * 100)).toFixed(1) + '%' :
|
||||
'???';
|
||||
coverage.duration = dur;
|
||||
return coverage;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,98 +0,0 @@
|
||||
/**
|
||||
Keyword analysis for HackMyResume.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module keyword-inspector.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var _ = require('underscore');
|
||||
var FluentDate = require('../core/fluent-date');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Analyze the resume's use of keywords.
|
||||
TODO: BUG: Keyword search regex is inaccurate, especially for one or two
|
||||
letter keywords like "C" or "CLI".
|
||||
@class keywordInspector
|
||||
*/
|
||||
var keywordInspector = module.exports = {
|
||||
|
||||
|
||||
|
||||
/**
|
||||
A unique name for this inspector.
|
||||
*/
|
||||
moniker: 'keyword-inspector',
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Run the Keyword Inspector on a resume.
|
||||
@method run
|
||||
@return An collection of statistical keyword data.
|
||||
*/
|
||||
run: function( rez ) {
|
||||
|
||||
// "Quote" or safely escape a keyword so it can be used as a regex. For
|
||||
// example, if the keyword is "C++", yield "C\+\+".
|
||||
// http://stackoverflow.com/a/2593661/4942583
|
||||
function regex_quote(str) {
|
||||
return (str + '').replace(/[.?*+^$[\]\\(){}|-]/ig, "\\$&");
|
||||
}
|
||||
|
||||
// Create a searchable plain-text digest of the resume
|
||||
// TODO: BUG: Don't search within keywords for other keywords. Job A
|
||||
// declares the "foo" keyword. Job B declares the "foo & bar" keyword. Job
|
||||
// B's mention of "foobar" should not count as a mention of "foo".
|
||||
// To achieve this, remove keywords from the search digest and treat them
|
||||
// separately.
|
||||
var searchable = '';
|
||||
rez.transformStrings( ['imp', 'computed', 'safe'], function trxString( key, val ) {
|
||||
searchable += ' ' + val;
|
||||
});
|
||||
|
||||
// Assemble a regex skeleton we can use to test for keywords with a bit
|
||||
// more
|
||||
var prefix = '(?:' + ['^', '\\s+', '[\\.,]+'].join('|') + ')';
|
||||
var suffix = '(?:' + ['$', '\\s+', '[\\.,]+'].join('|') + ')';
|
||||
|
||||
return rez.keywords().map(function(kw) {
|
||||
|
||||
// 1. Using word boundary or other regex class is inaccurate
|
||||
//
|
||||
// var regex = new RegExp( '\\b' + regex_quote( kw )/* + '\\b'*/, 'ig');
|
||||
//
|
||||
// 2. Searching for the raw keyword is inaccurate ("C" will match any
|
||||
// word containing a 'c'!).
|
||||
//
|
||||
// var regex = new RegExp( regex_quote( kw ), 'ig');
|
||||
//
|
||||
// 3. Instead, use a custom regex with special delimeters.
|
||||
|
||||
var regex_str = prefix + regex_quote( kw ) + suffix;
|
||||
var regex = new RegExp( regex_str, 'ig');
|
||||
var myArray, count = 0;
|
||||
while ((myArray = regex.exec( searchable )) !== null) {
|
||||
count++;
|
||||
}
|
||||
return {
|
||||
name: kw,
|
||||
count: count
|
||||
};
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,63 +0,0 @@
|
||||
/**
|
||||
Section analysis for HackMyResume.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module totals-inspector.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var _ = require('underscore');
|
||||
var FluentDate = require('../core/fluent-date');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Retrieve sectional overview and summary information.
|
||||
@class totalsInspector
|
||||
*/
|
||||
var totalsInspector = module.exports = {
|
||||
|
||||
|
||||
|
||||
moniker: 'totals-inspector',
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Run the Totals Inspector on a resume.
|
||||
@method run
|
||||
@return An object containing summary information for each section on the
|
||||
resume.
|
||||
*/
|
||||
run: function( rez ) {
|
||||
|
||||
var sectionTotals = { };
|
||||
_.each( rez, function(val, key){
|
||||
if( _.isArray( val ) && !_.isString(val) ) {
|
||||
sectionTotals[ key ] = val.length;
|
||||
}
|
||||
else if( val.history && _.isArray( val.history ) ) {
|
||||
sectionTotals[ key ] = val.history.length;
|
||||
}
|
||||
else if( val.sets && _.isArray( val.sets ) ) {
|
||||
sectionTotals[ key ] = val.sets.length;
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
totals: sectionTotals,
|
||||
numSections: Object.keys( sectionTotals ).length
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,119 +0,0 @@
|
||||
/**
|
||||
Definition of the HandlebarsGenerator class.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module renderers/handlebars-generator
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var _ = require('underscore')
|
||||
, HANDLEBARS = require('handlebars')
|
||||
, FS = require('fs')
|
||||
, registerHelpers = require('../helpers/handlebars-helpers')
|
||||
, PATH = require('path')
|
||||
, parsePath = require('parse-filepath')
|
||||
, READFILES = require('recursive-readdir-sync')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, SLASH = require('slash');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Perform template-based resume generation using Handlebars.js.
|
||||
@class HandlebarsGenerator
|
||||
*/
|
||||
var HandlebarsGenerator = module.exports = {
|
||||
|
||||
|
||||
|
||||
generateSimple: function( data, tpl ) {
|
||||
|
||||
try {
|
||||
// Compile and run the Handlebars template.
|
||||
var template = HANDLEBARS.compile( tpl, { strict: false, assumeObjects: false } );
|
||||
return template( data );
|
||||
}
|
||||
catch( ex ) {
|
||||
throw {
|
||||
fluenterror: template ?
|
||||
HMSTATUS.invokeTemplate : HMSTATUS.compileTemplate,
|
||||
inner: ex
|
||||
};
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
|
||||
|
||||
generate: function( json, jst, format, curFmt, opts, theme ) {
|
||||
|
||||
// Set up partials and helpers
|
||||
registerPartials( format, theme );
|
||||
registerHelpers( theme, opts );
|
||||
|
||||
// Preprocess text
|
||||
var encData = json;
|
||||
( format === 'html' || format === 'pdf' ) && (encData = json.markdownify());
|
||||
( format === 'doc' ) && (encData = json.xmlify());
|
||||
|
||||
// Set up the context
|
||||
var ctx = {
|
||||
r: encData,
|
||||
RAW: json,
|
||||
filt: opts.filters,
|
||||
format: format,
|
||||
opts: opts,
|
||||
engine: this,
|
||||
results: curFmt.files,
|
||||
headFragment: opts.headFragment || ''
|
||||
};
|
||||
|
||||
// Render the template
|
||||
return this.generateSimple( ctx, jst );
|
||||
}
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
function registerPartials(format, theme) {
|
||||
if( _.contains( ['html','doc','md','txt'], format )) {
|
||||
|
||||
// Locate the global partials folder
|
||||
var partialsFolder = PATH.join(
|
||||
parsePath( require.resolve('fresh-themes') ).dirname,
|
||||
'/partials/',
|
||||
format
|
||||
);
|
||||
|
||||
// Register global partials in the /partials/[format] folder
|
||||
// TODO: Only do this once per HMR invocation.
|
||||
_.each( READFILES( partialsFolder, function(error){ }), function( el ) {
|
||||
var pathInfo = parsePath( el );
|
||||
var name = SLASH( PATH.relative( partialsFolder, el )
|
||||
.replace(/\.(?:html|xml|hbs|md|txt)$/i, '') );
|
||||
var tplData = FS.readFileSync( el, 'utf8' );
|
||||
var compiledTemplate = HANDLEBARS.compile( tplData );
|
||||
HANDLEBARS.registerPartial( name, compiledTemplate );
|
||||
theme.partialsInitialized = true;
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
// Register theme-specific partials
|
||||
_.each( theme.partials, function( el ) {
|
||||
var tplData = FS.readFileSync( el.path, 'utf8' );
|
||||
var compiledTemplate = HANDLEBARS.compile( tplData );
|
||||
HANDLEBARS.registerPartial( el.name, compiledTemplate );
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,65 +0,0 @@
|
||||
/**
|
||||
Definition of the JRSGenerator class.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module jrs-generator.js
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var _ = require('underscore')
|
||||
, HANDLEBARS = require('handlebars')
|
||||
, FS = require('fs')
|
||||
, registerHelpers = require('../helpers/handlebars-helpers')
|
||||
, PATH = require('path')
|
||||
, parsePath = require('parse-filepath')
|
||||
, READFILES = require('recursive-readdir-sync')
|
||||
, SLASH = require('slash')
|
||||
, MD = require('marked');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Perform template-based resume generation for JSON Resume themes.
|
||||
@class JRSGenerator
|
||||
*/
|
||||
var JRSGenerator = module.exports = {
|
||||
|
||||
|
||||
|
||||
|
||||
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
||||
|
||||
// Disable JRS theme chatter (console.log, console.error, etc.)
|
||||
var off = ['log', 'error', 'dir'], org = off.map(function(c){
|
||||
var ret = console[c]; console[c] = function(){}; return ret;
|
||||
});
|
||||
|
||||
// Freeze and render
|
||||
var rezHtml = theme.render( json.harden() );
|
||||
|
||||
// Turn logging back on
|
||||
off.forEach(function(c, idx){ console[c] = org[idx]; });
|
||||
|
||||
// Unfreeze and apply Markdown
|
||||
rezHtml = rezHtml.replace( /@@@@~.*?~@@@@/gm, function(val){
|
||||
return MDIN( val.replace( /~@@@@/gm,'' ).replace( /@@@@~/gm,'' ) );
|
||||
});
|
||||
|
||||
return rezHtml;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
function MDIN(txt) { // TODO: Move this
|
||||
return MD(txt || '' ).replace(/^\s*<p>|<\/p>\s*$/gi, '');
|
||||
}
|
||||
|
||||
|
||||
}());
|
@ -1,73 +0,0 @@
|
||||
/**
|
||||
Definition of the UnderscoreGenerator class.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module underscore-generator.js
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var _ = require('underscore')
|
||||
, registerHelpers = require('../helpers/underscore-helpers')
|
||||
, HMSTATUS = require('../core/status-codes');
|
||||
|
||||
|
||||
/**
|
||||
Perform template-based resume generation using Underscore.js.
|
||||
@class UnderscoreGenerator
|
||||
*/
|
||||
var UnderscoreGenerator = module.exports = {
|
||||
|
||||
generateSimple: function( data, tpl ) {
|
||||
|
||||
try {
|
||||
// Compile and run the Handlebars template.
|
||||
var template = _.template( tpl );
|
||||
return template( data );
|
||||
}
|
||||
catch( ex ) {
|
||||
throw {
|
||||
fluenterror: template ?
|
||||
HMSTATUS.invokeTemplate : HMSTATUS.compileTemplate,
|
||||
inner: ex
|
||||
};
|
||||
}
|
||||
|
||||
},
|
||||
|
||||
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
||||
|
||||
// Tweak underscore's default template delimeters
|
||||
var delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template;
|
||||
if( opts.themeObj && opts.themeObj.delimeters ) {
|
||||
delims = _.mapObject( delims, function(val,key) {
|
||||
return new RegExp( val, "ig");
|
||||
});
|
||||
}
|
||||
_.templateSettings = delims;
|
||||
|
||||
// Strip {# comments #}
|
||||
jst = jst.replace( delims.comment, '');
|
||||
|
||||
var ctx = {
|
||||
r: format === 'html' || format === 'pdf' || format === 'png' ? json.markdownify() : json,
|
||||
filt: opts.filters,
|
||||
XML: require('xml-escape'),
|
||||
RAW: json,
|
||||
cssInfo: cssInfo,
|
||||
//engine: this,
|
||||
headFragment: opts.headFragment || '',
|
||||
opts: opts
|
||||
};
|
||||
|
||||
registerHelpers( theme, opts, cssInfo, ctx, this );
|
||||
|
||||
return this.generateSimple( ctx, jst );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,72 +0,0 @@
|
||||
/**
|
||||
Definition of John Resig's `Class` class.
|
||||
@module class.js
|
||||
*/
|
||||
|
||||
/* Simple JavaScript Inheritance
|
||||
* By John Resig http://ejohn.org/
|
||||
* MIT Licensed.
|
||||
* http://ejohn.org/blog/simple-javascript-inheritance/
|
||||
*/
|
||||
// Inspired by base2 and Prototype
|
||||
(function(){
|
||||
var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
|
||||
|
||||
// The base Class implementation (does nothing)
|
||||
this.Class = function(){};
|
||||
module.exports = Class;
|
||||
|
||||
// Create a new Class that inherits from this class
|
||||
Class.extend = function(prop) {
|
||||
var _super = this.prototype;
|
||||
|
||||
// Instantiate a base class (but only create the instance,
|
||||
// don't run the init constructor)
|
||||
initializing = true;
|
||||
var prototype = new this();
|
||||
initializing = false;
|
||||
|
||||
// Copy the properties over onto the new prototype
|
||||
for (var name in prop) {
|
||||
// Check if we're overwriting an existing function
|
||||
prototype[name] = typeof prop[name] == "function" &&
|
||||
typeof _super[name] == "function" && fnTest.test(prop[name]) ?
|
||||
(function(name, fn){
|
||||
return function() {
|
||||
var tmp = this._super;
|
||||
|
||||
// Add a new ._super() method that is the same method
|
||||
// but on the super-class
|
||||
this._super = _super[name];
|
||||
|
||||
// The method only need to be bound temporarily, so we
|
||||
// remove it when we're done executing
|
||||
var ret = fn.apply(this, arguments);
|
||||
this._super = tmp;
|
||||
|
||||
return ret;
|
||||
};
|
||||
})(name, prop[name]) : // jshint ignore:line
|
||||
prop[name];
|
||||
}
|
||||
|
||||
// The dummy class constructor
|
||||
function Class() {
|
||||
// All construction is actually done in the init method
|
||||
if ( !initializing && this.init )
|
||||
this.init.apply(this, arguments);
|
||||
}
|
||||
|
||||
// Populate our constructed prototype object
|
||||
Class.prototype = prototype;
|
||||
|
||||
// Enforce the constructor to be what we expect
|
||||
Class.prototype.constructor = Class;
|
||||
|
||||
// And make this class extendable
|
||||
Class.extend = arguments.callee;
|
||||
|
||||
return Class;
|
||||
};
|
||||
|
||||
})();
|
@ -1,12 +0,0 @@
|
||||
/**
|
||||
Definition of the SyntaxErrorEx class.
|
||||
@module file-contains.js
|
||||
*/
|
||||
|
||||
(function(){
|
||||
|
||||
module.exports = function( file, needle ) {
|
||||
return require('fs').readFileSync(file,'utf-8').indexOf( needle ) > -1;
|
||||
};
|
||||
|
||||
}());
|
@ -1,66 +0,0 @@
|
||||
/**
|
||||
Definition of the Markdown to WordProcessingML conversion routine.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module html-to-wpml.js
|
||||
*/
|
||||
|
||||
(function(){
|
||||
|
||||
var _ = require('underscore');
|
||||
var HTML5Tokenizer = require('simple-html-tokenizer');
|
||||
|
||||
module.exports = function( html ) {
|
||||
|
||||
// Tokenize the HTML stream.
|
||||
var tokens = HTML5Tokenizer.tokenize( html );
|
||||
|
||||
var final = '', is_bold, is_italic, is_link, link_url;
|
||||
|
||||
// Process <em>, <strong>, and <a> elements in the HTML stream, producing
|
||||
// equivalent WordProcessingML that can be dumped into a <w:p> or other
|
||||
// text container element.
|
||||
_.each( tokens, function( tok ) {
|
||||
|
||||
switch( tok.type ) {
|
||||
|
||||
case 'StartTag':
|
||||
switch( tok.tagName ) {
|
||||
case 'p': final += '<w:p>'; break;
|
||||
case 'strong': is_bold = true; break;
|
||||
case 'em': is_italic = true; break;
|
||||
case 'a':
|
||||
is_link = true;
|
||||
link_url = tok.attributes.filter(function(attr){
|
||||
return attr[0] === 'href'; }
|
||||
)[0][1];
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'EndTag':
|
||||
switch( tok.tagName ) {
|
||||
case 'p': final += '</w:p>'; break;
|
||||
case 'strong': is_bold = false; break;
|
||||
case 'em': is_italic = false; break;
|
||||
case 'a': is_link = false; break;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'Chars':
|
||||
if( tok.chars.trim().length ) {
|
||||
var style = is_bold ? '<w:b/>' : '';
|
||||
style += is_italic ? '<w:i/>': '';
|
||||
style += is_link ? '<w:rStyle w:val="Hyperlink"/>' : '';
|
||||
final +=
|
||||
(is_link ? ('<w:hlink w:dest="' + link_url + '">') : '') +
|
||||
'<w:r><w:rPr>' + style + '</w:rPr><w:t>' + tok.chars +
|
||||
'</w:t></w:r>' + (is_link ? '</w:hlink>' : '');
|
||||
}
|
||||
break;
|
||||
}
|
||||
});
|
||||
return final;
|
||||
|
||||
};
|
||||
|
||||
}());
|
@ -1,19 +0,0 @@
|
||||
/**
|
||||
Inline Markdown-to-Chalk conversion routines.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module md2chalk.js
|
||||
*/
|
||||
|
||||
(function(){
|
||||
|
||||
var MD = require('marked');
|
||||
var CHALK = require('chalk');
|
||||
var LO = require('lodash');
|
||||
|
||||
module.exports = function( v, style, boldStyle ) {
|
||||
boldStyle = boldStyle || 'bold';
|
||||
var temp = v.replace(/\*\*(.*?)\*\*/g, LO.get( CHALK, boldStyle )('$1'));
|
||||
return style ? LO.get( CHALK, style )(temp) : temp;
|
||||
};
|
||||
|
||||
}());
|
@ -1,56 +0,0 @@
|
||||
// Exemplar script for generating documents with Phantom.js.
|
||||
// https://raw.githubusercontent.com/ariya/phantomjs/master/examples/rasterize.js
|
||||
|
||||
(function() {
|
||||
|
||||
"use strict";
|
||||
var page = require('webpage').create(),
|
||||
system = require('system'),
|
||||
address, output, size;
|
||||
|
||||
if (system.args.length < 3 || system.args.length > 5) {
|
||||
console.log('Usage: rasterize.js URL filename [paperwidth*paperheight|paperformat] [zoom]');
|
||||
console.log(' paper (pdf output) examples: "5in*7.5in", "10cm*20cm", "A4", "Letter"');
|
||||
console.log(' image (png/jpg output) examples: "1920px" entire page, window width 1920px');
|
||||
console.log(' "800px*600px" window, clipped to 800x600');
|
||||
phantom.exit(1);
|
||||
} else {
|
||||
address = system.args[1];
|
||||
output = system.args[2];
|
||||
page.viewportSize = { width: 600, height: 600 };
|
||||
if (system.args.length > 3 && system.args[2].substr(-4) === ".pdf") {
|
||||
size = system.args[3].split('*');
|
||||
page.paperSize = size.length === 2 ? { width: size[0], height: size[1], margin: '0px' }
|
||||
: { format: system.args[3], orientation: 'portrait', margin: '1cm' };
|
||||
} else if (system.args.length > 3 && system.args[3].substr(-2) === "px") {
|
||||
size = system.args[3].split('*');
|
||||
if (size.length === 2) {
|
||||
pageWidth = parseInt(size[0], 10);
|
||||
pageHeight = parseInt(size[1], 10);
|
||||
page.viewportSize = { width: pageWidth, height: pageHeight };
|
||||
page.clipRect = { top: 0, left: 0, width: pageWidth, height: pageHeight };
|
||||
} else {
|
||||
console.log("size:", system.args[3]);
|
||||
pageWidth = parseInt(system.args[3], 10);
|
||||
pageHeight = parseInt(pageWidth * 3/4, 10); // it's as good an assumption as any
|
||||
console.log ("pageHeight:",pageHeight);
|
||||
page.viewportSize = { width: pageWidth, height: pageHeight };
|
||||
}
|
||||
}
|
||||
if (system.args.length > 4) {
|
||||
page.zoomFactor = system.args[4];
|
||||
}
|
||||
page.open(address, function (status) {
|
||||
if (status !== 'success') {
|
||||
console.log('Unable to load the address!');
|
||||
phantom.exit(1);
|
||||
} else {
|
||||
window.setTimeout(function () {
|
||||
page.render(output);
|
||||
phantom.exit();
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}());
|
@ -1,46 +0,0 @@
|
||||
/**
|
||||
Definition of the SafeJsonLoader class.
|
||||
@module syntax-error-ex.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var FS = require('fs')
|
||||
, SyntaxErrorEx = require('./syntax-error-ex');
|
||||
|
||||
|
||||
|
||||
module.exports = function loadSafeJson( file ) {
|
||||
|
||||
var ret = { };
|
||||
try {
|
||||
|
||||
ret.raw = FS.readFileSync( file, 'utf8' );
|
||||
ret.json = JSON.parse( ret.raw );
|
||||
|
||||
}
|
||||
catch( ex ) {
|
||||
|
||||
// If we get here, either FS.readFileSync or JSON.parse failed.
|
||||
// We'll return HMSTATUS.readError or HMSTATUS.parseError.
|
||||
var retRaw = ret.raw && ret.raw.trim();
|
||||
|
||||
ret.ex = {
|
||||
operation: retRaw ? 'parse' : 'read',
|
||||
inner: SyntaxErrorEx.is( ex ) ? (new SyntaxErrorEx( ex, retRaw )) : ex,
|
||||
file: file
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
};
|
||||
|
||||
|
||||
}());
|
@ -1,45 +0,0 @@
|
||||
/**
|
||||
Safe spawn utility for HackMyResume / FluentCV.
|
||||
@module safe-spawn.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
module.exports = function( cmd, args, isSync ) {
|
||||
|
||||
try {
|
||||
|
||||
var spawn = require('child_process')[ isSync? 'spawnSync' : 'spawn'];
|
||||
var info = spawn( cmd, args );
|
||||
|
||||
if( !isSync ) {
|
||||
info.on('error', function(err) {
|
||||
throw {
|
||||
cmd: 'wkhtmltopdf',
|
||||
inner: err
|
||||
};
|
||||
});
|
||||
}
|
||||
else {
|
||||
if( info.error ) {
|
||||
throw {
|
||||
cmd: 'wkhtmltopdf',
|
||||
inner: info.error
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
catch( ex ) {
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,65 +0,0 @@
|
||||
/**
|
||||
Object string transformation.
|
||||
@module string-transformer.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var _ = require('underscore');
|
||||
var moment = require('moment');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Create a copy of this object in which all string fields have been run through
|
||||
a transformation function (such as a Markdown filter or XML encoder).
|
||||
*/
|
||||
module.exports = function( ret, filt, transformer ) {
|
||||
|
||||
var that = this;
|
||||
|
||||
// TODO: refactor recursion
|
||||
function transformStringsInObject( obj, filters ) {
|
||||
|
||||
if( !obj ) return;
|
||||
if( moment.isMoment( obj ) ) return;
|
||||
|
||||
if( _.isArray( obj ) ) {
|
||||
obj.forEach( function(elem, idx, ar) {
|
||||
if( typeof elem === 'string' || elem instanceof String )
|
||||
ar[idx] = transformer( null, elem );
|
||||
else if (_.isObject(elem))
|
||||
transformStringsInObject( elem, filters );
|
||||
});
|
||||
}
|
||||
else if (_.isObject( obj )) {
|
||||
Object.keys( obj ).forEach(function(k) {
|
||||
if( filters.length && _.contains(filters, k) )
|
||||
return;
|
||||
var sub = obj[k];
|
||||
if( typeof sub === 'string' || sub instanceof String ) {
|
||||
obj[k] = transformer( k, sub );
|
||||
}
|
||||
else if (_.isObject( sub ))
|
||||
transformStringsInObject( sub, filters );
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Object.keys( ret ).forEach(function(member){
|
||||
if( !filt || !filt.length || !_.contains(filt, member) )
|
||||
transformStringsInObject( ret[ member ], filt || [] );
|
||||
});
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,26 +0,0 @@
|
||||
/**
|
||||
Definitions of string utility functions.
|
||||
@module string.js
|
||||
*/
|
||||
|
||||
/**
|
||||
Determine if the string is null, empty, or whitespace.
|
||||
See: http://stackoverflow.com/a/32800728/4942583
|
||||
@method isNullOrWhitespace
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
String.isNullOrWhitespace = function( input ) {
|
||||
return !input || !input.trim();
|
||||
};
|
||||
|
||||
String.prototype.endsWith = function(suffix) {
|
||||
return this.indexOf(suffix, this.length - suffix.length) !== -1;
|
||||
};
|
||||
|
||||
String.is = function( val ) {
|
||||
return typeof val === 'string' || val instanceof String;
|
||||
};
|
||||
|
||||
}());
|
@ -1,35 +0,0 @@
|
||||
/**
|
||||
Definition of the SyntaxErrorEx class.
|
||||
@module syntax-error-ex.js
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
/**
|
||||
Represents a SyntaxError exception with line and column info.
|
||||
Collect syntax error information from the provided exception object. The
|
||||
JavaScript `SyntaxError` exception isn't interpreted uniformly across environ-
|
||||
ments, so we reparse on error to grab the line and column.
|
||||
See: http://stackoverflow.com/q/13323356
|
||||
@class SyntaxErrorEx
|
||||
*/
|
||||
|
||||
function SyntaxErrorEx( ex, rawData ) {
|
||||
|
||||
var lineNum = null, colNum = null;
|
||||
var JSONLint = require('json-lint');
|
||||
var lint = JSONLint( rawData, { comments: false } );
|
||||
this.line = (lint.error ? lint.line : '???');
|
||||
this.col = (lint.error ? lint.character : '???');
|
||||
|
||||
}
|
||||
|
||||
SyntaxErrorEx.is = function( ex ) {
|
||||
return ex instanceof SyntaxError;
|
||||
};
|
||||
|
||||
module.exports = SyntaxErrorEx;
|
||||
|
||||
}());
|
@ -1,94 +0,0 @@
|
||||
/**
|
||||
Implementation of the 'analyze' verb for HackMyResume.
|
||||
@module verbs/analyze
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
|
||||
var MKDIRP = require('mkdirp')
|
||||
, PATH = require('path')
|
||||
, HMEVENT = require('../core/event-codes')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, _ = require('underscore')
|
||||
, ResumeFactory = require('../core/resume-factory')
|
||||
, Verb = require('../verbs/verb')
|
||||
, chalk = require('chalk');
|
||||
|
||||
|
||||
|
||||
var AnalyzeVerb = module.exports = Verb.extend({
|
||||
|
||||
init: function() {
|
||||
this._super('analyze');
|
||||
},
|
||||
|
||||
invoke: function() {
|
||||
this.stat( HMEVENT.begin, { cmd: 'analyze' });
|
||||
analyze.apply( this, arguments );
|
||||
this.stat( HMEVENT.end );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Run the 'analyze' command.
|
||||
*/
|
||||
function analyze( sources, dst, opts ) {
|
||||
if( !sources || !sources.length )
|
||||
throw { fluenterror: HMSTATUS.resumeNotFound, quit: true };
|
||||
|
||||
var nlzrs = _loadInspectors();
|
||||
|
||||
_.each(sources, function(src) {
|
||||
var result = ResumeFactory.loadOne( src, {
|
||||
format: 'FRESH', objectify: true
|
||||
}, this);
|
||||
if( result.fluenterror )
|
||||
this.setError( result.fluenterror, result );
|
||||
else
|
||||
_analyze.call(this, result, nlzrs, opts );
|
||||
}, this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Analyze a single resume.
|
||||
*/
|
||||
function _analyze( resumeObject, nlzrs, opts ) {
|
||||
var rez = resumeObject.rez;
|
||||
var safeFormat =
|
||||
(rez.meta && rez.meta.format && rez.meta.format.startsWith('FRESH')) ?
|
||||
'FRESH' : 'JRS';
|
||||
|
||||
this.stat( HMEVENT.beforeAnalyze, { fmt: safeFormat, file: resumeObject.file });
|
||||
var info = _.mapObject( nlzrs, function(val, key) {
|
||||
return val.run( resumeObject.rez );
|
||||
});
|
||||
this.stat( HMEVENT.afterAnalyze, { info: info } );
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Load inspectors.
|
||||
*/
|
||||
function _loadInspectors() {
|
||||
return {
|
||||
totals: require('../inspectors/totals-inspector'),
|
||||
coverage: require('../inspectors/gap-inspector'),
|
||||
keywords: require('../inspectors/keyword-inspector')
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,385 +0,0 @@
|
||||
/**
|
||||
Implementation of the 'build' verb for HackMyResume.
|
||||
@module verbs/build
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var _ = require('underscore')
|
||||
, PATH = require('path')
|
||||
, FS = require('fs')
|
||||
, MD = require('marked')
|
||||
, MKDIRP = require('mkdirp')
|
||||
, extend = require('extend')
|
||||
, parsePath = require('parse-filepath')
|
||||
, RConverter = require('fresh-jrs-converter')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, HMEVENT = require('../core/event-codes')
|
||||
, RTYPES = { FRESH: require('../core/fresh-resume'),
|
||||
JRS: require('../core/jrs-resume') }
|
||||
, _opts = require('../core/default-options')
|
||||
, FRESHTheme = require('../core/fresh-theme')
|
||||
, JRSTheme = require('../core/jrs-theme')
|
||||
, ResumeFactory = require('../core/resume-factory')
|
||||
, _fmts = require('../core/default-formats')
|
||||
, Verb = require('../verbs/verb');
|
||||
|
||||
var _err, _log, _rezObj;
|
||||
|
||||
|
||||
|
||||
/** An invokable resume generation command. */
|
||||
var BuildVerb = module.exports = Verb.extend({
|
||||
|
||||
/** Create a new build verb. */
|
||||
init: function() {
|
||||
this._super('build');
|
||||
},
|
||||
|
||||
/** Invoke the Build command. */
|
||||
invoke: function() {
|
||||
this.stat( HMEVENT.begin, { cmd: 'build' } );
|
||||
var ret = build.apply( this, arguments );
|
||||
this.stat( HMEVENT.end );
|
||||
return ret;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Given a source resume in FRESH or JRS format, a destination resume path, and a
|
||||
theme file, generate 0..N resumes in the desired formats.
|
||||
@param src Path to the source JSON resume file: "rez/resume.json".
|
||||
@param dst An array of paths to the target resume file(s).
|
||||
@param theme Friendly name of the resume theme. Defaults to "modern".
|
||||
@param logger Optional logging override.
|
||||
*/
|
||||
function build( src, dst, opts ) {
|
||||
|
||||
if( !src || !src.length ) {
|
||||
this.err( HMSTATUS.resumeNotFound, { quit: true } );
|
||||
}
|
||||
|
||||
prep( src, dst, opts );
|
||||
|
||||
// Load input resumes as JSON...
|
||||
var sheetObjects = ResumeFactory.load(src, {
|
||||
format: null, objectify: false, quit: true, inner: { sort: _opts.sort }
|
||||
}, this);
|
||||
|
||||
// Explicit check for any resume loading errors...
|
||||
if( !sheetObjects ||
|
||||
_.some( sheetObjects, function(so) { return so.fluenterror; } ) ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var sheets = sheetObjects.map(function(r) { return r.json; });
|
||||
|
||||
// Load the theme...
|
||||
var theme;
|
||||
this.stat( HMEVENT.beforeTheme, { theme: _opts.theme });
|
||||
try {
|
||||
var tFolder = verifyTheme.call( this, _opts.theme );
|
||||
theme = _opts.themeObj = loadTheme( tFolder );
|
||||
}
|
||||
catch( ex ) {
|
||||
var newEx = {
|
||||
fluenterror: HMSTATUS.themeLoad,
|
||||
inner: ex,
|
||||
attempted: _opts.theme
|
||||
};
|
||||
this.err( HMSTATUS.themeLoad, newEx );
|
||||
return null;
|
||||
}
|
||||
this.stat( HMEVENT.afterTheme, { theme: theme });
|
||||
|
||||
// Check for invalid outputs...
|
||||
var inv = verifyOutputs.call( this, dst, theme );
|
||||
if( inv && inv.length ) {
|
||||
this.err( HMSTATUS.invalidFormat, { data: inv, theme: theme } );
|
||||
}
|
||||
|
||||
// Merge input resumes, yielding a single source resume.
|
||||
var rez;
|
||||
if( sheets.length > 1 ) {
|
||||
var isFRESH = !sheets[0].basics;
|
||||
var mixed = _.any( sheets, function(s) { return isFRESH ? s.basics : !s.basics; });
|
||||
this.stat( HMEVENT.beforeMerge, { f: _.clone(sheetObjects), mixed: mixed });
|
||||
if( mixed ) {
|
||||
this.err( HMSTATUS.mixedMerge );
|
||||
}
|
||||
rez = _.reduceRight( sheets, function( a, b, idx ) {
|
||||
return extend( true, b, a );
|
||||
});
|
||||
this.stat( HMEVENT.afterMerge, { r: rez } );
|
||||
}
|
||||
else {
|
||||
rez = sheets[0];
|
||||
}
|
||||
|
||||
// Convert the merged source resume to the theme's format, if necessary
|
||||
var orgFormat = rez.basics ? 'JRS' : 'FRESH';
|
||||
var toFormat = theme.render ? 'JRS' : 'FRESH';
|
||||
if( toFormat !== orgFormat ) {
|
||||
this.stat( HMEVENT.beforeInlineConvert );
|
||||
rez = RConverter[ 'to' + toFormat ]( rez );
|
||||
this.stat( HMEVENT.afterInlineConvert, { file: sheetObjects[0].file, fmt: toFormat });
|
||||
}
|
||||
|
||||
// Add freebie formats to the theme
|
||||
addFreebieFormats( theme );
|
||||
this.stat( HMEVENT.applyTheme, { r: rez, theme: theme });
|
||||
|
||||
// Load the resume into a FRESHResume or JRSResume object
|
||||
_rezObj = new (RTYPES[ toFormat ])().parseJSON( rez );
|
||||
|
||||
// Expand output resumes...
|
||||
var targets = expand( dst, theme );
|
||||
|
||||
// Run the transformation!
|
||||
_.each(targets, function(t) {
|
||||
t.final = single.call( this, t, theme, targets );
|
||||
}, this);
|
||||
|
||||
// Don't send the client back empty-handed
|
||||
return { sheet: _rezObj, targets: targets, processed: targets };
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Prepare for a BUILD run.
|
||||
*/
|
||||
function prep( src, dst, opts ) {
|
||||
|
||||
// Cherry-pick options //_opts = extend( true, _opts, opts );
|
||||
_opts.theme = (opts.theme && opts.theme.toLowerCase().trim()) || 'modern';
|
||||
_opts.prettify = opts.prettify === true;
|
||||
_opts.css = opts.css;
|
||||
_opts.pdf = opts.pdf;
|
||||
_opts.wrap = opts.wrap || 60;
|
||||
_opts.stitles = opts.sectionTitles;
|
||||
_opts.tips = opts.tips;
|
||||
_opts.errHandler = opts.errHandler;
|
||||
_opts.noTips = opts.noTips;
|
||||
_opts.debug = opts.debug;
|
||||
_opts.sort = opts.sort;
|
||||
|
||||
// If two or more files are passed to the GENERATE command and the TO
|
||||
// keyword is omitted, the last file specifies the output file.
|
||||
( src.length > 1 && ( !dst || !dst.length ) ) && dst.push( src.pop() );
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Generate a single target resume such as "out/rez.html" or "out/rez.doc".
|
||||
TODO: Refactor.
|
||||
@param targInfo Information for the target resume.
|
||||
@param theme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
function single( targInfo, theme, finished ) {
|
||||
|
||||
var ret, ex, f = targInfo.file;
|
||||
|
||||
try {
|
||||
|
||||
if( !targInfo.fmt ) { return; }
|
||||
var fType = targInfo.fmt.outFormat
|
||||
, fName = PATH.basename(f, '.' + fType)
|
||||
, theFormat;
|
||||
|
||||
this.stat( HMEVENT.beforeGenerate, {
|
||||
fmt: targInfo.fmt.outFormat,
|
||||
file: PATH.relative(process.cwd(), f)
|
||||
});
|
||||
|
||||
// If targInfo.fmt.files exists, this format is backed by a document.
|
||||
// Fluent/FRESH themes are handled here.
|
||||
if( targInfo.fmt.files && targInfo.fmt.files.length ) {
|
||||
theFormat = _fmts.filter(
|
||||
function(fmt) { return fmt.name === targInfo.fmt.outFormat; })[0];
|
||||
MKDIRP.sync( PATH.dirname( f ) ); // Ensure dest folder exists;
|
||||
_opts.targets = finished;
|
||||
ret = theFormat.gen.generate( _rezObj, f, _opts );
|
||||
}
|
||||
//Otherwise this is an ad-hoc format (JSON, YML, or PNG) that every theme
|
||||
// gets "for free".
|
||||
else {
|
||||
theFormat = _fmts.filter( function(fmt) {
|
||||
return fmt.name === targInfo.fmt.outFormat;
|
||||
})[0];
|
||||
var outFolder = PATH.dirname( f );
|
||||
MKDIRP.sync( outFolder ); // Ensure dest folder exists;
|
||||
ret = theFormat.gen.generate( _rezObj, f, _opts );
|
||||
}
|
||||
}
|
||||
catch( e ) {
|
||||
// Catch any errors caused by generating this file and don't let them
|
||||
// propagate -- typically we want to continue processing other formats
|
||||
// even if this format failed.
|
||||
ex = e;
|
||||
}
|
||||
|
||||
this.stat( HMEVENT.afterGenerate, {
|
||||
fmt: targInfo.fmt.outFormat,
|
||||
file: PATH.relative( process.cwd(), f ),
|
||||
error: ex
|
||||
});
|
||||
|
||||
if( ex ) {
|
||||
if( ex.fluenterror )
|
||||
this.err( ex.fluenterror, ex );
|
||||
else
|
||||
this.err( HMSTATUS.generateError, { inner: ex } );
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Ensure that user-specified outputs/targets are valid.
|
||||
*/
|
||||
function verifyOutputs( targets, theme ) {
|
||||
|
||||
this.stat(HMEVENT.verifyOutputs, { targets: targets, theme: theme });
|
||||
|
||||
return _.reject(
|
||||
targets.map( function( t ) {
|
||||
var pathInfo = parsePath( t );
|
||||
return {
|
||||
format: pathInfo.extname.substr(1)
|
||||
};
|
||||
}),
|
||||
function(t) {
|
||||
return t.format === 'all' || theme.hasFormat( t.format );
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Reinforce the chosen theme with "freebie" formats provided by HackMyResume.
|
||||
A "freebie" format is an output format such as JSON, YML, or PNG that can be
|
||||
generated directly from the resume model or from one of the theme's declared
|
||||
output formats. For example, the PNG format can be generated for any theme
|
||||
that declares an HTML format; the theme doesn't have to provide an explicit
|
||||
PNG template.
|
||||
@param theTheme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
function addFreebieFormats( theTheme ) {
|
||||
// Add freebie formats (JSON, YAML, PNG) every theme gets...
|
||||
// Add HTML-driven PNG only if the theme has an HTML format.
|
||||
theTheme.formats.json = theTheme.formats.json || {
|
||||
freebie: true, title: 'json', outFormat: 'json', pre: 'json',
|
||||
ext: 'json', path: null, data: null
|
||||
};
|
||||
theTheme.formats.yml = theTheme.formats.yml || {
|
||||
freebie: true, title: 'yaml', outFormat: 'yml', pre: 'yml',
|
||||
ext: 'yml', path: null, data: null
|
||||
};
|
||||
if( theTheme.formats.html && !theTheme.formats.png ) {
|
||||
theTheme.formats.png = {
|
||||
freebie: true, title: 'png', outFormat: 'png',
|
||||
ext: 'yml', path: null, data: null
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Expand output files. For example, "foo.all" should be expanded to
|
||||
["foo.html", "foo.doc", "foo.pdf", "etc"].
|
||||
@param dst An array of output files as specified by the user.
|
||||
@param theTheme A FRESHTheme or JRSTheme object.
|
||||
*/
|
||||
function expand( dst, theTheme ) {
|
||||
|
||||
// Set up the destination collection. It's either the array of files passed
|
||||
// by the user or 'out/resume.all' if no targets were specified.
|
||||
var destColl = (dst && dst.length && dst) ||
|
||||
[PATH.normalize('out/resume.all')];
|
||||
|
||||
// Assemble an array of expanded target files... (can't use map() here)
|
||||
var targets = [];
|
||||
destColl.forEach( function(t) {
|
||||
|
||||
var to = PATH.resolve(t), pa = parsePath(to),fmat = pa.extname || '.all';
|
||||
|
||||
|
||||
targets.push.apply(
|
||||
targets, fmat === '.all' ?
|
||||
Object.keys( theTheme.formats ).map( function( k ) {
|
||||
var z = theTheme.formats[k];
|
||||
return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
|
||||
}) :
|
||||
[{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
|
||||
|
||||
// targets.push.apply(
|
||||
// targets, fmat === '.all' ?
|
||||
// Object.keys( explicitFormats ).map( function( k ) {
|
||||
// var z = theTheme.formats[k];
|
||||
// return { file: to.replace( /all$/g, z.outFormat ), fmt: z };
|
||||
// }) :
|
||||
// [{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
|
||||
|
||||
});
|
||||
|
||||
return targets;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Verify the specified theme name/path.
|
||||
*/
|
||||
function verifyTheme( themeNameOrPath ) {
|
||||
var tFolder = PATH.join(
|
||||
parsePath ( require.resolve('fresh-themes') ).dirname,
|
||||
'/themes/',
|
||||
themeNameOrPath
|
||||
);
|
||||
var exists = require('path-exists').sync;
|
||||
if( !exists( tFolder ) ) {
|
||||
tFolder = PATH.resolve( themeNameOrPath );
|
||||
if( !exists( tFolder ) ) {
|
||||
this.err( HMSTATUS.themeNotFound, { data: _opts.theme } );
|
||||
}
|
||||
}
|
||||
return tFolder;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Load the specified theme, which could be either a FRESH theme or a JSON Resume
|
||||
theme.
|
||||
*/
|
||||
function loadTheme( tFolder ) {
|
||||
|
||||
// Create a FRESH or JRS theme object
|
||||
var theTheme = _opts.theme.indexOf('jsonresume-theme-') > -1 ?
|
||||
new JRSTheme().open(tFolder) : new FRESHTheme().open( tFolder );
|
||||
|
||||
// Cache the theme object
|
||||
_opts.themeObj = theTheme;
|
||||
|
||||
return theTheme;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,89 +0,0 @@
|
||||
/**
|
||||
Implementation of the 'convert' verb for HackMyResume.
|
||||
@module verbs/convert
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
|
||||
var ResumeFactory = require('../core/resume-factory')
|
||||
, chalk = require('chalk')
|
||||
, Verb = require('../verbs/verb')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, _ = require('underscore')
|
||||
, HMEVENT = require('../core/event-codes');
|
||||
|
||||
|
||||
var ConvertVerb = module.exports = Verb.extend({
|
||||
|
||||
init: function() {
|
||||
this._super('convert');
|
||||
},
|
||||
|
||||
invoke: function() {
|
||||
this.stat( HMEVENT.begin, { cmd: 'convert' });
|
||||
convert.apply( this, arguments );
|
||||
this.stat( HMEVENT.end );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Convert between FRESH and JRS formats.
|
||||
*/
|
||||
function convert( srcs, dst, opts ) {
|
||||
|
||||
// Housekeeping
|
||||
if( !srcs || !srcs.length ) { throw { fluenterror: 6, quit: true }; }
|
||||
if( !dst || !dst.length ) {
|
||||
if( srcs.length === 1 ) {
|
||||
throw { fluenterror: HMSTATUS.inputOutputParity, quit: true };
|
||||
}
|
||||
else if( srcs.length === 2 ) {
|
||||
dst = dst || []; dst.push( srcs.pop() );
|
||||
}
|
||||
else {
|
||||
throw { fluenterror: HMSTATUS.inputOutputParity, quit: true };
|
||||
}
|
||||
}
|
||||
if(srcs && dst && srcs.length && dst.length && srcs.length !== dst.length){
|
||||
throw { fluenterror: HMSTATUS.inputOutputParity, quit: true };
|
||||
}
|
||||
|
||||
// Load source resumes
|
||||
_.each(srcs, function( src, idx ) {
|
||||
|
||||
// Load the resume
|
||||
var rinfo = ResumeFactory.loadOne( src, {
|
||||
format: null, objectify: true, throw: false
|
||||
});
|
||||
|
||||
// If a load error occurs, report it and move on to the next file (if any)
|
||||
if( rinfo.fluenterror ) {
|
||||
this.err( rinfo.fluenterror, rinfo );
|
||||
return;
|
||||
}
|
||||
|
||||
var s = rinfo.rez
|
||||
, srcFmt = ((s.basics && s.basics.imp) || s.imp).orgFormat === 'JRS' ?
|
||||
'JRS' : 'FRESH'
|
||||
, targetFormat = srcFmt === 'JRS' ? 'FRESH' : 'JRS';
|
||||
|
||||
this.stat(HMEVENT.beforeConvert, { srcFile: rinfo.file, srcFmt: srcFmt, dstFile: dst[idx], dstFmt: targetFormat });
|
||||
|
||||
// Save it to the destination format
|
||||
s.saveAs( dst[idx], targetFormat );
|
||||
|
||||
}, this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,60 +0,0 @@
|
||||
/**
|
||||
Implementation of the 'create' verb for HackMyResume.
|
||||
@module verbs/create
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
|
||||
var MKDIRP = require('mkdirp')
|
||||
, PATH = require('path')
|
||||
, chalk = require('chalk')
|
||||
, Verb = require('../verbs/verb')
|
||||
, _ = require('underscore')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, HMEVENT = require('../core/event-codes');
|
||||
|
||||
|
||||
|
||||
var CreateVerb = module.exports = Verb.extend({
|
||||
|
||||
init: function() {
|
||||
this._super('new');
|
||||
},
|
||||
|
||||
invoke: function() {
|
||||
this.stat( HMEVENT.begin, { cmd: 'create' });
|
||||
create.apply( this, arguments );
|
||||
this.stat( HMEVENT.begin, { cmd: 'convert' });
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Create a new empty resume in either FRESH or JRS format.
|
||||
*/
|
||||
function create( src, dst, opts ) {
|
||||
|
||||
if( !src || !src.length )
|
||||
throw { fluenterror: HMSTATUS.createNameMissing, quit: true };
|
||||
|
||||
_.each( src, function( t ) {
|
||||
var safeFmt = opts.format.toUpperCase();
|
||||
this.stat( HMEVENT.beforeCreate, { fmt: safeFmt, file: t } );
|
||||
MKDIRP.sync( PATH.dirname( t ) ); // Ensure dest folder exists;
|
||||
var RezClass = require('../core/' + safeFmt.toLowerCase() + '-resume' );
|
||||
RezClass.default().save(t);
|
||||
this.stat( HMEVENT.afterCreate, { fmt: safeFmt, file: t } );
|
||||
}, this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,83 +0,0 @@
|
||||
/**
|
||||
Implementation of the 'peek' verb for HackMyResume.
|
||||
@module verbs/peek
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
|
||||
var Verb = require('../verbs/verb')
|
||||
, _ = require('underscore')
|
||||
, __ = require('lodash')
|
||||
, safeLoadJSON = require('../utils/safe-json-loader')
|
||||
, HMSTATUS = require('../core/status-codes')
|
||||
, HMEVENT = require('../core/event-codes');
|
||||
|
||||
|
||||
|
||||
var PeekVerb = module.exports = Verb.extend({
|
||||
|
||||
init: function() {
|
||||
this._super('peek');
|
||||
},
|
||||
|
||||
invoke: function() {
|
||||
this.stat( HMEVENT.begin, { cmd: 'peek' } );
|
||||
peek.apply( this, arguments );
|
||||
this.stat( HMEVENT.end );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Peek at a resume, resume section, or resume field.
|
||||
*/
|
||||
function peek( src, dst, opts ) {
|
||||
|
||||
if(!src || !src.length) throw {fluenterror: HMSTATUS.resumeNotFound};
|
||||
|
||||
var objPath = (dst && dst[0]) || '';
|
||||
|
||||
_.each( src, function( t ) {
|
||||
|
||||
// Fire the 'beforePeek' event 2nd, so we have error/warning/success
|
||||
this.stat( HMEVENT.beforePeek, { file: t, target: objPath } );
|
||||
|
||||
// Load the input file JSON 1st
|
||||
var obj = safeLoadJSON( t );
|
||||
|
||||
// Fetch the requested object path (or the entire file)
|
||||
var tgt;
|
||||
if( !obj.ex )
|
||||
tgt = objPath ? __.get( obj.json, objPath ) : obj.json;
|
||||
|
||||
// Fire the 'afterPeek' event with collected info
|
||||
this.stat( HMEVENT.afterPeek, {
|
||||
file: t,
|
||||
requested: objPath,
|
||||
target: tgt,
|
||||
error: obj.ex
|
||||
});
|
||||
|
||||
// safeLoadJSON can only return a READ error or a PARSE error
|
||||
if( obj.ex ) {
|
||||
var errCode = obj.ex.operation === 'parse' ? HMSTATUS.parseError : HMSTATUS.readError;
|
||||
if( errCode === HMSTATUS.readError )
|
||||
obj.ex.quiet = true;
|
||||
this.setError( errCode, obj.ex );
|
||||
this.err( errCode, obj.ex );
|
||||
}
|
||||
|
||||
}, this);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}());
|
@ -1,103 +0,0 @@
|
||||
/**
|
||||
Implementation of the 'validate' verb for HackMyResume.
|
||||
@module verbs/validate
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function() {
|
||||
|
||||
|
||||
|
||||
var FS = require('fs');
|
||||
var ResumeFactory = require('../core/resume-factory');
|
||||
var SyntaxErrorEx = require('../utils/syntax-error-ex');
|
||||
var chalk = require('chalk');
|
||||
var Verb = require('../verbs/verb');
|
||||
var HMSTATUS = require('../core/status-codes');
|
||||
var HMEVENT = require('../core/event-codes');
|
||||
var _ = require('underscore');
|
||||
|
||||
|
||||
|
||||
/** An invokable resume validation command. */
|
||||
var ValidateVerb = module.exports = Verb.extend({
|
||||
|
||||
init: function() {
|
||||
this._super('validate');
|
||||
},
|
||||
|
||||
invoke: function() {
|
||||
this.stat( HMEVENT.begin, { cmd: 'validate' } );
|
||||
validate.apply( this, arguments );
|
||||
this.stat( HMEVENT.end );
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
/** Validate 1 to N resumes in FRESH or JSON Resume format. */
|
||||
function validate( sources, unused, opts ) {
|
||||
|
||||
if( !sources || !sources.length )
|
||||
throw { fluenterror: HMSTATUS.resumeNotFoundAlt, quit: true };
|
||||
|
||||
var validator = require('is-my-json-valid');
|
||||
var schemas = {
|
||||
fresh: require('fresca'),
|
||||
jars: require('../core/resume.json')
|
||||
};
|
||||
|
||||
var resumes = ResumeFactory.load( sources, {
|
||||
format: null,
|
||||
objectify: false
|
||||
}, this );
|
||||
|
||||
// Validate input resumes. Return a { file: <f>, isValid: <v>} object for
|
||||
// each resume (valid, invalid, or broken).
|
||||
return resumes.map( function( src ) {
|
||||
|
||||
var ret = { file: src, isValid: false };
|
||||
|
||||
// If there was an error reading the resume
|
||||
if( src.fluenterror ) {
|
||||
if( opts.assert ) throw src;
|
||||
this.setError( src.fluenterror, src );
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Successfully read the resume. Now parse it as JSON.
|
||||
var json = src.json, fmt = json.basics ? 'jrs' : 'fresh', errors = [];
|
||||
try {
|
||||
var validate = validator( schemas[ fmt ], { // Note [1]
|
||||
formats: {
|
||||
date: /^\d{4}(?:-(?:0[0-9]{1}|1[0-2]{1})(?:-[0-9]{2})?)?$/
|
||||
}
|
||||
});
|
||||
|
||||
ret.isValid = validate( json );
|
||||
if( !ret.isValid ) {
|
||||
errors = validate.errors;
|
||||
}
|
||||
|
||||
}
|
||||
catch( exc ) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
this.stat( HMEVENT.afterValidate, { file: src.file, isValid: ret.isValid,
|
||||
fmt: fmt.replace( 'jars', 'JSON Resume' ), errors: errors });
|
||||
|
||||
if( opts.assert && !ret.isValid ) {
|
||||
throw { fluenterror: HMSTATUS.invalid, shouldExit: true };
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
}, this);
|
||||
|
||||
}
|
||||
|
||||
}());
|
@ -1,96 +0,0 @@
|
||||
/**
|
||||
Definition of the Verb class.
|
||||
@module verbs/verb
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
(function(){
|
||||
|
||||
|
||||
|
||||
// Use J. Resig's nifty class implementation
|
||||
var Class = require( '../utils/class' )
|
||||
, EVENTS = require('events');
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
An instantiation of a HackMyResume command.
|
||||
@class Verb
|
||||
*/
|
||||
var Verb = module.exports = Class.extend({
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Constructor. Automatically called at creation.
|
||||
*/
|
||||
init: function( moniker ) {
|
||||
this.moniker = moniker;
|
||||
this.emitter = new EVENTS.EventEmitter();
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Forward subscriptions to the event emitter.
|
||||
*/
|
||||
on: function() {
|
||||
this.emitter.on.apply( this.emitter, arguments );
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Fire an arbitrary event, scoped to "hmr:".
|
||||
*/
|
||||
fire: function(evtName, payload) {
|
||||
payload = payload || { };
|
||||
payload.cmd = this.moniker;
|
||||
this.emitter.emit( 'hmr:' + evtName, payload );
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Handle an error condition.
|
||||
*/
|
||||
err: function( errorCode, payload, hot ) {
|
||||
payload = payload || { };
|
||||
payload.sub = payload.fluenterror = errorCode;
|
||||
payload.throw = hot;
|
||||
this.fire( 'error', payload );
|
||||
if( hot ) throw payload;
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
|
||||
/**
|
||||
Fire the 'hmr:status' error event.
|
||||
*/
|
||||
stat: function( subEvent, payload ) {
|
||||
payload = payload || { };
|
||||
payload.sub = subEvent;
|
||||
this.fire('status', payload);
|
||||
return true;
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
Associate error info with the invocation.
|
||||
*/
|
||||
setError: function( code, obj ) {
|
||||
this.errorCode = code;
|
||||
this.errorObj = obj;
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
}());
|
207
test/test-api.js
207
test/test-api.js
@ -1,207 +0,0 @@
|
||||
/**
|
||||
@module test-api.js
|
||||
*/
|
||||
|
||||
var chai = require('chai')
|
||||
, expect = chai.expect
|
||||
, should = chai.should()
|
||||
, path = require('path')
|
||||
, _ = require('underscore')
|
||||
, FRESHResume = require('../src/core/fresh-resume')
|
||||
, FCMD = require( '../src/hackmyapi')
|
||||
, validator = require('is-my-json-valid')
|
||||
, HMRMAIN = require('../src/cli/main')
|
||||
, EXTEND = require('extend');
|
||||
|
||||
chai.config.includeStack = false;
|
||||
|
||||
var _sheet;
|
||||
|
||||
var opts = {
|
||||
format: 'FRESH',
|
||||
prettify: true,
|
||||
silent: false,
|
||||
assert: true // Causes validation errors to throw exceptions
|
||||
};
|
||||
|
||||
var opts2 = {
|
||||
format: 'JRS',
|
||||
prettify: true,
|
||||
silent: true
|
||||
};
|
||||
|
||||
var sb = 'test/sandbox/';
|
||||
var ft = 'node_modules/fresh-test-resumes/src/fresh/';
|
||||
|
||||
var tests = [
|
||||
|
||||
[ 'new',
|
||||
[sb + 'new-fresh-resume.json'],
|
||||
[],
|
||||
opts,
|
||||
' (FRESH format)'
|
||||
],
|
||||
|
||||
[ 'new',
|
||||
[sb + 'new-jrs-resume.json'],
|
||||
[],
|
||||
opts2,
|
||||
' (JRS format)'
|
||||
],
|
||||
|
||||
[
|
||||
'new',
|
||||
[sb + 'new-1.json', sb + 'new-2.json', sb + 'new-3.json'],
|
||||
[],
|
||||
opts,
|
||||
' (multiple FRESH resumes)'
|
||||
],
|
||||
|
||||
[ 'new',
|
||||
[sb + 'new-jrs-1.json', sb + 'new-jrs-2.json', sb + 'new-jrs-3.json'],
|
||||
[],
|
||||
opts,
|
||||
' (multiple JRS resumes)'
|
||||
],
|
||||
|
||||
[ '!new',
|
||||
[],
|
||||
[],
|
||||
opts,
|
||||
" (when a filename isn't specified)"
|
||||
],
|
||||
|
||||
[ 'validate',
|
||||
[ft + 'jane-fullstacker.json'],
|
||||
[],
|
||||
opts,
|
||||
' (jane-q-fullstacker|FRESH)'
|
||||
],
|
||||
|
||||
[ 'validate',
|
||||
[ft + 'johnny-trouble.json'],
|
||||
[],
|
||||
opts,
|
||||
' (johnny-trouble|FRESH)'
|
||||
],
|
||||
|
||||
[ 'validate',
|
||||
[sb + 'new-fresh-resume.json'],
|
||||
[],
|
||||
opts,
|
||||
' (new-fresh-resume|FRESH)'
|
||||
],
|
||||
|
||||
[ 'validate',
|
||||
['test/resumes/jrs-0.0.0/richard-hendriks.json'],
|
||||
[],
|
||||
opts2,
|
||||
' (richard-hendriks.json|JRS)'
|
||||
],
|
||||
|
||||
[ 'validate',
|
||||
['test/resumes/jrs-0.0.0/jane-incomplete.json'],
|
||||
[],
|
||||
opts2,
|
||||
' (jane-incomplete.json|JRS)'
|
||||
],
|
||||
|
||||
[ 'validate',
|
||||
[sb + 'new-1.json', sb + 'new-jrs-resume.json', sb + 'new-1.json',
|
||||
sb + 'new-2.json', sb + 'new-3.json'],
|
||||
[],
|
||||
opts,
|
||||
' (5|BOTH)'
|
||||
],
|
||||
|
||||
[ 'analyze',
|
||||
[ft + 'jane-fullstacker.json'],
|
||||
[],
|
||||
opts,
|
||||
' (jane-q-fullstacker|FRESH)'
|
||||
],
|
||||
|
||||
[ 'analyze',
|
||||
['test/resumes/jrs-0.0.0/richard-hendriks.json'],
|
||||
[],
|
||||
opts2,
|
||||
' (richard-hendriks|JRS)'
|
||||
],
|
||||
|
||||
[ 'build',
|
||||
[ ft + 'jane-fullstacker.json', ft + 'override/jane-fullstacker-override.fresh.json' ],
|
||||
[ sb + 'merged/jane-fullstacker-gamedev.fresh.all'],
|
||||
opts,
|
||||
' (jane-q-fullstacker w/ override|FRESH)'
|
||||
],
|
||||
|
||||
[ 'build',
|
||||
[ ft + 'override/jane-partial-a.json', ft + 'override/jane-partial-b.json',
|
||||
ft + 'override/jane-partial-c.json' ],
|
||||
[ sb + 'merged/jane-abc.fresh.all'],
|
||||
opts,
|
||||
' (jane merge A + B + C|FRESH)',
|
||||
function( r ) {
|
||||
var expected = [
|
||||
'name','meta','info', 'contact', 'location', 'projects', 'social',
|
||||
'employment', 'education', 'affiliation', 'service', 'skills',
|
||||
'samples', 'writing', 'reading', 'speaking', 'recognition',
|
||||
'references', 'testimonials', 'languages', 'interests',
|
||||
'extracurricular', 'governance'
|
||||
];
|
||||
return Object.keys( _.pick( r, expected ) ).length === expected.length;
|
||||
}
|
||||
],
|
||||
|
||||
[ '!build',
|
||||
[ ft + 'jane-fullstacker.json'],
|
||||
[ sb + 'shouldnt-exist.pdf' ],
|
||||
EXTEND(true, {}, opts, { theme: 'awesome' }),
|
||||
' (jane-q-fullstacker + Awesome + PDF|FRESH)'
|
||||
]
|
||||
|
||||
];
|
||||
|
||||
describe('Testing API interface', function () {
|
||||
|
||||
function run( verb, src, dst, opts, msg, fnTest ) {
|
||||
|
||||
msg = msg || '.';
|
||||
var shouldSucceed = true;
|
||||
if( verb[0] === '!' ) {
|
||||
verb = verb.substr(1);
|
||||
shouldSucceed = false;
|
||||
}
|
||||
|
||||
it( 'The ' + verb.toUpperCase() + ' command should ' + (shouldSucceed ? ' SUCCEED' : ' FAIL') + msg, function () {
|
||||
|
||||
function runIt() {
|
||||
try {
|
||||
var v = new FCMD.verbs[verb]();
|
||||
v.on('hmr:error', function(ex) { throw ex; });
|
||||
var r = v.invoke( src, dst, opts );
|
||||
if( fnTest )
|
||||
if( !fnTest( r.sheet ) )
|
||||
throw "Test: Unexpected API result.";
|
||||
}
|
||||
catch(ex) {
|
||||
console.error(ex);
|
||||
if( ex.stack || (ex.inner && ex.inner.stack))
|
||||
console.error( ex.stack || ex.inner.stack );
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
|
||||
if( shouldSucceed )
|
||||
runIt.should.not.Throw();
|
||||
else
|
||||
runIt.should.Throw();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
tests.forEach( function(a) {
|
||||
run.apply( /* The players of */ null, a );
|
||||
});
|
||||
|
||||
});
|
@ -1,71 +0,0 @@
|
||||
|
||||
var chai = require('chai')
|
||||
, expect = chai.expect
|
||||
, should = chai.should()
|
||||
, path = require('path')
|
||||
, _ = require('underscore')
|
||||
, FRESHResume = require('../src/core/fresh-resume')
|
||||
, validator = require('is-my-json-valid');
|
||||
|
||||
chai.config.includeStack = false;
|
||||
|
||||
function testResume(opts) {
|
||||
|
||||
describe( opts.title + ' (FRESH)', function () {
|
||||
|
||||
var _sheet;
|
||||
|
||||
it('should open without throwing an exception', function () {
|
||||
function tryOpen() {
|
||||
_sheet = new FRESHResume().open( opts.path );
|
||||
}
|
||||
tryOpen.should.not.Throw();
|
||||
});
|
||||
|
||||
it('should have one or more of each section', function() {
|
||||
var newObj = _.pick( _sheet, opts.sections );
|
||||
expect( Object.keys(newObj).length ).to.equal( opts.sections.length );
|
||||
});
|
||||
|
||||
it('should have a work duration of ' + opts.duration + ' years', function() {
|
||||
_sheet.computed.numYears.should.equal( opts.duration );
|
||||
});
|
||||
|
||||
it('should save without throwing an exception', function(){
|
||||
function trySave() {
|
||||
_sheet.save( 'test/sandbox/' + opts.title + '.json' );
|
||||
}
|
||||
trySave.should.not.Throw();
|
||||
});
|
||||
|
||||
it('should not be modified after saving', function() {
|
||||
var savedSheet = new FRESHResume().open('test/sandbox/' + opts.title + '.json');
|
||||
_sheet.stringify().should.equal( savedSheet.stringify() );
|
||||
});
|
||||
|
||||
it('should validate against the FRESH resume schema', function() {
|
||||
var result = _sheet.isValid();
|
||||
// var schemaJson = require('fresca');
|
||||
// var validate = validator( schemaJson, { verbose: true } );
|
||||
// var result = validate( JSON.parse( _sheet.imp.raw ) );
|
||||
result || console.log("\n\nOops, resume didn't validate. " +
|
||||
"Validation errors:\n\n", _sheet.imp.validationErrors, "\n\n");
|
||||
result.should.equal( true );
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
var sects = [ 'info', 'employment', 'service', 'skills', 'education', 'writing', 'recognition', 'references' ];
|
||||
testResume({ title: 'jane-q-fullstacker', path: 'node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json', duration: 7, sections: sects });
|
||||
testResume({ title: 'johnny-trouble-resume', path: 'node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json', duration: 4, sections: sects });
|
||||
|
||||
sects = [ 'info', 'contact', 'location' ];
|
||||
testResume({ title: 'jane-q-fullstacker A', path: 'node_modules/fresh-test-resumes/src/fresh/override/jane-partial-a.json', duration: 0, sections: sects });
|
||||
|
||||
sects = [ 'projects', 'social', 'employment', 'education', 'affiliation' ];
|
||||
testResume({ title: 'jane-q-fullstacker B', path: 'node_modules/fresh-test-resumes/src/fresh/override/jane-partial-b.json', duration: 7, sections: sects });
|
||||
|
||||
sects = [ 'service', 'skills', 'samples', 'writing', 'reading', 'speaking', 'recognition', 'references', 'testimonials', 'languages', 'interests', 'extracurricular', 'governance' ];
|
||||
testResume({ title: 'jane-q-fullstacker C', path: 'node_modules/fresh-test-resumes/src/fresh/override/jane-partial-c.json', duration: 0, sections: sects });
|
@ -1,69 +0,0 @@
|
||||
|
||||
var chai = require('chai')
|
||||
, expect = chai.expect
|
||||
, should = chai.should()
|
||||
, path = require('path')
|
||||
, _ = require('underscore')
|
||||
, JRSResume = require('../src/core/jrs-resume')
|
||||
, validator = require('is-my-json-valid');
|
||||
|
||||
chai.config.includeStack = false;
|
||||
|
||||
function testResume( opts ) {
|
||||
|
||||
describe( opts.title + ' (JRS)', function() {
|
||||
|
||||
opts.isValid = opts.isValid !== false;
|
||||
|
||||
var _sheet;
|
||||
|
||||
it('should open without throwing an exception', function () {
|
||||
var that = this;
|
||||
function tryOpen() {
|
||||
_sheet = new JRSResume().open(
|
||||
path.join( __dirname, 'resumes/jrs-0.0.0/' + opts.title + '.json' ) );
|
||||
}
|
||||
tryOpen.should.not.Throw();
|
||||
});
|
||||
|
||||
it('should have one or more of each section', function() {
|
||||
var newObj = _.pick( _sheet, opts.sections );
|
||||
expect( Object.keys(newObj).length ).to.equal( opts.sections.length );
|
||||
});
|
||||
|
||||
it('should have a work duration of ' + opts.duration + ' years', function() {
|
||||
_sheet.basics.computed.numYears.should.equal( opts.duration );
|
||||
});
|
||||
|
||||
it('should save without throwing an exception', function() {
|
||||
var that = this;
|
||||
function trySave() {
|
||||
_sheet.save( 'test/sandbox/' + opts.title + '.json' );
|
||||
}
|
||||
trySave.should.not.Throw();
|
||||
});
|
||||
|
||||
it('should not be modified after saving', function() {
|
||||
var savedSheet = new JRSResume().open( 'test/sandbox/' + opts.title + '.json' );
|
||||
_sheet.stringify().should.equal( savedSheet.stringify() );
|
||||
});
|
||||
|
||||
it('should ' + (opts.isValid ? '' : 'NOT ') + 'validate against the JSON Resume schema', function() {
|
||||
var result = _sheet.isValid();
|
||||
// var schemaJson = require('../src/core/resume.json');
|
||||
// var validate = validator( schemaJson, { verbose: true } );
|
||||
// var result = validate( JSON.parse( _sheet.imp.raw ) );
|
||||
result || console.log("\n\nOops, resume didn't validate. " +
|
||||
"Validation errors:\n\n", _sheet.basics.imp.validationErrors, "\n\n");
|
||||
result.should.equal( opts.isValid );
|
||||
});
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
var sects = [ 'basics', 'work', 'volunteer', 'skills', 'education', 'publications', 'awards', 'references' ];
|
||||
|
||||
testResume({ title: 'jane-q-fullstacker', duration: 7, sections: sects });
|
||||
testResume({ title: 'jane-incomplete', duration: 0, sections: _.without(sects, 'awards', 'work') });
|
||||
testResume({ title: 'richard-hendriks', duration: 1, sections: sects });
|
||||
testResume({ title: 'empty', duration: 0, sections: [], isValid: false });
|
@ -1,86 +0,0 @@
|
||||
|
||||
var chai = require('chai')
|
||||
, expect = chai.expect
|
||||
, should = chai.should()
|
||||
, path = require('path')
|
||||
, _ = require('underscore')
|
||||
, FRESHResume = require('../src/core/fresh-resume')
|
||||
, HMR = require( '../src/hackmyapi')
|
||||
, validator = require('is-my-json-valid')
|
||||
, READFILES = require('recursive-readdir-sync')
|
||||
, fileContains = require('../src/utils/file-contains')
|
||||
, FS = require('fs')
|
||||
, CHALK = require('chalk');
|
||||
|
||||
chai.config.includeStack = true;
|
||||
|
||||
function genThemes( title, src, fmt ) {
|
||||
|
||||
describe('Testing themes against ' + title.toUpperCase() + ' resume ' + '(' + fmt + ')' , function () {
|
||||
|
||||
var _sheet;
|
||||
|
||||
function genTheme( fmt, src, themeName, themeLoc, testTitle ) {
|
||||
themeLoc = themeLoc || themeName;
|
||||
testTitle = themeName.toUpperCase() + ' theme (' + fmt + ') should generate without throwing an exception';
|
||||
it( testTitle, function () {
|
||||
function tryOpen() {
|
||||
//var src = ['node_modules/jane-q-fullstacker/resume/jane-resume.json'];
|
||||
var dst = ['test/sandbox/' + fmt + '/' + title + '/' + themeName + '/resume.all'];
|
||||
var opts = {
|
||||
theme: themeLoc,
|
||||
format: fmt,
|
||||
prettify: true,
|
||||
silent: false,
|
||||
css: 'embed',
|
||||
debug: true
|
||||
};
|
||||
try {
|
||||
var v = new HMR.verbs.build();
|
||||
v.invoke( src, dst, opts );
|
||||
}
|
||||
catch(ex) {
|
||||
console.error( ex );
|
||||
console.error( ex.stack );
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
tryOpen.should.not.Throw();
|
||||
});
|
||||
}
|
||||
|
||||
genTheme(fmt, src, 'hello-world');
|
||||
genTheme(fmt, src, 'compact');
|
||||
genTheme(fmt, src, 'modern');
|
||||
genTheme(fmt, src, 'underscore');
|
||||
genTheme(fmt, src, 'awesome');
|
||||
genTheme(fmt, src, 'positive');
|
||||
genTheme(fmt, src, 'jsonresume-theme-boilerplate', 'node_modules/jsonresume-theme-boilerplate' );
|
||||
genTheme(fmt, src, 'jsonresume-theme-sceptile', 'node_modules/jsonresume-theme-sceptile' );
|
||||
genTheme(fmt, src, 'jsonresume-theme-modern', 'node_modules/jsonresume-theme-modern' );
|
||||
genTheme(fmt, src, 'jsonresume-theme-classy', 'node_modules/jsonresume-theme-classy' );
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function folderContains( needle, haystack ) {
|
||||
return _.some( READFILES( path.join(__dirname, haystack) ), function( absPath ) {
|
||||
if( FS.lstatSync( absPath ).isFile() ) {
|
||||
if( fileContains( absPath, needle ) ) {
|
||||
console.error('Found invalid metadata in ' + absPath);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
genThemes( 'jane-q-fullstacker', ['node_modules/fresh-test-resumes/src/fresh/jane-fullstacker.json'], 'FRESH' );
|
||||
genThemes( 'johnny-trouble', ['node_modules/fresh-test-resumes/src/fresh/johnny-trouble.json'], 'FRESH' );
|
||||
genThemes( 'richard-hendriks', ['test/resumes/jrs-0.0.0/richard-hendriks.json'], 'JRS' );
|
||||
|
||||
describe('Verifying generated theme files...', function() {
|
||||
it('Generated files should not contain ICE.', function() {
|
||||
expect( folderContains('@@@@', 'sandbox') ).to.be.false;
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user