From 1256095e2508f2cf63f138714574fe63c679e4c8 Mon Sep 17 00:00:00 2001 From: hacksalot Date: Sat, 23 Jan 2016 03:58:11 -0500 Subject: [PATCH] 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". --- src/helpers/generic-helpers.js | 86 ++++++++++++++-------------------- 1 file changed, 34 insertions(+), 52 deletions(-) diff --git a/src/helpers/generic-helpers.js b/src/helpers/generic-helpers.js index 4bab729..6c262eb 100644 --- a/src/helpers/generic-helpers.js +++ b/src/helpers/generic-helpers.js @@ -85,50 +85,38 @@ Generic template helper definitions for HackMyResume / FluentCV. fontFace: function( key, defFont ) { var ret = '' - , hasDef = defFont && String.is( defFont ) - , fontSpec; + , hasDef = defFont && String.is( defFont ); // Key must be specified if( !( key && key.trim()) ) { _reportError( HMSTATUS.invalidHelperUse, { helper: 'fontFace', error: HMSTATUS.missingParam, expected: 'key' }); - } - - // 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'}); - } + return ret; } // If the theme has a "fonts" section, lookup the font face. - else if (fontSpec = GenericHelpers.theme.fonts[ key ]) { // jshint ignore:line - - ret = String.is( fontSpec ) ? fontSpec : // [1] - (_.isArray( fontSpec ) && fontSpec[0]); - - if( !(ret && ret.trim()) ) { - ret = defFont; // [2] - if( !hasDef ) { - _reportError( HMSTATUS.invalidHelperUse, { - helper: 'fontFace', error: HMSTATUS.missingParam, - expected: 'defFont'}); - } + else if( GenericHelpers.theme.fonts ) { + var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key ); + if( !fontSpec ) { + // Check for an "all" format + if( GenericHelpers.theme.fonts.all ) + fontSpec = GenericHelpers.theme.fonts.all[ key ]; + } + if( fontSpec ) { + ret = String.is( fontSpec ) ? fontSpec : // [1] + (_.isArray( fontSpec ) && fontSpec[0]); } } - // The key wasn't found in the "fonts" section. Default to defFont. - else { - if( !hasDef ) { + // We weren't able to lookup the specified key. Default to defFont. + if( !(ret && ret.trim()) ) { + ret = defFont; + if( !defFont ) { _reportError( HMSTATUS.invalidHelperUse, { helper: 'fontFace', error: HMSTATUS.missingParam, expected: 'defFont'}); } - ret = defFont; } return ret; @@ -148,8 +136,7 @@ Generic template helper definitions for HackMyResume / FluentCV. fontList: function( key, defFontList, sep ) { var ret = '' - , hasDef = defFontList && String.is( defFontList ) - , fontSpec; + , hasDef = defFontList && String.is( defFontList ); // Key must be specified 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. - else if( fontSpec = GenericHelpers.theme.fonts[ key ] ) { // jshint ignore:line - if( _.isArray( fontSpec ) ) { - fontSpec = fontSpec.map( function(ff) { - return "'" + ff + "'"; - }); - ret = fontSpec.join( sep === undefined ? ', ' : (sep || '') ); + else if( GenericHelpers.theme.fonts ) { + var fontSpec = LO.get( GenericHelpers.theme.fonts, this.format + '.' + key ); + if( !fontSpec ) { + if( GenericHelpers.theme.fonts.all ) + fontSpec = GenericHelpers.theme.fonts.all[ key ]; } - 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. - else { - if( !hasDef ) { + if( !(ret && ret.trim()) ) { + ret = defFontList; + if( !hasDef ) _reportError( HMSTATUS.invalidHelperUse, { helper: 'fontList', error: HMSTATUS.missingParam, expected: 'defFontList'}); - } - ret = defFontList; } return ret;