From c08c5f0fa3ff13adbd9abf7bf3c9933f07f0b976 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Wed, 7 Feb 2018 05:55:27 -0500 Subject: [PATCH] feat: introduce two skill-related helpers --- dist/helpers/block-helpers.js | 10 ++++++++++ dist/helpers/generic-helpers.js | 19 +++++++++++++++---- src/helpers/block-helpers.coffee | 10 +++++++++- src/helpers/generic-helpers.coffee | 14 ++++++++++---- 4 files changed, 44 insertions(+), 9 deletions(-) diff --git a/dist/helpers/block-helpers.js b/dist/helpers/block-helpers.js index f06a063..adae083 100644 --- a/dist/helpers/block-helpers.js +++ b/dist/helpers/block-helpers.js @@ -43,6 +43,16 @@ Block helper definitions for HackMyResume / FluentCV. } return ret; }, + ifHasSkill: function(rez, skill, options) { + var ret, skUp; + skUp = skill.toUpperCase(); + ret = _.some(rez.skills.list, function(sk) { + return (skUp.toUpperCase() === sk.name.toUpperCase()) && sk.years; + }, this); + if (ret) { + return options.fn(this); + } + }, /** Emit the enclosed content if the resume has the named diff --git a/dist/helpers/generic-helpers.js b/dist/helpers/generic-helpers.js index a9da25e..5fd4944 100644 --- a/dist/helpers/generic-helpers.js +++ b/dist/helpers/generic-helpers.js @@ -6,7 +6,7 @@ Generic template helper definitions for HackMyResume / FluentCV. */ (function() { - var FS, FluentDate, GenericHelpers, H2W, HMSTATUS, LO, MD, PATH, XML, _, _fromTo, _reportError, moment, printf, skillLevelToIndex, unused; + var FS, FluentDate, GenericHelpers, H2W, HMSTATUS, LO, MD, PATH, XML, _, _fromTo, _reportError, _skillLevelToIndex, moment, printf, unused; MD = require('marked'); @@ -391,7 +391,7 @@ Generic template helper definitions for HackMyResume / FluentCV. */ skillColor: function(lvl) { var idx, skillColors; - idx = skillLevelToIndex(lvl); + idx = _skillLevelToIndex(lvl); skillColors = (this.theme && this.theme.palette && this.theme.palette.skillLevels) || ['#FFFFFF', '#5CB85C', '#F1C40F', '#428BCA', '#C00000']; return skillColors[idx]; }, @@ -402,7 +402,7 @@ Generic template helper definitions for HackMyResume / FluentCV. */ skillHeight: function(lvl) { var idx; - idx = skillLevelToIndex(lvl); + idx = _skillLevelToIndex(lvl); return ['38.25', '30', '16', '8', '0'][idx]; }, @@ -541,6 +541,17 @@ Generic template helper definitions for HackMyResume / FluentCV. ret = PAD(stringOrArray, stringOrArray.length + Math.abs(padAmount), null, padAmount < 0 ? PAD.LEFT : PAD.RIGHT); } return ret; + }, + skillYears: function(skill, rez) { + var sk; + sk = _.find(rez.skills.list, function(sk) { + return sk.name.toUpperCase() === skill.toUpperCase(); + }); + if (sk) { + return sk.years; + } else { + return '?'; + } } }; @@ -599,7 +610,7 @@ Generic template helper definitions for HackMyResume / FluentCV. return ''; }; - skillLevelToIndex = function(lvl) { + _skillLevelToIndex = function(lvl) { var idx, intVal; idx = 0; if (String.is(lvl)) { diff --git a/src/helpers/block-helpers.coffee b/src/helpers/block-helpers.coffee index e3d3045..d01fcb6 100644 --- a/src/helpers/block-helpers.coffee +++ b/src/helpers/block-helpers.coffee @@ -38,6 +38,14 @@ BlockHelpers = module.exports = + ifHasSkill: ( rez, skill, options ) -> + skUp = skill.toUpperCase() + ret = _.some rez.skills.list, (sk) -> + (skUp.toUpperCase() == sk.name.toUpperCase()) and sk.years + , @ + options.fn @ if ret + + ###* Emit the enclosed content if the resume has the named property or subproperty. @@ -55,4 +63,4 @@ BlockHelpers = module.exports = Return true if either value is truthy. @method either ### - either: ( lhs, rhs, options ) -> options.fn @ if lhs || rhs + either: ( lhs, rhs, options ) -> options.fn @ if lhs || rhs diff --git a/src/helpers/generic-helpers.coffee b/src/helpers/generic-helpers.coffee index dddef4d..79724fe 100644 --- a/src/helpers/generic-helpers.coffee +++ b/src/helpers/generic-helpers.coffee @@ -329,6 +329,7 @@ GenericHelpers = module.exports = # If not provided by the user, stitle should default to sname. ps. # Handlebars silently passes in the options object to the last param, # where in Underscore stitle will be null/undefined, so we check both. + # TODO: not actually sure that's true, given that we _.wrap these functions stitle = (stitle && String.is(stitle) && stitle) || sname # If there's a section title override, use it. @@ -342,7 +343,7 @@ GenericHelpers = module.exports = wpml: ( txt, inline ) -> return '' if !txt inline = (inline && !inline.hash) || false - txt = XML(txt.trim()) + txt = XML txt.trim() txt = if inline then MD(txt).replace(/^\s*

|<\/p>\s*$/gi, '') else MD(txt) txt = H2W( txt ) return txt @@ -376,7 +377,7 @@ GenericHelpers = module.exports = '#FFFFAA'). ### skillColor: ( lvl ) -> - idx = skillLevelToIndex lvl + idx = _skillLevelToIndex lvl skillColors = (this.theme && this.theme.palette && this.theme.palette.skillLevels) || [ '#FFFFFF', '#5CB85C', '#F1C40F', '#428BCA', '#C00000' ] @@ -389,7 +390,7 @@ GenericHelpers = module.exports = @method lastWord ### skillHeight: ( lvl ) -> - idx = skillLevelToIndex lvl + idx = _skillLevelToIndex lvl ['38.25', '30', '16', '8', '0'][idx] @@ -505,6 +506,11 @@ GenericHelpers = module.exports = ret + skillYears: ( skill, rez ) -> + sk = _.find rez.skills.list, (sk) -> sk.name.toUpperCase() == skill.toUpperCase() + if sk then sk.years else '?' + + ###* Report an error to the outside world without throwing an exception. Currently @@ -562,7 +568,7 @@ _fromTo = ( dateA, dateB, fmt, sep, fallback ) -> -skillLevelToIndex = ( lvl ) -> +_skillLevelToIndex = ( lvl ) -> idx = 0 if String.is( lvl ) lvl = lvl.trim().toLowerCase()