mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-25 01:40:10 +00:00
Add baseline support for multifile themes. #rough
This commit is contained in:
parent
cf25621679
commit
5f19f0a7df
@ -12,7 +12,7 @@ Abstract theme representation.
|
|||||||
, PATH = require('path')
|
, PATH = require('path')
|
||||||
, EXTEND = require('../utils/extend')
|
, EXTEND = require('../utils/extend')
|
||||||
, moment = require('moment')
|
, moment = require('moment')
|
||||||
, recursiveReadSync = require('recursive-readdir-sync');
|
, RECURSIVE_READ_DIR = require('recursive-readdir-sync');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The Theme class is a representation of a FluentCV theme asset.
|
The Theme class is a representation of a FluentCV theme asset.
|
||||||
@ -40,47 +40,77 @@ Abstract theme representation.
|
|||||||
var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) );
|
var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) );
|
||||||
EXTEND( true, this, themeInfo );
|
EXTEND( true, this, themeInfo );
|
||||||
|
|
||||||
|
var formatsHash = { };
|
||||||
|
|
||||||
// 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.
|
// containing info for each file.
|
||||||
var tplFolder = PATH.join( themeFolder, 'src' );
|
var tplFolder = PATH.join( themeFolder, 'src' );
|
||||||
var fmts = recursiveReadSync( tplFolder ).map( function( file ) {
|
var fmts = RECURSIVE_READ_DIR( tplFolder ).map(
|
||||||
var absPath = PATH.join( tplFolder, file );
|
function( absPath ) {
|
||||||
var pathInfo = PATH.parse(absPath);
|
|
||||||
var temp = [ pathInfo.name, {
|
var pathInfo = PATH.parse(absPath);
|
||||||
title: friendlyName(pathInfo.name),
|
|
||||||
pre: pathInfo.name,
|
// If this file lives in a specific format folder within the theme,
|
||||||
ext: pathInfo.ext.slice(1),
|
// such as "/latex" or "/html", then that format is the output format
|
||||||
path: absPath,
|
// for all files within the folder.
|
||||||
data: FS.readFileSync( absPath, 'utf8' ),
|
var outFmt = '';
|
||||||
css: null
|
var portion = pathInfo.dir.replace(tplFolder,'');
|
||||||
}];
|
if( portion && portion.trim() ) {
|
||||||
return temp;
|
var reg = /^(?:\/|\\)(html|latex|doc|pdf)(?:\/|\\)?/ig;
|
||||||
});
|
var res = reg.exec( portion );
|
||||||
|
res && (outFmt = res[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Otherwise, the output format is inferred from the filename, as in
|
||||||
|
// compact-[outputformat].[extension], for ex, compact-pdf.html.
|
||||||
|
if( !outFmt ) {
|
||||||
|
var idx = pathInfo.name.lastIndexOf('-');
|
||||||
|
outFmt = ( idx === -1 ) ? pathInfo.name : pathInfo.name.substr( idx + 1 )
|
||||||
|
}
|
||||||
|
|
||||||
|
// We should have a valid output format now
|
||||||
|
formatsHash[ outFmt ] = formatsHash[outFmt] || { outFormat: outFmt, files: [] };
|
||||||
|
|
||||||
|
var obj = {
|
||||||
|
path: absPath,
|
||||||
|
ext: pathInfo.ext.slice(1),
|
||||||
|
title: friendlyName( outFmt ),
|
||||||
|
pre: outFmt,
|
||||||
|
// outFormat: outFmt || pathInfo.name,
|
||||||
|
data: FS.readFileSync( absPath, 'utf8' ),
|
||||||
|
css: null
|
||||||
|
};
|
||||||
|
|
||||||
|
// Add this file to the list of files for this format type.
|
||||||
|
formatsHash[ outFmt ].files.push( obj );
|
||||||
|
return obj;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
// Add freebie formats every theme gets
|
// Add freebie formats every theme gets
|
||||||
fmts.push( [ 'json', { title: 'json', pre: 'json', ext: 'json', path: null, data: null } ] );
|
formatsHash[ 'json' ] = { title: 'json', outFormat: 'json', pre: 'json', ext: 'json', path: null, data: null };
|
||||||
fmts.push( [ 'yml', { title: 'yaml', pre: 'yml', ext: 'yml', path: null, data: null } ] );
|
formatsHash[ 'yml' ] = { title: 'yaml', outFormat: 'yml', pre: 'yml', ext: 'yml', path: null, data: null };
|
||||||
|
|
||||||
// Now, get all the CSS files...
|
// Now, get all the CSS files...
|
||||||
this.cssFiles = fmts.filter(function( fmt ){ return fmt[1].ext === 'css'; });
|
this.cssFiles = fmts.filter(function( fmt ){ return fmt.ext === 'css'; });
|
||||||
|
|
||||||
// ...and assemble information on them
|
// ...and assemble information on them
|
||||||
this.cssFiles.forEach(function( cssf ) {
|
this.cssFiles.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 ) {
|
||||||
return fmt[1].pre === cssf[1].pre && fmt[1].ext === 'html'
|
return fmt.pre === cssf.pre && fmt.ext === 'html'
|
||||||
});
|
});
|
||||||
fmts[ idx ][1].css = cssf[1].data;
|
fmts[ idx ].css = cssf.data;
|
||||||
fmts[ idx ][1].cssPath = cssf[1].path;
|
fmts[ idx ].cssPath = cssf.path;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove CSS files from the formats array
|
// Remove CSS files from the formats array
|
||||||
fmts = fmts.filter( function( fmt) {
|
fmts = fmts.filter( function( fmt) {
|
||||||
return fmt[1].ext !== 'css';
|
return fmt.ext !== 'css';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Create a hash out of the formats for this theme
|
// Create a hash out of the formats for this theme
|
||||||
this.formats = _.object( fmts );
|
this.formats = formatsHash;
|
||||||
|
|
||||||
// Set the official theme name
|
// Set the official theme name
|
||||||
this.name = PATH.parse( themeFolder ).name;
|
this.name = PATH.parse( themeFolder ).name;
|
||||||
|
@ -76,7 +76,7 @@ module.exports = function () {
|
|||||||
targets.push.apply(targets, fmat === '.all' ?
|
targets.push.apply(targets, fmat === '.all' ?
|
||||||
Object.keys( theTheme.formats ).map(function(k){
|
Object.keys( theTheme.formats ).map(function(k){
|
||||||
var z = theTheme.formats[k];
|
var z = theTheme.formats[k];
|
||||||
return { file: to.replace(/all$/g,z.pre), fmt: z }
|
return { file: to.replace(/all$/g,z.outFormat), fmt: z }
|
||||||
}) : [{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
|
}) : [{ file: to, fmt: theTheme.getFormat( fmat.slice(1) ) }]);
|
||||||
|
|
||||||
});
|
});
|
||||||
@ -95,17 +95,34 @@ module.exports = function () {
|
|||||||
*/
|
*/
|
||||||
function single( fi, theme ) {
|
function single( fi, theme ) {
|
||||||
try {
|
try {
|
||||||
var f = fi.file, fType = fi.fmt.ext, fName = path.basename(f,'.'+fType);
|
var f = fi.file, fType = fi.fmt.outFormat, fName = path.basename(f,'.'+fType);
|
||||||
var fObj = _.property( fi.fmt.pre )( theme.formats );
|
|
||||||
var fOut = path.join( f.substring( 0, f.lastIndexOf('.')+1 ) + fObj.pre);
|
|
||||||
|
|
||||||
_log( 'Generating '.useful + fi.fmt.title.toUpperCase().useful.bold + ' resume: '.useful +
|
if( fi.fmt.files && fi.fmt.files.length ) {
|
||||||
path.relative(process.cwd(), f ).useful.bold );
|
fi.fmt.files.forEach( function( form ) {
|
||||||
|
|
||||||
var theFormat = _fmts.filter(
|
if( form.ext === 'css' )
|
||||||
function( fmt ) { return fmt.name === fi.fmt.pre; })[0];
|
return;
|
||||||
MKDIRP.sync( path.dirname( fOut ) ); // Ensure dest folder exists;
|
|
||||||
theFormat.gen.generate( rez, fOut, _opts );
|
_log( 'Generating '.useful + form.title.toUpperCase().useful.bold + ' resume: '.useful +
|
||||||
|
path.relative(process.cwd(), f ).useful.bold );
|
||||||
|
|
||||||
|
var theFormat = _fmts.filter(
|
||||||
|
function( fmt ) { return fmt.name === form.pre; })[0];
|
||||||
|
|
||||||
|
MKDIRP.sync( path.dirname( f ) ); // Ensure dest folder exists;
|
||||||
|
theFormat.gen.generate( rez, f, _opts );
|
||||||
|
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
_log( 'Generating '.useful + fi.fmt.outFormat.toUpperCase().useful.bold + ' resume: '.useful +
|
||||||
|
path.relative(process.cwd(), f ).useful.bold );
|
||||||
|
|
||||||
|
var theFormat = _fmts.filter(
|
||||||
|
function( fmt ) { return fmt.name === fi.fmt.outFormat; })[0];
|
||||||
|
MKDIRP.sync( path.dirname( f ) ); // Ensure dest folder exists;
|
||||||
|
theFormat.gen.generate( rez, f, _opts );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch( ex ) {
|
catch( ex ) {
|
||||||
_err( ex );
|
_err( ex );
|
||||||
|
@ -25,8 +25,8 @@ HTML resume generator for FluentCV.
|
|||||||
, outFolder = PATH.parse( info.outputFile ).dir, that = this;
|
, outFolder = PATH.parse( info.outputFile ).dir, that = this;
|
||||||
|
|
||||||
info.theme.cssFiles.forEach( function( f ) {
|
info.theme.cssFiles.forEach( function( f ) {
|
||||||
var fi = PATH.parse( f[1].path );
|
var fi = PATH.parse( f.path );
|
||||||
FS.copySync( f[1].path, PATH.join( outFolder, fi.base ), { clobber: true }, function( e ) {
|
FS.copySync( f.path, PATH.join( outFolder, fi.base ), { clobber: true }, function( e ) {
|
||||||
throw { fluenterror: that.codes.copyCss, data: [cssSrc,cssDst] };
|
throw { fluenterror: that.codes.copyCss, data: [cssSrc,cssDst] };
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -96,12 +96,16 @@ Template-based resume generator base for FluentCV.
|
|||||||
// Load theme and CSS data
|
// Load theme and CSS data
|
||||||
var tplFolder = PATH.join( tFolder, 'src' );
|
var tplFolder = PATH.join( tFolder, 'src' );
|
||||||
var curFmt = theme.getFormat( this.format );
|
var curFmt = theme.getFormat( this.format );
|
||||||
var cssInfo = { file: curFmt.css ? curFmt.cssPath : null, data: curFmt.css || null };
|
|
||||||
|
|
||||||
// Compile and invoke the template!
|
var that = this;
|
||||||
var mk = this.single( rez, curFmt.data, this.format, cssInfo, this.opts );
|
curFmt.files.forEach(function(tplInfo){
|
||||||
this.onBeforeSave && (mk = this.onBeforeSave( { mk: mk, theme: theme, outputFile: f } ));
|
|
||||||
FS.writeFileSync( f, mk, { encoding: 'utf8', flags: 'w' } );
|
var cssInfo = { file: tplInfo.css ? tplInfo.cssPath : null, data: tplInfo.css || null };
|
||||||
|
// Compile and invoke the template!
|
||||||
|
var mk = that.single( rez, tplInfo.data, that.format, cssInfo, that.opts );
|
||||||
|
that.onBeforeSave && (mk = that.onBeforeSave( { mk: mk, theme: theme, outputFile: f } ));
|
||||||
|
FS.writeFileSync( f, mk, { encoding: 'utf8', flags: 'w' } );
|
||||||
|
});
|
||||||
|
|
||||||
},
|
},
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user