1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-05 09:56:22 +00:00
This commit is contained in:
hacksalot 2016-02-09 10:37:33 -05:00
parent d894f62607
commit 7c0a9bcc02

View File

@ -17,11 +17,15 @@ LO = require 'lodash'
PATH = require 'path' PATH = require 'path'
printf = require 'printf' printf = require 'printf'
_ = require 'underscore' _ = require 'underscore'
unused = require '../utils/string'; unused = require '../utils/string'
###* Generic template helper function definitions. ### ###* Generic template helper function definitions. ###
GenericHelpers = module.exports = GenericHelpers = module.exports =
###* ###*
Convert the input date to a specified format through Moment.js. Convert the input date to a specified format through Moment.js.
If date is invalid, will return the time provided by the user, If date is invalid, will return the time provided by the user,
@ -35,6 +39,8 @@ GenericHelpers = module.exports =
datetime || (typeof fallback == 'string' ? fallback : (fallback == true ? 'Present' : null)); datetime || (typeof fallback == 'string' ? fallback : (fallback == true ? 'Present' : null));
###* ###*
Given a resume sub-object with a start/end date, format a representation of Given a resume sub-object with a start/end date, format a representation of
the date range. the date range.
@ -44,12 +50,16 @@ GenericHelpers = module.exports =
return '' if !obj return '' if !obj
_fromTo obj.start, obj.end, fmt, sep, fallback, options _fromTo obj.start, obj.end, fmt, sep, fallback, options
###* ###*
Format a from/to date range for display. Format a from/to date range for display.
@method toFrom @method toFrom
### ###
fromTo: () -> _fromTo.apply this, arguments fromTo: () -> _fromTo.apply this, arguments
###* ###*
Return a named color value as an RRGGBB string. Return a named color value as an RRGGBB string.
@method toFrom @method toFrom
@ -66,6 +76,8 @@ GenericHelpers = module.exports =
return colorDefault return colorDefault
ret ret
###* ###*
Return true if the section is present on the resume and has at least one Return true if the section is present on the resume and has at least one
element. element.
@ -84,6 +96,8 @@ GenericHelpers = module.exports =
ret = options.fn @ ret = options.fn @
ret ret
###* ###*
Emit the size of the specified named font. Emit the size of the specified named font.
@param key {String} A named style from the "fonts" section of the theme's @param key {String} A named style from the "fonts" section of the theme's
@ -133,6 +147,7 @@ GenericHelpers = module.exports =
ret ret
###* ###*
Emit the font face (such as 'Helvetica' or 'Calibri') associated with the Emit the font face (such as 'Helvetica' or 'Calibri') associated with the
provided key. provided key.
@ -185,6 +200,8 @@ GenericHelpers = module.exports =
return ret; return ret;
###* ###*
Emit a comma-delimited list of font names suitable associated with the Emit a comma-delimited list of font names suitable associated with the
provided key. provided key.
@ -240,6 +257,8 @@ GenericHelpers = module.exports =
return ret; return ret;
###* ###*
Capitalize the first letter of the word. Capitalize the first letter of the word.
@method section @method section
@ -248,6 +267,8 @@ GenericHelpers = module.exports =
val = (val && val.trim()) || '' val = (val && val.trim()) || ''
return if val then (val.charAt(0).toUpperCase() + val.slice(1)) else val return if val then (val.charAt(0).toUpperCase() + val.slice(1)) else val
###* ###*
Return true if the context has the property or subpropery. Return true if the context has the property or subpropery.
@method has @method has
@ -258,6 +279,8 @@ GenericHelpers = module.exports =
return options.fn this return options.fn this
return return
###* ###*
Generic template helper function to display a user-overridable section Generic template helper function to display a user-overridable section
title for a FRESH resume theme. Use this in lieue of hard-coding section title for a FRESH resume theme. Use this in lieue of hard-coding section
@ -291,6 +314,8 @@ GenericHelpers = module.exports =
this.opts.stitles[ sname.toLowerCase().trim() ] ) || this.opts.stitles[ sname.toLowerCase().trim() ] ) ||
stitle; stitle;
###* ###*
Convert inline Markdown to inline WordProcessingML. Convert inline Markdown to inline WordProcessingML.
@method wpml @method wpml
@ -304,6 +329,7 @@ GenericHelpers = module.exports =
return txt return txt
###* ###*
Emit a conditional link. Emit a conditional link.
@method link @method link
@ -311,6 +337,8 @@ GenericHelpers = module.exports =
link: ( text, url ) -> link: ( text, url ) ->
return if url && url.trim() then ('<a href="' + url + '">' + text + '</a>') else text return if url && url.trim() then ('<a href="' + url + '">' + text + '</a>') else text
###* ###*
Return the last word of the specified text. Return the last word of the specified text.
@method lastWord @method lastWord
@ -318,6 +346,8 @@ GenericHelpers = module.exports =
lastWord: ( txt ) -> lastWord: ( txt ) ->
return if txt && txt.trim() then _.last( txt.split(' ') ) else '' return if txt && txt.trim() then _.last( txt.split(' ') ) else ''
###* ###*
Convert a skill level to an RGB color triplet. TODO: refactor Convert a skill level to an RGB color triplet. TODO: refactor
@method skillColor @method skillColor
@ -333,6 +363,8 @@ GenericHelpers = module.exports =
[ '#FFFFFF', '#5CB85C', '#F1C40F', '#428BCA', '#C00000' ] [ '#FFFFFF', '#5CB85C', '#F1C40F', '#428BCA', '#C00000' ]
return skillColors[idx] return skillColors[idx]
###* ###*
Return an appropriate height. TODO: refactor Return an appropriate height. TODO: refactor
@method lastWord @method lastWord
@ -341,6 +373,8 @@ GenericHelpers = module.exports =
idx = skillLevelToIndex lvl idx = skillLevelToIndex lvl
['38.25', '30', '16', '8', '0'][idx] ['38.25', '30', '16', '8', '0'][idx]
###* ###*
Return all but the last word of the input text. Return all but the last word of the input text.
@method initialWords @method initialWords
@ -348,6 +382,8 @@ GenericHelpers = module.exports =
initialWords: ( txt ) -> initialWords: ( txt ) ->
if txt && txt.trim() then _.initial( txt.split(' ') ).join(' ') else '' if txt && txt.trim() then _.initial( txt.split(' ') ).join(' ') else ''
###* ###*
Trim the protocol (http or https) from a URL/ Trim the protocol (http or https) from a URL/
@method trimURL @method trimURL
@ -355,6 +391,8 @@ GenericHelpers = module.exports =
trimURL: ( url ) -> trimURL: ( url ) ->
if url && url.trim() then url.trim().replace(/^https?:\/\//i, '') else '' if url && url.trim() then url.trim().replace(/^https?:\/\//i, '') else ''
###* ###*
Convert text to lowercase. Convert text to lowercase.
@method toLower @method toLower
@ -362,6 +400,8 @@ GenericHelpers = module.exports =
toLower: ( txt ) -> toLower: ( txt ) ->
if txt && txt.trim() then txt.toLowerCase() else '' if txt && txt.trim() then txt.toLowerCase() else ''
###* ###*
Convert text to lowercase. Convert text to lowercase.
@method toLower @method toLower
@ -369,6 +409,8 @@ GenericHelpers = module.exports =
toUpper: ( txt ) -> toUpper: ( txt ) ->
if txt && txt.trim() then txt.toUpperCase() else '' if txt && txt.trim() then txt.toUpperCase() else ''
###* ###*
Return true if either value is truthy. Return true if either value is truthy.
@method either @method either
@ -377,6 +419,8 @@ GenericHelpers = module.exports =
if lhs || rhs if lhs || rhs
return options.fn this return options.fn this
###* ###*
Conditional stylesheet link. Creates a link to the specified stylesheet with Conditional stylesheet link. Creates a link to the specified stylesheet with
<link> or embeds the styles inline with <style></style>, depending on the <link> or embeds the styles inline with <style></style>, depending on the
@ -413,6 +457,8 @@ GenericHelpers = module.exports =
# it when Handlebars is the chosen engine, which is most of the time. # it when Handlebars is the chosen engine, which is most of the time.
ret ret
###* ###*
Perform a generic comparison. Perform a generic comparison.
See: 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
@ -445,6 +491,8 @@ relies on kludging the running verb into. opts.
_reportError = ( code, params ) -> _reportError = ( code, params ) ->
GenericHelpers.opts.errHandler.err( code, params ) GenericHelpers.opts.errHandler.err( code, params )
###* ###*
Format a from/to date range for display. Format a from/to date range for display.
### ###
@ -487,6 +535,8 @@ _fromTo = ( dateA, dateB, fmt, sep, fallback ) ->
return dateFrom || dateTo return dateFrom || dateTo
return '' return ''
skillLevelToIndex = ( lvl ) -> skillLevelToIndex = ( lvl ) ->
idx = 0 idx = 0
if String.is( lvl ) if String.is( lvl )
@ -507,6 +557,7 @@ skillLevelToIndex = ( lvl ) ->
idx idx
# Note [1] -------------------------------------------------------------------- # Note [1] --------------------------------------------------------------------
# Make sure it's precisely a string or array since some template engines jam # Make sure it's precisely a string or array since some template engines jam
# their options/context object into the last parameter and we are allowing the # their options/context object into the last parameter and we are allowing the