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

Introduce FRESH theme/format inheritance.

Support "inherits" property in theme.json (FRESH themes only).
This commit is contained in:
hacksalot 2016-01-05 06:34:56 -05:00
parent 3f40441b0a
commit d205e882f6

View File

@ -53,14 +53,26 @@ Definition of the FRESHTheme class.
// Move properties from the theme JSON file to the theme object // Move properties from the theme JSON file to the theme object
EXTEND( true, this, themeInfo ); EXTEND( true, this, themeInfo );
// Check for an "inherits" entry in the theme JSON.
if( this.inherits ) {
var cached = { };
_.each( this.inherits, function(th, key) {
var themesFolder = require.resolve('fresh-themes');
var d = parsePath( themeFolder ).dirname;
var themePath = PATH.join(d, th);
cached[ th ] = cached[th] || new FRESHTheme().open( themePath );
formatsHash[ key ] = cached[ th ].getFormat( key );
});
}
// Check for an explicit "formats" entry in the theme JSON. If it has one, // Check for an explicit "formats" entry in the theme JSON. If it has one,
// then this theme declares its files explicitly. // then this theme declares its files explicitly.
if( !!this.formats ) { if( !!this.formats ) {
formatsHash = loadExplicit.call( this ); formatsHash = loadExplicit.call( this, formatsHash );
this.explicit = true; this.explicit = true;
} }
else { else {
formatsHash = loadImplicit.call( this ); formatsHash = loadImplicit.call( this, formatsHash );
} }
// Cache // Cache
@ -95,10 +107,9 @@ Definition of the FRESHTheme class.
Load the theme implicitly, by scanning the theme folder for Load the theme implicitly, by scanning the theme folder for
files. TODO: Refactor duplicated code with loadExplicit. files. TODO: Refactor duplicated code with loadExplicit.
*/ */
function loadImplicit() { function loadImplicit(formatsHash) {
// Set up a hash of formats supported by this theme. // Set up a hash of formats supported by this theme.
var formatsHash = { };
var that = this; var that = this;
var major = false; var major = false;
@ -195,10 +206,9 @@ Definition of the FRESHTheme class.
Load the theme explicitly, by following the 'formats' hash Load the theme explicitly, by following the 'formats' hash
in the theme's JSON settings file. in the theme's JSON settings file.
*/ */
function loadExplicit() { function loadExplicit(formatsHash) {
// Housekeeping // Housekeeping
var formatsHash = { };
var tplFolder = PATH.join( this.folder, 'src' ); var tplFolder = PATH.join( this.folder, 'src' );
var act = null; var act = null;
var that = this; var that = this;