1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-22 08:20:11 +00:00

Improve font helpers.

Log a warning on incorrect use.
This commit is contained in:
hacksalot 2016-01-22 08:33:01 -05:00
parent 5a1ec033bb
commit 4fe74057f9
4 changed files with 54 additions and 18 deletions

View File

@ -197,6 +197,9 @@ Error-handling routines for HackMyResume.
case HMSTATUS.invalidHelperUse: case HMSTATUS.invalidHelperUse:
msg = printf( M2C( this.msgs.invalidHelperUse.msg ), ex.helper ); msg = printf( M2C( this.msgs.invalidHelperUse.msg ), ex.helper );
if( ex.error ) {
msg += printf( '\n--> ' + M2C( this.msgs.invalidParamCount.msg ), ex.expected );
}
quit = false; quit = false;
etype = 'warning'; etype = 'warning';
break; break;

View File

@ -14,7 +14,7 @@ events:
- Merging **%s** - Merging **%s**
- " onto **%s**" - " onto **%s**"
applyTheme: applyTheme:
msg: Applying **%s** theme (%s format%s) msg: Applying **%s** theme (**%s** format%s)
afterBuild: afterBuild:
msg: msg:
- "The **%s** theme says:" - "The **%s** theme says:"
@ -81,7 +81,7 @@ errors:
parseError: parseError:
msg: Invalid or corrupt JSON on line %s column %s. msg: Invalid or corrupt JSON on line %s column %s.
invalidHelperUse: invalidHelperUse:
msg: Warning: Invalid use of the **%s** theme helper. msg: "**Warning**: Incorrect use of the **%s** theme helper."
fileSaveError: fileSaveError:
msg: An error occurred while writing %s to disk: %s. msg: An error occurred while writing %s to disk: %s.
mixedMerge: mixedMerge:
@ -92,3 +92,5 @@ errors:
msg: "An error occurred during template compilation." msg: "An error occurred during template compilation."
themeLoad: themeLoad:
msg: "Applying **%s** theme (? formats)" msg: "Applying **%s** theme (? formats)"
invalidParamCount:
msg: "Invalid number of parameters. Expected: **%s**."

View File

@ -29,7 +29,8 @@ Status codes for HackMyResume.
mixedMerge: 19, mixedMerge: 19,
invokeTemplate: 20, invokeTemplate: 20,
compileTemplate: 21, compileTemplate: 21,
themeLoad: 22 themeLoad: 22,
invalidParamCount: 23
}; };
}()); }());

View File

@ -79,15 +79,29 @@ Generic template helper definitions for HackMyResume / FluentCV.
provided key. provided key.
@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
theme.json file. For example: 'default' or 'heading1'. theme.json file. For example: 'default' or 'heading1'.
@param defFont {String} The font to use if the specified key isn't present.
Can be any valid font-face name such as 'Helvetica Neue' or 'Calibri'.
*/ */
fontFace: function( key ) { fontFace: function( key, defFont ) {
if( key && key.trim() && GenericHelpers.theme.fonts ) {
var fontSpec = GenericHelpers.theme.fonts[ key ]; var ret = '';
if( fontSpec ) if( arguments.length !== 3 ) { // key, defFont, and the HandleBars options
return String.is( fontSpec ) ? fontSpec : fontSpec[0]; _reportError( HMSTATUS.invalidHelperUse, {
helper: 'fontFace', error: HMSTATUS.invalidParamCount, expected: 2
});
} }
else if( !GenericHelpers.theme.fonts ) {
ret = defFont;
}
else {
var fontSpec = GenericHelpers.theme.fonts[ key ];
if( !fontSpec )
_reportError( HMSTATUS.invalidHelperUse, { helper: 'fontFace' } ); _reportError( HMSTATUS.invalidHelperUse, { helper: 'fontFace' } );
return ''; else
ret = String.is( fontSpec ) ? fontSpec : fontSpec[0];
}
return ret;
}, },
/** /**
@ -95,19 +109,35 @@ Generic template helper definitions for HackMyResume / FluentCV.
provided key. provided key.
@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
theme.json file. For example: 'default' or 'heading1'. theme.json file. For example: 'default' or 'heading1'.
@param defFont {String} The font to use if the specified key isn't present.
Can be any valid font-face name such as 'Helvetica Neue' or 'Calibri'.
*/ */
fontList: function( key ) { fontList: function( key, defFontList, sep ) {
var ret = ''; var ret = '';
if( !_.contains( [3,4], arguments.length ) ) {
_reportError( HMSTATUS.invalidHelperUse, {
helper: 'fontList', error: HMSTATUS.invalidParamCount, expected: [2,3]
});
}
else if( !GenericHelpers.theme.fonts ) {
ret = defFontList;
}
else {
var fontSpec = GenericHelpers.theme.fonts[ key ]; var fontSpec = GenericHelpers.theme.fonts[ key ];
if( _.isArray( fontSpec ) ) { if( !fontSpec ) {
_reportError( HMSTATUS.invalidHelperUse, { helper: 'fontFace' } );
}
else if( _.isArray( fontSpec ) ) {
fontSpec = fontSpec.map( function(ff) { fontSpec = fontSpec.map( function(ff) {
return "'" + ff + "'"; return "'" + ff + "'";
}); });
ret = fontSpec.join(', '); ret = fontSpec.join( sep === undefined ? ', ' : (sep || '') );
} }
else if( _.isString( fontSpec )) { else if( _.isString( fontSpec )) {
ret = fontSpec; ret = fontSpec;
} }
}
return ret; return ret;
}, },