1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-07-07 18:20:05 +01:00
This commit is contained in:
hacksalot 2015-12-20 20:22:46 -05:00
parent cdbb264093
commit f80c333361

View File

@ -13,19 +13,23 @@ Generic template helper definitions for FluentCV.
, _ = require('underscore'); , _ = require('underscore');
/** /**
Register useful Handlebars helpers. Generic template helper function definitions.
@method registerHelpers @class GenericHelpers
*/ */
module.exports = { var GenericHelpers = module.exports = {
// Set up a date formatting helper so we can do: /**
// {{formatDate val 'YYYY-MM'}} Convert the input date to a specified format through Moment.js.
@method formatDate
*/
formatDate: function(datetime, format) { formatDate: function(datetime, format) {
return moment ? moment( datetime ).format( format ) : datetime; return moment ? moment( datetime ).format( format ) : datetime;
}, },
// Set up a Markdown-to-WordProcessingML helper so we can do: /**
// {{wmpl val [true|false]}} Convert inline Markdown to inline WordProcessingML.
@method wpml
*/
wpml: function( txt, inline ) { wpml: function( txt, inline ) {
if(!txt) return ''; if(!txt) return '';
inline = (inline && !inline.hash) || false; inline = (inline && !inline.hash) || false;
@ -36,24 +40,31 @@ Generic template helper definitions for FluentCV.
return txt; return txt;
}, },
// Set up a last-word helper so we can do: /**
// {{lastWord val [true|false]}} Emit a conditional link.
@method link
*/
link: function( text, url ) { link: function( text, url ) {
return url && url.trim() ? return url && url.trim() ?
('<a href="' + url + '">' + text + '</a>') : text; ('<a href="' + url + '">' + text + '</a>') : text;
}, },
// Set up a last-word helper so we can do: /**
// {{lastWord val [true|false]}} Return the last word of the specified text.
@method lastWord
*/
lastWord: function( txt ) { lastWord: function( txt ) {
return txt && txt.trim() ? _.last( txt.split(' ') ) : ''; return txt && txt.trim() ? _.last( txt.split(' ') ) : '';
}, },
// Set up a skill colorizing helper: /**
// {{skillColor val}} Convert a skill level to an RGB color triplet.
// Skill level can be expressed as a string ("beginner", "intermediate", @method skillColor
// etc.), as an integer (1,5,etc), as a string integer ("1", "5", etc.), @param lvl Input skill level. Skill level can be expressed as a string
// or as an RRGGBB color triplet ('#C00000', '#FFFFAA'). ("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 ) { skillColor: function( lvl ) {
var idx = skillLevelToIndex( lvl ); var idx = skillLevelToIndex( lvl );
var skillColors = (this.theme && this.theme.palette && var skillColors = (this.theme && this.theme.palette &&
@ -62,40 +73,52 @@ Generic template helper definitions for FluentCV.
return skillColors[idx]; return skillColors[idx];
}, },
// Set up a skill colorizing helper: /**
// {{skillColor val}} Return an appropriate height.
@method lastWord
*/
skillHeight: function( lvl ) { skillHeight: function( lvl ) {
var idx = skillLevelToIndex( lvl ); var idx = skillLevelToIndex( lvl );
return ['38.25', '30', '16', '8', '0'][idx]; return ['38.25', '30', '16', '8', '0'][idx];
}, },
// Set up a Markdown-to-WordProcessingML helper so we can do: /**
// {{initialWords val [true|false]}} Return all but the last word of the input text.
@method initialWords
*/
initialWords: function( txt ) { initialWords: function( txt ) {
return txt && txt.trim() ? _.initial( txt.split(' ') ).join(' ') : ''; return txt && txt.trim() ? _.initial( txt.split(' ') ).join(' ') : '';
}, },
// Set up a URL-trimming helper to drop the protocol so we can do: /**
// {{trimURL url}} Trim the protocol (http or https) from a URL/
@method trimURL
*/
trimURL: function( url ) { trimURL: function( url ) {
return url && url.trim() ? url.trim().replace(/^https?:\/\//i, '') : ''; 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}} Convert text to lowercase.
@method toLower
*/
toLower: function( txt ) { toLower: function( txt ) {
return txt && txt.trim() ? txt.toLowerCase() : ''; return txt && txt.trim() ? txt.toLowerCase() : '';
}, },
// Set up a Markdown-to-WordProcessingML helper so we can do: /**
// {{either A B}} Return true if either value is truthy.
@method either
*/
either: function( lhs, rhs, options ) { either: function( lhs, rhs, options ) {
if (lhs || rhs) return options.fn(this); if (lhs || rhs) return options.fn(this);
}, },
// Set up a generic conditional helper so we can do: /**
// {{compare val otherVal operator="<"}} Perform a generic comparison.
// http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates/ See: http://doginthehat.com.au/2012/02/comparison-block-helper-for-handlebars-templates
@method compare
*/
compare: function(lvalue, rvalue, options) { compare: function(lvalue, rvalue, options) {
if (arguments.length < 3) if (arguments.length < 3)
throw new Error("Handlerbars Helper 'compare' needs 2 parameters"); throw new Error("Handlerbars Helper 'compare' needs 2 parameters");