mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2025-05-15 01:57:08 +01:00
Compare commits
6 Commits
Author | SHA1 | Date | |
---|---|---|---|
7c0354046c | |||
43cd1c7e52 | |||
f80c333361 | |||
cdbb264093 | |||
87b3bbe785 | |||
b92cf7298a |
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hackmyresume",
|
"name": "hackmyresume",
|
||||||
"version": "1.0.1",
|
"version": "1.1.0",
|
||||||
"description": "Generate polished résumés and CVs in HTML, Markdown, LaTeX, MS Word, PDF, plain text, JSON, XML, YAML, smoke signal, and carrier pigeon.",
|
"description": "Generate polished résumés and CVs in HTML, Markdown, LaTeX, MS Word, PDF, plain text, JSON, XML, YAML, smoke signal, and carrier pigeon.",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
169
src/eng/generic-helpers.js
Normal file
169
src/eng/generic-helpers.js
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
/**
|
||||||
|
Generic template helper definitions for FluentCV.
|
||||||
|
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||||
|
@module generic-helpers.js
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
(function() {
|
||||||
|
|
||||||
|
var MD = require('marked')
|
||||||
|
, H2W = require('../utils/html-to-wpml')
|
||||||
|
, moment = require('moment')
|
||||||
|
, _ = require('underscore');
|
||||||
|
|
||||||
|
/**
|
||||||
|
Generic template helper function definitions.
|
||||||
|
@class GenericHelpers
|
||||||
|
*/
|
||||||
|
var GenericHelpers = module.exports = {
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert the input date to a specified format through Moment.js.
|
||||||
|
@method formatDate
|
||||||
|
*/
|
||||||
|
formatDate: function(datetime, format) {
|
||||||
|
return moment ? moment( datetime ).format( format ) : datetime;
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Convert inline Markdown to inline WordProcessingML.
|
||||||
|
@method wpml
|
||||||
|
*/
|
||||||
|
wpml: function( txt, inline ) {
|
||||||
|
if(!txt) return '';
|
||||||
|
inline = (inline && !inline.hash) || false;
|
||||||
|
txt = inline ?
|
||||||
|
MD(txt.trim()).replace(/^\s*<p>|<\/p>\s*$/gi, '') :
|
||||||
|
MD(txt.trim());
|
||||||
|
txt = H2W( txt.trim() );
|
||||||
|
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.
|
||||||
|
@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.
|
||||||
|
@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() : '';
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return true if either value is truthy.
|
||||||
|
@method either
|
||||||
|
*/
|
||||||
|
either: function( lhs, rhs, options ) {
|
||||||
|
if (lhs || rhs) return options.fn(this);
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
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, intVal );
|
||||||
|
}
|
||||||
|
return idx;
|
||||||
|
}
|
||||||
|
|
||||||
|
}());
|
@ -31,7 +31,7 @@ Definition of the HandlebarsGenerator class.
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Register necessary helpers.
|
// Register necessary helpers.
|
||||||
registerHelpers();
|
registerHelpers( theme );
|
||||||
|
|
||||||
// Compile and run the Handlebars template.
|
// Compile and run the Handlebars template.
|
||||||
var template = HANDLEBARS.compile(jst);
|
var template = HANDLEBARS.compile(jst);
|
||||||
|
@ -8,116 +8,17 @@ Template helper definitions for Handlebars.
|
|||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
var HANDLEBARS = require('handlebars')
|
var HANDLEBARS = require('handlebars')
|
||||||
, MD = require('marked')
|
, _ = require('underscore')
|
||||||
, H2W = require('../utils/html-to-wpml')
|
, helpers = require('./generic-helpers');
|
||||||
, moment = require('moment')
|
|
||||||
, _ = require('underscore');
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Register useful Handlebars helpers.
|
Register useful Handlebars helpers.
|
||||||
@method registerHelpers
|
@method registerHelpers
|
||||||
*/
|
*/
|
||||||
module.exports = function() {
|
module.exports = function( theme ) {
|
||||||
|
|
||||||
// Set up a date formatting helper so we can do:
|
helpers.theme = theme;
|
||||||
// {{formatDate val 'YYYY-MM'}}
|
HANDLEBARS.registerHelper( helpers );
|
||||||
HANDLEBARS.registerHelper("formatDate", function(datetime, format) {
|
|
||||||
return moment ? moment( datetime ).format( format ) : datetime;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a Markdown-to-WordProcessingML helper so we can do:
|
|
||||||
// {{wmpl val [true|false]}}
|
|
||||||
HANDLEBARS.registerHelper("wpml", function( txt, inline ) {
|
|
||||||
if(!txt) return '';
|
|
||||||
inline = (inline && !inline.hash) || false;
|
|
||||||
txt = inline ?
|
|
||||||
MD(txt.trim()).replace(/^\s*<p>|<\/p>\s*$/gi, '') :
|
|
||||||
MD(txt.trim());
|
|
||||||
txt = H2W( txt.trim() );
|
|
||||||
return txt;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a last-word helper so we can do:
|
|
||||||
// {{lastWord val [true|false]}}
|
|
||||||
HANDLEBARS.registerHelper("link", function( text, url ) {
|
|
||||||
return url && url.trim() ?
|
|
||||||
('<a href="' + url + '">' + text + '</a>') : text;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a last-word helper so we can do:
|
|
||||||
// {{lastWord val [true|false]}}
|
|
||||||
HANDLEBARS.registerHelper("lastWord", function( txt ) {
|
|
||||||
return txt && txt.trim() ? _.last( txt.split(' ') ) : '';
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a skill colorizing helper:
|
|
||||||
// {{skillColor val}}
|
|
||||||
HANDLEBARS.registerHelper("skillColor", function( lvl ) {
|
|
||||||
switch(lvl) {
|
|
||||||
case 'beginner': return '#5CB85C';
|
|
||||||
case 'intermediate': return '#F1C40F';
|
|
||||||
case 'advanced': return '#428BCA';
|
|
||||||
case 'master': return '#C00000';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a skill colorizing helper:
|
|
||||||
// {{skillColor val}}
|
|
||||||
HANDLEBARS.registerHelper("skillHeight", function( lvl ) {
|
|
||||||
switch(lvl) {
|
|
||||||
case 'beginner': return '30';
|
|
||||||
case 'intermediate': return '16';
|
|
||||||
case 'advanced': return '8';
|
|
||||||
case 'master': return '0';
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a Markdown-to-WordProcessingML helper so we can do:
|
|
||||||
// {{initialWords val [true|false]}}
|
|
||||||
HANDLEBARS.registerHelper("initialWords", function( txt ) {
|
|
||||||
return txt && txt.trim() ? _.initial( txt.split(' ') ).join(' ') : '';
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a URL-trimming helper to drop the protocol so we can do:
|
|
||||||
// {{trimURL url}}
|
|
||||||
HANDLEBARS.registerHelper("trimURL", function( url ) {
|
|
||||||
return url && url.trim() ? url.trim().replace(/^https?:\/\//i, '') : '';
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a URL-trimming helper to drop the protocol so we can do:
|
|
||||||
// {{trimURL url}}
|
|
||||||
HANDLEBARS.registerHelper("toLower", function( txt ) {
|
|
||||||
return txt && txt.trim() ? txt.toLowerCase() : '';
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a Markdown-to-WordProcessingML helper so we can do:
|
|
||||||
// {{either A B}}
|
|
||||||
HANDLEBARS.registerHelper("either", function( lhs, rhs, options ) {
|
|
||||||
if (lhs || rhs) return options.fn(this);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set up a generic conditional helper so we can do:
|
|
||||||
// {{compare val otherVal operator="<"}}
|
|
||||||
// http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates/
|
|
||||||
HANDLEBARS.registerHelper('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);
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -47,7 +47,6 @@ function main() {
|
|||||||
opts = getOpts( a );
|
opts = getOpts( a );
|
||||||
logMsg( title );
|
logMsg( title );
|
||||||
|
|
||||||
|
|
||||||
// Get the action to be performed
|
// Get the action to be performed
|
||||||
var params = a._.map( function(p){ return p.toLowerCase().trim(); });
|
var params = a._.map( function(p){ return p.toLowerCase().trim(); });
|
||||||
var verb = params[0];
|
var verb = params[0];
|
||||||
@ -56,7 +55,7 @@ function main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get source and dest params
|
// Find the TO keyword, if any
|
||||||
var splitAt = _.indexOf( params, 'to' );
|
var splitAt = _.indexOf( params, 'to' );
|
||||||
if( splitAt === a._.length - 1 ) {
|
if( splitAt === a._.length - 1 ) {
|
||||||
// 'TO' cannot be the last argument
|
// 'TO' cannot be the last argument
|
||||||
@ -66,8 +65,10 @@ function main() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Massage inputs and outputs
|
||||||
var src = a._.slice(1, splitAt === -1 ? undefined : splitAt );
|
var src = a._.slice(1, splitAt === -1 ? undefined : splitAt );
|
||||||
var dst = splitAt === -1 ? [] : a._.slice( splitAt + 1 );
|
var dst = splitAt === -1 ? [] : a._.slice( splitAt + 1 );
|
||||||
|
( splitAt === -1 ) && dst.push( src.pop() ); // Allow omitting TO keyword
|
||||||
var parms = [ src, dst, opts, logMsg ];
|
var parms = [ src, dst, opts, logMsg ];
|
||||||
|
|
||||||
// Invoke the action
|
// Invoke the action
|
||||||
|
@ -17,3 +17,7 @@ String.isNullOrWhitespace = function( input ) {
|
|||||||
String.prototype.endsWith = function(suffix) {
|
String.prototype.endsWith = function(suffix) {
|
||||||
return this.indexOf(suffix, this.length - suffix.length) !== -1;
|
return this.indexOf(suffix, this.length - suffix.length) !== -1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
String.is = function( val ) {
|
||||||
|
return typeof val === 'string' || val instanceof String;
|
||||||
|
};
|
||||||
|
Reference in New Issue
Block a user