mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 16:30:11 +00:00
Scrub.
This commit is contained in:
parent
2ff912e687
commit
72de1bbd33
@ -6,6 +6,8 @@ Definition of the FRESHTheme class.
|
|||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var FS = require('fs')
|
var FS = require('fs')
|
||||||
, extend = require('../utils/extend')
|
, extend = require('../utils/extend')
|
||||||
, validator = require('is-my-json-valid')
|
, validator = require('is-my-json-valid')
|
||||||
@ -15,16 +17,21 @@ Definition of the FRESHTheme class.
|
|||||||
, pathExists = require('path-exists').sync
|
, pathExists = require('path-exists').sync
|
||||||
, EXTEND = require('../utils/extend')
|
, EXTEND = require('../utils/extend')
|
||||||
, moment = require('moment')
|
, moment = require('moment')
|
||||||
, RECURSIVE_READ_DIR = require('recursive-readdir-sync');
|
, READFILES = require('recursive-readdir-sync');
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The FRESHTheme class is a representation of a HackMyResume theme asset.
|
The FRESHTheme class is a representation of a FRESH theme
|
||||||
|
asset. See also: JRSTheme.
|
||||||
@class FRESHTheme
|
@class FRESHTheme
|
||||||
*/
|
*/
|
||||||
function FRESHTheme() {
|
function FRESHTheme() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Open and parse the specified theme.
|
Open and parse the specified theme.
|
||||||
*/
|
*/
|
||||||
@ -38,18 +45,7 @@ Definition of the FRESHTheme class.
|
|||||||
// Set up a formats hash for the theme
|
// Set up a formats hash for the theme
|
||||||
var formatsHash = { };
|
var formatsHash = { };
|
||||||
|
|
||||||
// See if the theme has a package.json. If so, load it.
|
// Load the theme
|
||||||
var packageJsonPath = PATH.join(themeFolder, 'package.json');
|
|
||||||
if( pathExists( packageJsonPath ) ) {
|
|
||||||
var themePack = require( themeFolder );
|
|
||||||
var themePkgJson = require( packageJsonPath );
|
|
||||||
this.name = themePkgJson.name;
|
|
||||||
this.render = (themePack && themePack.render) || undefined;
|
|
||||||
this.formats = { html: { title: 'html', outFormat: 'html', ext: 'html', path: null, data: null } };
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Otherwise, do a full theme load
|
|
||||||
var themeFile = PATH.join( themeFolder, pathInfo.basename + '.json' );
|
var themeFile = PATH.join( themeFolder, pathInfo.basename + '.json' );
|
||||||
var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) );
|
var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) );
|
||||||
var that = this;
|
var that = this;
|
||||||
@ -76,6 +72,8 @@ Definition of the FRESHTheme class.
|
|||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Determine if the theme supports the specified output format.
|
Determine if the theme supports the specified output format.
|
||||||
*/
|
*/
|
||||||
@ -83,6 +81,8 @@ Definition of the FRESHTheme class.
|
|||||||
return _.has( this.formats, fmt );
|
return _.has( this.formats, fmt );
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Determine if the theme supports the specified output format.
|
Determine if the theme supports the specified output format.
|
||||||
*/
|
*/
|
||||||
@ -90,6 +90,11 @@ Definition of the FRESHTheme class.
|
|||||||
return this.formats[ fmt ];
|
return this.formats[ fmt ];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Load the theme implicitly, by scanning the theme folder for
|
||||||
|
files. TODO: Refactor duplicated code with loadExplicit.
|
||||||
|
*/
|
||||||
function loadImplicit() {
|
function loadImplicit() {
|
||||||
|
|
||||||
// Set up a hash of formats supported by this theme.
|
// Set up a hash of formats supported by this theme.
|
||||||
@ -103,7 +108,7 @@ Definition of the FRESHTheme class.
|
|||||||
// Iterate over all files in the theme folder, producing an array, fmts,
|
// Iterate over all files in the theme folder, producing an array, fmts,
|
||||||
// containing info for each file. While we're doing that, also build up
|
// containing info for each file. While we're doing that, also build up
|
||||||
// the formatsHash object.
|
// the formatsHash object.
|
||||||
var fmts = RECURSIVE_READ_DIR( tplFolder ).map( function( absPath ) {
|
var fmts = READFILES(tplFolder).map( function(absPath) {
|
||||||
|
|
||||||
// If this file lives in a specific format folder within the theme,
|
// If this file lives in a specific format folder within the theme,
|
||||||
// such as "/latex" or "/html", then that format is the output format
|
// such as "/latex" or "/html", then that format is the output format
|
||||||
@ -131,7 +136,7 @@ Definition of the FRESHTheme class.
|
|||||||
// compact-[outputformat].[extension], for ex, compact-pdf.html.
|
// compact-[outputformat].[extension], for ex, compact-pdf.html.
|
||||||
if( !outFmt ) {
|
if( !outFmt ) {
|
||||||
var idx = pathInfo.name.lastIndexOf('-');
|
var idx = pathInfo.name.lastIndexOf('-');
|
||||||
outFmt = ( idx === -1 ) ? pathInfo.name : pathInfo.name.substr( idx + 1 );
|
outFmt = (idx === -1) ? pathInfo.name : pathInfo.name.substr(idx + 1);
|
||||||
isMajor = true;
|
isMajor = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -161,9 +166,13 @@ Definition of the FRESHTheme class.
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Now, get all the CSS files...
|
// Now, get all the CSS files...
|
||||||
(this.cssFiles = fmts.filter(function( fmt ){ return fmt && (fmt.ext === 'css'); }))
|
(this.cssFiles = fmts.filter(function( fmt ){
|
||||||
|
return fmt && (fmt.ext === 'css');
|
||||||
|
}))
|
||||||
|
|
||||||
|
// For each CSS file, get its corresponding HTML file
|
||||||
.forEach(function( cssf ) {
|
.forEach(function( cssf ) {
|
||||||
// For each CSS file, get its corresponding HTML file
|
|
||||||
var idx = _.findIndex(fmts, function( fmt ) {
|
var idx = _.findIndex(fmts, function( fmt ) {
|
||||||
return fmt && fmt.pre === cssf.pre && fmt.ext === 'html';
|
return fmt && fmt.pre === cssf.pre && fmt.ext === 'html';
|
||||||
});
|
});
|
||||||
@ -180,16 +189,19 @@ Definition of the FRESHTheme class.
|
|||||||
return formatsHash;
|
return formatsHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Load the theme explicitly, by following the 'formats' hash
|
||||||
|
in the theme's JSON settings file.
|
||||||
|
*/
|
||||||
function loadExplicit() {
|
function loadExplicit() {
|
||||||
|
|
||||||
var that = this;
|
// Housekeeping
|
||||||
// Set up a hash of formats supported by this theme.
|
|
||||||
var formatsHash = { };
|
var formatsHash = { };
|
||||||
|
|
||||||
// Establish the base theme folder
|
|
||||||
var tplFolder = PATH.join( this.folder, 'src' );
|
var tplFolder = PATH.join( this.folder, 'src' );
|
||||||
|
|
||||||
var act = null;
|
var act = null;
|
||||||
|
var that = this;
|
||||||
|
|
||||||
// Iterate over all files in the theme folder, producing an array, fmts,
|
// Iterate over all files in the theme folder, producing an array, fmts,
|
||||||
// containing info for each file. While we're doing that, also build up
|
// containing info for each file. While we're doing that, also build up
|
||||||
@ -200,13 +212,16 @@ Definition of the FRESHTheme class.
|
|||||||
// If this file is mentioned in the theme's JSON file under "transforms"
|
// If this file is mentioned in the theme's JSON file under "transforms"
|
||||||
var pathInfo = parsePath(absPath);
|
var pathInfo = parsePath(absPath);
|
||||||
var absPathSafe = absPath.trim().toLowerCase();
|
var absPathSafe = absPath.trim().toLowerCase();
|
||||||
var outFmt = _.find( Object.keys( that.formats ), function( fmtKey ) {
|
var outFmt = _.find(
|
||||||
var fmtVal = that.formats[ fmtKey ];
|
Object.keys( that.formats ),
|
||||||
return _.some( fmtVal.transform, function( fpath ) {
|
function( fmtKey ) {
|
||||||
var absPathB = PATH.join( that.folder, fpath ).trim().toLowerCase();
|
var fmtVal = that.formats[ fmtKey ];
|
||||||
return absPathB === absPathSafe;
|
return _.some( fmtVal.transform, function(fpath) {
|
||||||
|
var absPathB = PATH.join( that.folder, fpath )
|
||||||
|
.trim().toLowerCase();
|
||||||
|
return absPathB === absPathSafe;
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
if( outFmt ) {
|
if( outFmt ) {
|
||||||
act = 'transform';
|
act = 'transform';
|
||||||
}
|
}
|
||||||
@ -227,7 +242,7 @@ Definition of the FRESHTheme class.
|
|||||||
// compact-[outputformat].[extension], for ex, compact-pdf.html.
|
// compact-[outputformat].[extension], for ex, compact-pdf.html.
|
||||||
if( !outFmt ) {
|
if( !outFmt ) {
|
||||||
var idx = pathInfo.name.lastIndexOf('-');
|
var idx = pathInfo.name.lastIndexOf('-');
|
||||||
outFmt = ( idx === -1 ) ? pathInfo.name : pathInfo.name.substr( idx + 1 );
|
outFmt = (idx === -1) ? pathInfo.name : pathInfo.name.substr(idx + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We should have a valid output format now.
|
// We should have a valid output format now.
|
||||||
@ -257,7 +272,11 @@ Definition of the FRESHTheme class.
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Now, get all the CSS files...
|
// Now, get all the CSS files...
|
||||||
(this.cssFiles = fmts.filter(function( fmt ){ return fmt.ext === 'css'; }))
|
(this.cssFiles = fmts.filter(function( fmt ){
|
||||||
|
return fmt.ext === 'css';
|
||||||
|
}))
|
||||||
|
|
||||||
|
// For each CSS file, get its corresponding HTML file
|
||||||
.forEach(function( cssf ) {
|
.forEach(function( cssf ) {
|
||||||
// For each CSS file, get its corresponding HTML file
|
// For each CSS file, get its corresponding HTML file
|
||||||
var idx = _.findIndex(fmts, function( fmt ) {
|
var idx = _.findIndex(fmts, function( fmt ) {
|
||||||
@ -275,12 +294,22 @@ Definition of the FRESHTheme class.
|
|||||||
return formatsHash;
|
return formatsHash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
Return a more friendly name for certain formats.
|
||||||
|
TODO: Refactor
|
||||||
|
*/
|
||||||
function friendlyName( val ) {
|
function friendlyName( val ) {
|
||||||
val = val.trim().toLowerCase();
|
val = val.trim().toLowerCase();
|
||||||
var friendly = { yml: 'yaml', md: 'markdown', txt: 'text' };
|
var friendly = { yml: 'yaml', md: 'markdown', txt: 'text' };
|
||||||
return friendly[val] || val;
|
return friendly[val] || val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports = FRESHTheme;
|
module.exports = FRESHTheme;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -17,7 +17,7 @@ Definition of the JRSTheme class.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
The JRSTheme class is a representation of a JSON Resume
|
The JRSTheme class is a representation of a JSON Resume
|
||||||
theme asset.
|
theme asset. See also: FRESHTheme.
|
||||||
@class JRSTheme
|
@class JRSTheme
|
||||||
*/
|
*/
|
||||||
function JRSTheme() {
|
function JRSTheme() {
|
||||||
|
Loading…
Reference in New Issue
Block a user