1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2025-05-10 15:57:07 +01:00

Relocate internal sources to HackMyAPI.

Move internal sources and related tests to:

https://github.com/hacksalot/HackMyAPI
This commit is contained in:
hacksalot
2016-01-24 09:55:04 -05:00
parent fa29f9794d
commit d3194fba19
61 changed files with 15 additions and 6109 deletions

View File

@ -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;
};
})();

View File

@ -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;
};
}());

View File

@ -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;
};
}());

View File

@ -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;
};
}());

View File

@ -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);
}
});
}
}());

View File

@ -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;
};
}());

View File

@ -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 ) {
}
};
}());

View File

@ -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;
};
}());

View File

@ -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;
};
}());

View File

@ -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;
}());