mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-02 20:37:08 +01:00
Finish HackMyCore reshaping.
Reintroduce HackMyCore, dropping the interim submodule, and reorganize and improve tests.
This commit is contained in:
72
dist/utils/class.js
vendored
Normal file
72
dist/utils/class.js
vendored
Normal file
@ -0,0 +1,72 @@
|
||||
/**
|
||||
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;
|
||||
};
|
||||
|
||||
})();
|
12
dist/utils/file-contains.js
vendored
Normal file
12
dist/utils/file-contains.js
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
|
||||
/**
|
||||
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;
|
||||
};
|
||||
|
||||
}).call(this);
|
61
dist/utils/html-to-wpml.js
vendored
Normal file
61
dist/utils/html-to-wpml.js
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
|
||||
/**
|
||||
Definition of the Markdown to WordProcessingML conversion routine.
|
||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||
@module utils/html-to-wpml
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var HTML5Tokenizer, _;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
HTML5Tokenizer = require('simple-html-tokenizer');
|
||||
|
||||
module.exports = function(html) {
|
||||
var final, is_bold, is_italic, is_link, link_url, tokens;
|
||||
tokens = HTML5Tokenizer.tokenize(html);
|
||||
final = is_bold = is_italic = is_link = link_url = '';
|
||||
_.each(tokens, function(tok) {
|
||||
var style;
|
||||
switch (tok.type) {
|
||||
case 'StartTag':
|
||||
switch (tok.tagName) {
|
||||
case 'p':
|
||||
return final += '<w:p>';
|
||||
case 'strong':
|
||||
return is_bold = true;
|
||||
case 'em':
|
||||
return is_italic = true;
|
||||
case 'a':
|
||||
is_link = true;
|
||||
return link_url = tok.attributes.filter(function(attr) {
|
||||
return attr[0] === 'href';
|
||||
})[0][1];
|
||||
}
|
||||
break;
|
||||
case 'EndTag':
|
||||
switch (tok.tagName) {
|
||||
case 'p':
|
||||
return final += '</w:p>';
|
||||
case 'strong':
|
||||
return is_bold = false;
|
||||
case 'em':
|
||||
return is_italic = false;
|
||||
case 'a':
|
||||
return is_link = false;
|
||||
}
|
||||
break;
|
||||
case 'Chars':
|
||||
if ((tok.chars.trim().length)) {
|
||||
style = is_bold ? '<w:b/>' : '';
|
||||
style += is_italic ? '<w:i/>' : '';
|
||||
style += is_link ? '<w:rStyle w:val="Hyperlink"/>' : '';
|
||||
return 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>' : '');
|
||||
}
|
||||
}
|
||||
});
|
||||
return final;
|
||||
};
|
||||
|
||||
}).call(this);
|
28
dist/utils/md2chalk.js
vendored
Normal file
28
dist/utils/md2chalk.js
vendored
Normal file
@ -0,0 +1,28 @@
|
||||
|
||||
/**
|
||||
Inline Markdown-to-Chalk conversion routines.
|
||||
@license MIT. See LICENSE.md for details.
|
||||
@module utils/md2chalk
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var CHALK, LO, MD;
|
||||
|
||||
MD = require('marked');
|
||||
|
||||
CHALK = require('chalk');
|
||||
|
||||
LO = require('lodash');
|
||||
|
||||
module.exports = function(v, style, boldStyle) {
|
||||
var temp;
|
||||
boldStyle = boldStyle || 'bold';
|
||||
temp = v.replace(/\*\*(.*?)\*\*/g, LO.get(CHALK, boldStyle)('$1'));
|
||||
if (style) {
|
||||
return LO.get(CHALK, style)(temp);
|
||||
} else {
|
||||
return temp;
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
77
dist/utils/rasterize.js
vendored
Normal file
77
dist/utils/rasterize.js
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
(function() {
|
||||
"use strict";
|
||||
var address, output, page, pageHeight, pageWidth, size, system;
|
||||
|
||||
page = require('webpage').create();
|
||||
|
||||
system = require('system');
|
||||
|
||||
address = output = size = null;
|
||||
|
||||
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);
|
||||
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 {
|
||||
return window.setTimeout(function() {
|
||||
page.render(output);
|
||||
phantom.exit();
|
||||
}, 200);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}).call(this);
|
32
dist/utils/safe-json-loader.js
vendored
Normal file
32
dist/utils/safe-json-loader.js
vendored
Normal file
@ -0,0 +1,32 @@
|
||||
|
||||
/**
|
||||
Definition of the SafeJsonLoader class.
|
||||
@module utils/safe-json-loader
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var FS, SyntaxErrorEx;
|
||||
|
||||
FS = require('fs');
|
||||
|
||||
SyntaxErrorEx = require('./syntax-error-ex');
|
||||
|
||||
module.exports = function(file) {
|
||||
var ret, retRaw;
|
||||
ret = {};
|
||||
try {
|
||||
ret.raw = FS.readFileSync(file, 'utf8');
|
||||
ret.json = JSON.parse(ret.raw);
|
||||
} catch (_error) {
|
||||
retRaw = ret.raw && ret.raw.trim();
|
||||
ret.ex = {
|
||||
operation: retRaw ? 'parse' : 'read',
|
||||
inner: SyntaxErrorEx.is(_error) ? new SyntaxErrorEx(_error, retRaw) : _error,
|
||||
file: file
|
||||
};
|
||||
}
|
||||
return ret;
|
||||
};
|
||||
|
||||
}).call(this);
|
46
dist/utils/safe-spawn.js
vendored
Normal file
46
dist/utils/safe-spawn.js
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
|
||||
/**
|
||||
Safe spawn utility for HackMyResume / FluentCV.
|
||||
@module utils/safe-spawn
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
module.exports = function(cmd, args, isSync, callback) {
|
||||
var info, spawn;
|
||||
try {
|
||||
spawn = require('child_process')[isSync ? 'spawnSync' : 'spawn'];
|
||||
info = spawn(cmd, args);
|
||||
if (!isSync) {
|
||||
info.on('error', function(err) {
|
||||
if (callback != null) {
|
||||
callback(err);
|
||||
} else {
|
||||
throw {
|
||||
cmd: cmd,
|
||||
inner: err
|
||||
};
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (info.error) {
|
||||
if (callback != null) {
|
||||
callback(err);
|
||||
} else {
|
||||
throw {
|
||||
cmd: cmd,
|
||||
inner: info.error
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (_error) {
|
||||
if (callback != null) {
|
||||
return callback(_error);
|
||||
} else {
|
||||
throw _error;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
62
dist/utils/string-transformer.js
vendored
Normal file
62
dist/utils/string-transformer.js
vendored
Normal file
@ -0,0 +1,62 @@
|
||||
|
||||
/**
|
||||
Object string transformation.
|
||||
@module utils/string-transformer
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
(function() {
|
||||
var _, moment;
|
||||
|
||||
_ = require('underscore');
|
||||
|
||||
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, transformStringsInObject;
|
||||
that = this;
|
||||
transformStringsInObject = function(obj, filters) {
|
||||
if (!obj) {
|
||||
return;
|
||||
}
|
||||
if (moment.isMoment(obj)) {
|
||||
return;
|
||||
}
|
||||
if (_.isArray(obj)) {
|
||||
return obj.forEach(function(elem, idx, ar) {
|
||||
if (typeof elem === 'string' || elem instanceof String) {
|
||||
return ar[idx] = transformer(null, elem);
|
||||
} else if (_.isObject(elem)) {
|
||||
return transformStringsInObject(elem, filters);
|
||||
}
|
||||
});
|
||||
} else if (_.isObject(obj)) {
|
||||
return Object.keys(obj).forEach(function(k) {
|
||||
var sub;
|
||||
if (filters.length && _.contains(filters, k)) {
|
||||
return;
|
||||
}
|
||||
sub = obj[k];
|
||||
if (typeof sub === 'string' || sub instanceof String) {
|
||||
return obj[k] = transformer(k, sub);
|
||||
} else if (_.isObject(sub)) {
|
||||
return transformStringsInObject(sub, filters);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
Object.keys(ret).forEach(function(member) {
|
||||
if (!filt || !filt.length || !_.contains(filt, member)) {
|
||||
return transformStringsInObject(ret[member], filt || []);
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
};
|
||||
|
||||
}).call(this);
|
27
dist/utils/string.js
vendored
Normal file
27
dist/utils/string.js
vendored
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
/**
|
||||
Definitions of string utility functions.
|
||||
@module utils/string
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
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;
|
||||
};
|
||||
|
||||
}).call(this);
|
39
dist/utils/syntax-error-ex.js
vendored
Normal file
39
dist/utils/syntax-error-ex.js
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
|
||||
/**
|
||||
Definition of the SyntaxErrorEx class.
|
||||
@module utils/syntax-error-ex
|
||||
@license MIT. See LICENSE.md for details.
|
||||
*/
|
||||
|
||||
|
||||
/**
|
||||
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() {
|
||||
var SyntaxErrorEx;
|
||||
|
||||
SyntaxErrorEx = function(ex, rawData) {
|
||||
var JSONLint, colNum, lineNum, lint;
|
||||
lineNum = null;
|
||||
colNum = null;
|
||||
JSONLint = require('json-lint');
|
||||
lint = JSONLint(rawData, {
|
||||
comments: false
|
||||
});
|
||||
this.line = lint.error ? lint.line : '???';
|
||||
return this.col = lint.error ? lint.character : '???';
|
||||
};
|
||||
|
||||
SyntaxErrorEx.is = function(ex) {
|
||||
return ex instanceof SyntaxError;
|
||||
};
|
||||
|
||||
module.exports = SyntaxErrorEx;
|
||||
|
||||
}).call(this);
|
Reference in New Issue
Block a user