mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-12-23 13:47:22 +00:00
Add baseline Markdownification.
This commit is contained in:
parent
e8704e1374
commit
f3c9f92263
@ -11,6 +11,7 @@ Definition of the FRESHResume class.
|
||||
, _ = require('underscore')
|
||||
, PATH = require('path')
|
||||
, moment = require('moment')
|
||||
, MD = require('marked')
|
||||
, CONVERTER = require('./convert');
|
||||
|
||||
/**
|
||||
@ -70,6 +71,41 @@ Definition of the FRESHResume class.
|
||||
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
|
||||
way. Don't override .toString().
|
||||
|
@ -18,25 +18,15 @@ Underscore template generate for FluentCV.
|
||||
}
|
||||
_.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 #}
|
||||
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,
|
||||
r: json.markdownify(),
|
||||
filt: opts.filters,
|
||||
cssInfo: cssInfo,
|
||||
headFragment: opts.headFragment || ''
|
||||
|
Loading…
Reference in New Issue
Block a user