1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-11-24 17:30:10 +00:00

Support "fonts.all" in FRESH themes.

Add support for default font specs in FRESH theme.json files. The "all"
format matches any format that doesn't have a specific key in "fonts".
This commit is contained in:
hacksalot 2016-01-23 03:58:11 -05:00
parent f073c79b8d
commit 1256095e25

View File

@ -85,50 +85,38 @@ Generic template helper definitions for HackMyResume / FluentCV.
fontFace: function( key, defFont ) { fontFace: function( key, defFont ) {
var ret = '' var ret = ''
, hasDef = defFont && String.is( defFont ) , hasDef = defFont && String.is( defFont );
, fontSpec;
// Key must be specified // Key must be specified
if( !( key && key.trim()) ) { if( !( key && key.trim()) ) {
_reportError( HMSTATUS.invalidHelperUse, { _reportError( HMSTATUS.invalidHelperUse, {
helper: 'fontFace', error: HMSTATUS.missingParam, expected: 'key' helper: 'fontFace', error: HMSTATUS.missingParam, expected: 'key'
}); });
} return ret;
// If the theme doesn't have a "fonts" section, use defFont.
else if( !GenericHelpers.theme.fonts ) {
ret = defFont;
if( !hasDef ) {
_reportError( HMSTATUS.invalidHelperUse, {
helper: 'fontFace', error: HMSTATUS.missingParam,
expected: 'defFont'});
}
} }
// If the theme has a "fonts" section, lookup the font face. // If the theme has a "fonts" section, lookup the font face.
else if (fontSpec = GenericHelpers.theme.fonts[ key ]) { // jshint ignore:line else if( GenericHelpers.theme.fonts ) {
var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key );
ret = String.is( fontSpec ) ? fontSpec : // [1] if( !fontSpec ) {
(_.isArray( fontSpec ) && fontSpec[0]); // Check for an "all" format
if( GenericHelpers.theme.fonts.all )
if( !(ret && ret.trim()) ) { fontSpec = GenericHelpers.theme.fonts.all[ key ];
ret = defFont; // [2] }
if( !hasDef ) { if( fontSpec ) {
_reportError( HMSTATUS.invalidHelperUse, { ret = String.is( fontSpec ) ? fontSpec : // [1]
helper: 'fontFace', error: HMSTATUS.missingParam, (_.isArray( fontSpec ) && fontSpec[0]);
expected: 'defFont'});
}
} }
} }
// The key wasn't found in the "fonts" section. Default to defFont. // We weren't able to lookup the specified key. Default to defFont.
else { if( !(ret && ret.trim()) ) {
if( !hasDef ) { ret = defFont;
if( !defFont ) {
_reportError( HMSTATUS.invalidHelperUse, { _reportError( HMSTATUS.invalidHelperUse, {
helper: 'fontFace', error: HMSTATUS.missingParam, helper: 'fontFace', error: HMSTATUS.missingParam,
expected: 'defFont'}); expected: 'defFont'});
} }
ret = defFont;
} }
return ret; return ret;
@ -148,8 +136,7 @@ Generic template helper definitions for HackMyResume / FluentCV.
fontList: function( key, defFontList, sep ) { fontList: function( key, defFontList, sep ) {
var ret = '' var ret = ''
, hasDef = defFontList && String.is( defFontList ) , hasDef = defFontList && String.is( defFontList );
, fontSpec;
// Key must be specified // Key must be specified
if( !( key && key.trim()) ) { if( !( key && key.trim()) ) {
@ -158,37 +145,32 @@ Generic template helper definitions for HackMyResume / FluentCV.
}); });
} }
// If the theme doesn't have a "fonts" section, use defFont
else if( !GenericHelpers.theme.fonts ) {
ret = defFontList;
if( !hasDef ) {
_reportError( HMSTATUS.invalidHelperUse, {
helper: 'fontList', error: HMSTATUS.missingParam,
expected: 'defFontList'});
}
}
// If the theme has a "fonts" section, lookup the font list. // If the theme has a "fonts" section, lookup the font list.
else if( fontSpec = GenericHelpers.theme.fonts[ key ] ) { // jshint ignore:line else if( GenericHelpers.theme.fonts ) {
if( _.isArray( fontSpec ) ) { var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key );
fontSpec = fontSpec.map( function(ff) { if( !fontSpec ) {
return "'" + ff + "'"; if( GenericHelpers.theme.fonts.all )
}); fontSpec = GenericHelpers.theme.fonts.all[ key ];
ret = fontSpec.join( sep === undefined ? ', ' : (sep || '') );
} }
else if( _.isString( fontSpec )) {
ret = fontSpec; if( fontSpec ) {
if( _.isArray( fontSpec ) ) {
fontSpec = fontSpec.map( function(ff) {
return "'" + ff + "'";
});
ret = fontSpec.join( sep === undefined ? ', ' : (sep || '') );
}
else if( _.isString( fontSpec )) { ret = fontSpec; }
} }
} }
// The key wasn't found in the "fonts" section. Default to defFont. // The key wasn't found in the "fonts" section. Default to defFont.
else { if( !(ret && ret.trim()) ) {
if( !hasDef ) { ret = defFontList;
if( !hasDef )
_reportError( HMSTATUS.invalidHelperUse, { _reportError( HMSTATUS.invalidHelperUse, {
helper: 'fontList', error: HMSTATUS.missingParam, helper: 'fontList', error: HMSTATUS.missingParam,
expected: 'defFontList'}); expected: 'defFontList'});
}
ret = defFontList;
} }
return ret; return ret;