1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-21 16:00: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:
msg = printf( M2C( this.msgs.invalidHelperUse.msg ), ex.helper );
if( ex.error ) {
msg += printf( '\n--> ' + M2C( this.msgs.invalidParamCount.msg ), ex.expected );
}
quit = false;
etype = 'warning';
break;

View File

@ -14,7 +14,7 @@ events:
- Merging **%s**
- " onto **%s**"
applyTheme:
msg: Applying **%s** theme (%s format%s)
msg: Applying **%s** theme (**%s** format%s)
afterBuild:
msg:
- "The **%s** theme says:"
@ -81,7 +81,7 @@ errors:
parseError:
msg: Invalid or corrupt JSON on line %s column %s.
invalidHelperUse:
msg: Warning: Invalid use of the **%s** theme helper.
msg: "**Warning**: Incorrect use of the **%s** theme helper."
fileSaveError:
msg: An error occurred while writing %s to disk: %s.
mixedMerge:
@ -92,3 +92,5 @@ errors:
msg: "An error occurred during template compilation."
themeLoad:
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,
invokeTemplate: 20,
compileTemplate: 21,
themeLoad: 22
themeLoad: 22,
invalidParamCount: 23
};
}());

View File

@ -79,15 +79,29 @@ Generic template helper definitions for HackMyResume / FluentCV.
provided key.
@param key {String} A named style from the "fonts" section of the theme's
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 ) {
if( key && key.trim() && GenericHelpers.theme.fonts ) {
var fontSpec = GenericHelpers.theme.fonts[ key ];
if( fontSpec )
return String.is( fontSpec ) ? fontSpec : fontSpec[0];
fontFace: function( key, defFont ) {
var ret = '';
if( arguments.length !== 3 ) { // key, defFont, and the HandleBars options
_reportError( HMSTATUS.invalidHelperUse, {
helper: 'fontFace', error: HMSTATUS.invalidParamCount, expected: 2
});
}
_reportError( HMSTATUS.invalidHelperUse, { helper: 'fontFace' } );
return '';
else if( !GenericHelpers.theme.fonts ) {
ret = defFont;
}
else {
var fontSpec = GenericHelpers.theme.fonts[ key ];
if( !fontSpec )
_reportError( HMSTATUS.invalidHelperUse, { helper: 'fontFace' } );
else
ret = String.is( fontSpec ) ? fontSpec : fontSpec[0];
}
return ret;
},
/**
@ -95,19 +109,35 @@ Generic template helper definitions for HackMyResume / FluentCV.
provided key.
@param key {String} A named style from the "fonts" section of the theme's
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 fontSpec = GenericHelpers.theme.fonts[ key ];
if( _.isArray( fontSpec ) ) {
fontSpec = fontSpec.map( function(ff) {
return "'" + ff + "'";
if( !_.contains( [3,4], arguments.length ) ) {
_reportError( HMSTATUS.invalidHelperUse, {
helper: 'fontList', error: HMSTATUS.invalidParamCount, expected: [2,3]
});
ret = fontSpec.join(', ');
}
else if( _.isString( fontSpec )) {
ret = fontSpec;
else if( !GenericHelpers.theme.fonts ) {
ret = defFontList;
}
else {
var fontSpec = GenericHelpers.theme.fonts[ key ];
if( !fontSpec ) {
_reportError( HMSTATUS.invalidHelperUse, { helper: 'fontFace' } );
}
else if( _.isArray( fontSpec ) ) {
fontSpec = fontSpec.map( function(ff) {
return "'" + ff + "'";
});
ret = fontSpec.join( sep === undefined ? ', ' : (sep || '') );
}
else if( _.isString( fontSpec )) {
ret = fontSpec;
}
}
return ret;
},