1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 01:56:21 +00:00

feat: introduce stringOrObject & linkMD helpers

This commit is contained in:
hacksalot 2018-02-07 23:35:05 -05:00
parent c08c5f0fa3
commit 8648befcdd
No known key found for this signature in database
GPG Key ID: 2F343EC247CA4B06
2 changed files with 59 additions and 0 deletions

View File

@ -369,6 +369,18 @@ Generic template helper definitions for HackMyResume / FluentCV.
} }
}, },
/**
Emit a conditional Markdown link.
@method link
*/
linkMD: function(text, url) {
if (url && url.trim()) {
return '[' + text + '](' + url + ')';
} else {
return text;
}
},
/** /**
Return the last word of the specified text. Return the last word of the specified text.
@method lastWord @method lastWord
@ -527,6 +539,10 @@ Generic template helper definitions for HackMyResume / FluentCV.
return options.inverse(this); return options.inverse(this);
} }
}, },
/**
Emit padded text.
*/
pad: function(stringOrArray, padAmount, unused) { pad: function(stringOrArray, padAmount, unused) {
var PAD, ret; var PAD, ret;
stringOrArray = stringOrArray || ''; stringOrArray = stringOrArray || '';
@ -542,6 +558,11 @@ Generic template helper definitions for HackMyResume / FluentCV.
} }
return ret; return ret;
}, },
/**
Given the name of a skill ("JavaScript" or "HVAC repair"), return the number
of years assigned to that skill in the resume.skills.list collection.
*/
skillYears: function(skill, rez) { skillYears: function(skill, rez) {
var sk; var sk;
sk = _.find(rez.skills.list, function(sk) { sk = _.find(rez.skills.list, function(sk) {
@ -552,6 +573,18 @@ Generic template helper definitions for HackMyResume / FluentCV.
} else { } else {
return '?'; return '?';
} }
},
/**
Given an object that may be a string or an object, return it as-is if it's a
string, otherwise return the value at obj[objPath].
*/
stringOrObject: function(obj, objPath, rez) {
if (_.isString(obj)) {
return obj;
} else {
return LO.get(obj, objPath);
}
} }
}; };

View File

@ -359,6 +359,15 @@ GenericHelpers = module.exports =
###*
Emit a conditional Markdown link.
@method link
###
linkMD: ( text, url ) ->
return if url && url.trim() then ('[' + text + '](' + url + ')') else text
###* ###*
Return the last word of the specified text. Return the last word of the specified text.
@method lastWord @method lastWord
@ -492,6 +501,9 @@ GenericHelpers = module.exports =
###*
Emit padded text.
###
pad: (stringOrArray, padAmount, unused ) -> pad: (stringOrArray, padAmount, unused ) ->
stringOrArray = stringOrArray || '' stringOrArray = stringOrArray || ''
padAmount = padAmount || 0 padAmount = padAmount || 0
@ -506,12 +518,26 @@ GenericHelpers = module.exports =
ret ret
###*
Given the name of a skill ("JavaScript" or "HVAC repair"), return the number
of years assigned to that skill in the resume.skills.list collection.
###
skillYears: ( skill, rez ) -> skillYears: ( skill, rez ) ->
sk = _.find rez.skills.list, (sk) -> sk.name.toUpperCase() == skill.toUpperCase() sk = _.find rez.skills.list, (sk) -> sk.name.toUpperCase() == skill.toUpperCase()
if sk then sk.years else '?' if sk then sk.years else '?'
###*
Given an object that may be a string or an object, return it as-is if it's a
string, otherwise return the value at obj[objPath].
###
stringOrObject: ( obj, objPath, rez ) ->
if _.isString obj then obj else LO.get obj, objPath
###* ###*
Report an error to the outside world without throwing an exception. Currently Report an error to the outside world without throwing an exception. Currently
relies on kludging the running verb into. opts. relies on kludging the running verb into. opts.