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

Add baseline Markdownification.

This commit is contained in:
devlinjd 2015-12-08 22:22:33 -05:00
parent e8704e1374
commit f3c9f92263
2 changed files with 39 additions and 13 deletions

View File

@ -11,6 +11,7 @@ Definition of the FRESHResume class.
, _ = require('underscore') , _ = require('underscore')
, PATH = require('path') , PATH = require('path')
, moment = require('moment') , moment = require('moment')
, MD = require('marked')
, CONVERTER = require('./convert'); , CONVERTER = require('./convert');
/** /**
@ -70,6 +71,41 @@ Definition of the FRESHResume class.
return JSON.stringify( obj, replacer, 2 ); return JSON.stringify( obj, replacer, 2 );
}, },
/**
*/
FreshResume.prototype.markdownify = function() {
var that = this;
var ret = extend(true, { }, this);
// TODO: refactor recursion
function markdownifyStringsInObject( obj ) {
if( !obj ) return;
if( Object.prototype.toString.call( obj ) === '[object Array]' ) {
obj.forEach(function(elem){
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] );
});
}
}
Object.keys( ret ).forEach(function(member){
markdownifyStringsInObject( that[ member ] );
});
return ret;
};
/** /**
Convert this object to a JSON string, sanitizing meta-properties along the Convert this object to a JSON string, sanitizing meta-properties along the
way. Don't override .toString(). way. Don't override .toString().

View File

@ -18,25 +18,15 @@ Underscore template generate for FluentCV.
} }
_.templateSettings = delims; _.templateSettings = delims;
// Convert {{ someVar }} to {% print(filt.out(someVar) %}
// Convert {{ someVar|someFilter }} to {% print(filt.someFilter(someVar) %}
jst = jst.replace( delims.interpolate, function replace(m, p1) {
if( p1.indexOf('|') > -1 ) {
var terms = p1.split('|');
return '[~ print( filt.' + terms[1] + '( ' + terms[0] + ' )) ~]';
}
else {
return '[~ print( filt.out(' + p1 + ') ) ~]';
}
});
// Strip {# comments #} // Strip {# comments #}
jst = jst.replace( delims.comment, ''); jst = jst.replace( delims.comment, '');
// Compile and run the template. TODO: avoid unnecessary recompiles. // Compile and run the template. TODO: avoid unnecessary recompiles.
var compiled = _.template(jst); var compiled = _.template(jst);
var mr = json.markdownify();
var ret = compiled({ var ret = compiled({
r: json, r: json.markdownify(),
filt: opts.filters, filt: opts.filters,
cssInfo: cssInfo, cssInfo: cssInfo,
headFragment: opts.headFragment || '' headFragment: opts.headFragment || ''