mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-05 09:56:22 +00:00
Improve font helpers.
Log a warning on incorrect use.
This commit is contained in:
parent
5a1ec033bb
commit
4fe74057f9
@ -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;
|
||||||
|
@ -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**."
|
||||||
|
@ -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
|
||||||
};
|
};
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -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
|
||||||
|
});
|
||||||
}
|
}
|
||||||
_reportError( HMSTATUS.invalidHelperUse, { helper: 'fontFace' } );
|
else if( !GenericHelpers.theme.fonts ) {
|
||||||
return '';
|
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.
|
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 = '';
|
||||||
var fontSpec = GenericHelpers.theme.fonts[ key ];
|
if( !_.contains( [3,4], arguments.length ) ) {
|
||||||
if( _.isArray( fontSpec ) ) {
|
_reportError( HMSTATUS.invalidHelperUse, {
|
||||||
fontSpec = fontSpec.map( function(ff) {
|
helper: 'fontList', error: HMSTATUS.invalidParamCount, expected: [2,3]
|
||||||
return "'" + ff + "'";
|
|
||||||
});
|
});
|
||||||
ret = fontSpec.join(', ');
|
|
||||||
}
|
}
|
||||||
else if( _.isString( fontSpec )) {
|
else if( !GenericHelpers.theme.fonts ) {
|
||||||
ret = fontSpec;
|
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;
|
return ret;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user