mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 08:20:11 +00:00
Add basic multiplexing support.
This commit is contained in:
parent
8ee2716245
commit
5a716dff16
@ -27,26 +27,62 @@ Abstract theme representation.
|
|||||||
*/
|
*/
|
||||||
Theme.prototype.open = function( themeFolder ) {
|
Theme.prototype.open = function( themeFolder ) {
|
||||||
|
|
||||||
function friendlyName( val ) {
|
|
||||||
val = val.trim().toLowerCase();
|
|
||||||
var friendly = { yml: 'yaml', md: 'markdown', txt: 'text' };
|
|
||||||
return friendly[val] || val;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Open the [theme-name].json file; should have the same name as folder
|
// Open the [theme-name].json file; should have the same name as folder
|
||||||
this.folder = themeFolder;
|
this.folder = themeFolder;
|
||||||
var pathInfo = PATH.parse( themeFolder );
|
var pathInfo = PATH.parse( themeFolder );
|
||||||
var themeFile = PATH.join( themeFolder, pathInfo.base + '.json' );
|
var themeFile = PATH.join( themeFolder, pathInfo.base + '.json' );
|
||||||
var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) );
|
var themeInfo = JSON.parse( FS.readFileSync( themeFile, 'utf8' ) );
|
||||||
|
var that = this;
|
||||||
|
|
||||||
// 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 );
|
||||||
|
|
||||||
|
// Set up a formats has for the theme
|
||||||
|
var formatsHash = { };
|
||||||
|
|
||||||
|
// Check for an explicit "formats" entry in the theme JSON. If it has one,
|
||||||
|
// then this theme declares its files explicitly.
|
||||||
|
if( !!this.formats ) {
|
||||||
|
formatsHash = loadExplicit.call( this );
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
formatsHash = loadImplicit.call( this );
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add freebie formats every theme gets
|
||||||
|
formatsHash[ 'json' ] = { title: 'json', outFormat: 'json', pre: 'json', ext: 'json', path: null, data: null };
|
||||||
|
formatsHash[ 'yml' ] = { title: 'yaml', outFormat: 'yml', pre: 'yml', ext: 'yml', path: null, data: null };
|
||||||
|
|
||||||
|
// Cache
|
||||||
|
this.formats = formatsHash;
|
||||||
|
|
||||||
|
// Set the official theme name
|
||||||
|
this.name = PATH.parse( this.folder ).name;
|
||||||
|
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Determine if the theme supports the specified output format.
|
||||||
|
*/
|
||||||
|
Theme.prototype.hasFormat = function( fmt ) {
|
||||||
|
return _.has( this.formats, fmt );
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
Determine if the theme supports the specified output format.
|
||||||
|
*/
|
||||||
|
Theme.prototype.getFormat = function( fmt ) {
|
||||||
|
return this.formats[ fmt ];
|
||||||
|
};
|
||||||
|
|
||||||
|
function loadImplicit() {
|
||||||
|
|
||||||
// Set up a hash of formats supported by this theme.
|
// Set up a hash of formats supported by this theme.
|
||||||
var formatsHash = { };
|
var formatsHash = { };
|
||||||
|
|
||||||
// Establish the base theme folder
|
// Establish the base theme folder
|
||||||
var tplFolder = PATH.join( themeFolder, 'src' );
|
var tplFolder = PATH.join( this.folder, 'src' );
|
||||||
|
|
||||||
// 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
|
||||||
@ -73,7 +109,8 @@ Abstract theme representation.
|
|||||||
}
|
}
|
||||||
|
|
||||||
// We should have a valid output format now.
|
// We should have a valid output format now.
|
||||||
formatsHash[ outFmt ] = formatsHash[outFmt] || { outFormat: outFmt, files: [] };
|
formatsHash[ outFmt ] =
|
||||||
|
formatsHash[outFmt] || { outFormat: outFmt, files: [] };
|
||||||
|
|
||||||
// Create the file representation object.
|
// Create the file representation object.
|
||||||
var obj = {
|
var obj = {
|
||||||
@ -91,10 +128,6 @@ Abstract theme representation.
|
|||||||
return obj;
|
return obj;
|
||||||
});
|
});
|
||||||
|
|
||||||
// Add freebie formats every theme gets
|
|
||||||
formatsHash[ 'json' ] = { title: 'json', outFormat: 'json', pre: 'json', ext: 'json', 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.ext === 'css'; }))
|
(this.cssFiles = fmts.filter(function( fmt ){ return fmt.ext === 'css'; }))
|
||||||
.forEach(function( cssf ) {
|
.forEach(function( cssf ) {
|
||||||
@ -111,28 +144,49 @@ Abstract theme representation.
|
|||||||
return fmt.ext !== 'css';
|
return fmt.ext !== 'css';
|
||||||
});
|
});
|
||||||
|
|
||||||
// Cache the formats hash
|
return formatsHash;
|
||||||
this.formats = formatsHash;
|
}
|
||||||
|
|
||||||
// Set the official theme name
|
function loadExplicit() {
|
||||||
this.name = PATH.parse( themeFolder ).name;
|
|
||||||
|
|
||||||
return this;
|
var formatsHash = { };
|
||||||
};
|
var that = this;
|
||||||
|
|
||||||
/**
|
// Establish the base theme folder
|
||||||
Determine if the theme supports the specified output format.
|
var tplFolder = this.folder;//PATH.join( this.folder, 'src' );
|
||||||
*/
|
|
||||||
Theme.prototype.hasFormat = function( fmt ) {
|
|
||||||
return _.has( this.formats, fmt );
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
// Iterate over all keys in the "formats" section of the theme JSON file.
|
||||||
Determine if the theme supports the specified output format.
|
// Each key will be a format (html, latex, pdf, etc) with some data.
|
||||||
*/
|
Object.keys( this.formats ).forEach( function( k ) {
|
||||||
Theme.prototype.getFormat = function( fmt ) {
|
|
||||||
return this.formats[ fmt ];
|
formatsHash[ k ] = {
|
||||||
};
|
outFormat: k,
|
||||||
|
files: that.formats[ k ].files.map(function(fi){
|
||||||
|
|
||||||
|
var absPath = PATH.join( tplFolder, fi );
|
||||||
|
var pathInfo = PATH.parse( absPath );
|
||||||
|
|
||||||
|
|
||||||
|
return {
|
||||||
|
path: absPath,
|
||||||
|
ext: pathInfo.ext.slice(1),
|
||||||
|
title: friendlyName( k ),
|
||||||
|
pre: k,
|
||||||
|
outFormat: k,
|
||||||
|
data: FS.readFileSync( absPath, 'utf8' ),
|
||||||
|
css: null
|
||||||
|
};
|
||||||
|
})
|
||||||
|
};
|
||||||
|
});
|
||||||
|
return formatsHash;
|
||||||
|
}
|
||||||
|
|
||||||
|
function friendlyName( val ) {
|
||||||
|
val = val.trim().toLowerCase();
|
||||||
|
var friendly = { yml: 'yaml', md: 'markdown', txt: 'text' };
|
||||||
|
return friendly[val] || val;
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = Theme;
|
module.exports = Theme;
|
||||||
|
|
||||||
|
@ -10,27 +10,37 @@ Underscore template generate for FluentCV.
|
|||||||
module.exports = function( json, jst, format, cssInfo, opts ) {
|
module.exports = function( json, jst, format, cssInfo, opts ) {
|
||||||
|
|
||||||
// Tweak underscore's default template delimeters
|
// Tweak underscore's default template delimeters
|
||||||
_.templateSettings = opts.template;
|
var delims = opts.themeObj.delimeters || opts.template;
|
||||||
|
if( opts.themeObj.delimeters ) {
|
||||||
|
delims = _.mapObject( delims, function(val,key) {
|
||||||
|
return new RegExp( val, "ig")
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_.templateSettings = delims;
|
||||||
|
|
||||||
// Convert {{ someVar }} to {% print(filt.out(someVar) %}
|
// Convert {{ someVar }} to {% print(filt.out(someVar) %}
|
||||||
// Convert {{ someVar|someFilter }} to {% print(filt.someFilter(someVar) %}
|
// Convert {{ someVar|someFilter }} to {% print(filt.someFilter(someVar) %}
|
||||||
jst = jst.replace( _.templateSettings.interpolate, function replace(m, p1) {
|
jst = jst.replace( delims.interpolate, function replace(m, p1) {
|
||||||
if( p1.indexOf('|') > -1 ) {
|
if( p1.indexOf('|') > -1 ) {
|
||||||
var terms = p1.split('|');
|
var terms = p1.split('|');
|
||||||
return '{% print( filt.' + terms[1] + '( ' + terms[0] + ' )) %}';
|
return '[~ print( filt.' + terms[1] + '( ' + terms[0] + ' )) ]]';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return '{% print( filt.out(' + p1 + ') ) %}';
|
return '[~ print( filt.out(' + p1 + ') ) ]]';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Strip {# comments #}
|
// Strip {# comments #}
|
||||||
jst = jst.replace( _.templateSettings.comment, '');
|
jst = jst.replace( delims.comment, '');
|
||||||
|
|
||||||
// Compile and run the template. TODO: avoid unnecessary recompiles.
|
// Compile and run the template. TODO: avoid unnecessary recompiles.
|
||||||
jst = _.template(jst)({ r: json, filt: opts.filters, cssInfo: cssInfo, headFragment: opts.headFragment || '' });
|
var compiled = _.template(jst);
|
||||||
|
var ret = compiled({
|
||||||
return jst;
|
r: json,
|
||||||
|
filt: opts.filters,
|
||||||
|
cssInfo: cssInfo,
|
||||||
|
headFragment: opts.headFragment || ''
|
||||||
|
});
|
||||||
|
return ret;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -93,21 +93,21 @@ module.exports = function () {
|
|||||||
@param f Full path to the destination resume to generate, for example,
|
@param f Full path to the destination resume to generate, for example,
|
||||||
"/foo/bar/resume.pdf" or "c:\foo\bar\resume.txt".
|
"/foo/bar/resume.pdf" or "c:\foo\bar\resume.txt".
|
||||||
*/
|
*/
|
||||||
function single( fi, theme ) {
|
function single( targetInfo, theme ) {
|
||||||
try {
|
try {
|
||||||
var f = fi.file, fType = fi.fmt.outFormat, fName = path.basename(f,'.'+fType);
|
var f = targetInfo.file, fType = targetInfo.fmt.outFormat, fName = path.basename(f,'.'+fType);
|
||||||
|
|
||||||
if( fi.fmt.files && fi.fmt.files.length ) {
|
if( targetInfo.fmt.files && targetInfo.fmt.files.length ) {
|
||||||
fi.fmt.files.forEach( function( form ) {
|
targetInfo.fmt.files.forEach( function( form ) {
|
||||||
|
|
||||||
if( form.ext === 'css' )
|
if( form.ext === 'css' )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_log( 'Generating '.useful + form.title.toUpperCase().useful.bold + ' resume: '.useful +
|
_log( 'Generating '.useful + targetInfo.fmt.outFormat.toUpperCase().useful.bold + ' resume: '.useful +
|
||||||
path.relative(process.cwd(), f ).useful.bold );
|
path.relative(process.cwd(), f ).useful.bold );
|
||||||
|
|
||||||
var theFormat = _fmts.filter(
|
var theFormat = _fmts.filter(
|
||||||
function( fmt ) { return fmt.name === form.pre; })[0];
|
function( fmt ) { return fmt.name === targetInfo.fmt.outFormat; })[0];
|
||||||
|
|
||||||
MKDIRP.sync( path.dirname( f ) ); // Ensure dest folder exists;
|
MKDIRP.sync( path.dirname( f ) ); // Ensure dest folder exists;
|
||||||
theFormat.gen.generate( rez, f, _opts );
|
theFormat.gen.generate( rez, f, _opts );
|
||||||
@ -115,11 +115,11 @@ module.exports = function () {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
_log( 'Generating '.useful + fi.fmt.outFormat.toUpperCase().useful.bold + ' resume: '.useful +
|
_log( 'Generating '.useful + targetInfo.fmt.outFormat.toUpperCase().useful.bold + ' resume: '.useful +
|
||||||
path.relative(process.cwd(), f ).useful.bold );
|
path.relative(process.cwd(), f ).useful.bold );
|
||||||
|
|
||||||
var theFormat = _fmts.filter(
|
var theFormat = _fmts.filter(
|
||||||
function( fmt ) { return fmt.name === fi.fmt.outFormat; })[0];
|
function( fmt ) { return fmt.name === targetInfo.fmt.outFormat; })[0];
|
||||||
MKDIRP.sync( path.dirname( f ) ); // Ensure dest folder exists;
|
MKDIRP.sync( path.dirname( f ) ); // Ensure dest folder exists;
|
||||||
theFormat.gen.generate( rez, f, _opts );
|
theFormat.gen.generate( rez, f, _opts );
|
||||||
}
|
}
|
||||||
|
@ -11,7 +11,7 @@ LaTeXGenerator generates a LaTeX resume via TemplateGenerator.
|
|||||||
var LaTeXGenerator = module.exports = TemplateGenerator.extend({
|
var LaTeXGenerator = module.exports = TemplateGenerator.extend({
|
||||||
|
|
||||||
init: function(){
|
init: function(){
|
||||||
this._super( 'tex', 'tex' );
|
this._super( 'latex', 'tex' );
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user