From 857de6575007f8dc6ad91e615c16919a8fd506c2 Mon Sep 17 00:00:00 2001 From: devlinjd Date: Wed, 9 Dec 2015 00:13:58 -0500 Subject: [PATCH] More MEGADESK. --- src/core/fresh-resume.js | 39 ++++++++++++++++++++++++--------- src/core/theme.js | 7 +++--- src/eng/underscore-generator.js | 5 ++--- 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/src/core/fresh-resume.js b/src/core/fresh-resume.js index 6446f4a..afeaf42 100644 --- a/src/core/fresh-resume.js +++ b/src/core/fresh-resume.js @@ -57,6 +57,12 @@ Definition of the FRESHResume class. return this; } + FreshResume.prototype.dupe = function() { + var rnew = new FreshResume(); + rnew.parse( this.stringify(), { } ); + return rnew; + }; + /** Convert the supplied object to a JSON string, sanitizing meta-properties along the way. @@ -77,30 +83,42 @@ Definition of the FRESHResume class. FreshResume.prototype.markdownify = function() { var that = this; - var ret = extend(true, { }, this); + var ret = this.dupe(); + + function MDIN(txt){ + return MD(txt || '' ).replace(/^\s*\|\<\/p\>\s*$/gi, ''); + } // TODO: refactor recursion - function markdownifyStringsInObject( obj ) { + function markdownifyStringsInObject( obj, inline ) { if( !obj ) return; + + inline = inline === undefined || inline; + if( Object.prototype.toString.call( obj ) === '[object Array]' ) { - obj.forEach(function(elem){ - markdownifyStringsInObject( elem ); + obj.forEach(function(elem, idx, ar){ + if( typeof elem === 'string' || elem instanceof String ) + ar[idx] = inline ? MDIN(elem) : MD( elem ); + else + markdownifyStringsInObject( elem ); }); } else if (typeof obj === 'object') { - if( obj._isAMomentObject || obj.safe ) - return; Object.keys( obj ).forEach(function(key) { var sub = obj[key]; - if( typeof sub === 'string' || sub instanceof String ) - obj[key] = MD( obj[key] ); + if( typeof sub === 'string' || sub instanceof String ) { + if( key !== 'url' ) + obj[key] = inline ? MDIN( obj[key] ) : MD( obj[key] ); + } + else + markdownifyStringsInObject( sub ); }); } } Object.keys( ret ).forEach(function(member){ - markdownifyStringsInObject( that[ member ] ); + markdownifyStringsInObject( ret[ member ] ); }); return ret; @@ -191,7 +209,8 @@ Definition of the FRESHResume class. Get the default (empty) sheet. */ FreshResume.default = function() { - return new FreshResume().open( PATH.join( __dirname, 'empty-fresh.json'), 'Empty' ); + return new FreshResume().open( + PATH.join( __dirname, 'empty-fresh.json'), 'Empty' ); } /** diff --git a/src/core/theme.js b/src/core/theme.js index 17a9dc5..26ddd65 100644 --- a/src/core/theme.js +++ b/src/core/theme.js @@ -136,10 +136,11 @@ Abstract theme representation. // Now, get all the CSS files... (this.cssFiles = fmts.filter(function( fmt ){ return fmt.ext === 'css'; })) .forEach(function( cssf ) { - // For each CSS file, get its corresponding HTML file - var idx = _.findIndex(fmts, function( fmt ) { - return fmt.pre === cssf.pre && fmt.ext === 'html' + // For each CSS file, get its corresponding HTML file + var idx = _.findIndex(fmts, function( fmt ) { + return fmt.pre === cssf.pre && fmt.ext === 'html' }); + cssf.action = null; fmts[ idx ].css = cssf.data; fmts[ idx ].cssPath = cssf.path; }); diff --git a/src/eng/underscore-generator.js b/src/eng/underscore-generator.js index a560dd6..0aeb3b5 100644 --- a/src/eng/underscore-generator.js +++ b/src/eng/underscore-generator.js @@ -22,12 +22,11 @@ Underscore template generate for FluentCV. jst = jst.replace( delims.comment, ''); // Compile and run the template. TODO: avoid unnecessary recompiles. var compiled = _.template(jst); - - var mr = json.markdownify(); - var ret = compiled({ r: json.markdownify(), filt: opts.filters, + XML: require('xml-escape'), + RAW: json, cssInfo: cssInfo, headFragment: opts.headFragment || '' });