mirror of
https://github.com/JuanCanham/HackMyResume.git
synced 2024-11-22 08:20:11 +00:00
Class-ify Underscore/Handlebars engine.
This commit is contained in:
parent
b0bc71cd66
commit
1441fe3ae5
@ -17,31 +17,34 @@ Definition of the HandlebarsGenerator class.
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Perform template-based resume generation using Handlebars.js.
|
Perform template-based resume generation using Handlebars.js.
|
||||||
@method generate
|
@class HandlebarsGenerator
|
||||||
*/
|
*/
|
||||||
module.exports = function( json, jst, format, cssInfo, opts, theme ) {
|
var HandlebarsGenerator = module.exports = {
|
||||||
|
|
||||||
// Pre-compile any partials present in the theme.
|
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
||||||
_.each( theme.partials, function( el ) {
|
|
||||||
var tplData = FS.readFileSync( el.path, 'utf8' );
|
|
||||||
var compiledTemplate = HANDLEBARS.compile( tplData );
|
|
||||||
HANDLEBARS.registerPartial( el.name, compiledTemplate );
|
|
||||||
});
|
|
||||||
|
|
||||||
// Register necessary helpers.
|
// Pre-compile any partials present in the theme.
|
||||||
registerHelpers();
|
_.each( theme.partials, function( el ) {
|
||||||
|
var tplData = FS.readFileSync( el.path, 'utf8' );
|
||||||
|
var compiledTemplate = HANDLEBARS.compile( tplData );
|
||||||
|
HANDLEBARS.registerPartial( el.name, compiledTemplate );
|
||||||
|
});
|
||||||
|
|
||||||
// Compile and run the Handlebars template.
|
// Register necessary helpers.
|
||||||
var template = HANDLEBARS.compile(jst);
|
registerHelpers();
|
||||||
return template({
|
|
||||||
r: json,
|
// Compile and run the Handlebars template.
|
||||||
filt: opts.filters,
|
var template = HANDLEBARS.compile(jst);
|
||||||
cssInfo: cssInfo,
|
return template({
|
||||||
headFragment: opts.headFragment || ''
|
r: format === 'html' || format === 'pdf' ? json.markdownify() : json,
|
||||||
});
|
RAW: json,
|
||||||
|
filt: opts.filters,
|
||||||
|
cssInfo: cssInfo,
|
||||||
|
headFragment: opts.headFragment || ''
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -1,37 +1,52 @@
|
|||||||
/**
|
/**
|
||||||
Definition of the UnderscoreGenerator class.
|
Definition of the UnderscoreGenerator class.
|
||||||
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
||||||
|
@module underscore-generator.js
|
||||||
*/
|
*/
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
var _ = require('underscore');
|
var _ = require('underscore');
|
||||||
|
|
||||||
module.exports = function( json, jst, format, cssInfo, opts, theme ) {
|
|
||||||
|
|
||||||
// Tweak underscore's default template delimeters
|
|
||||||
var delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template;
|
/**
|
||||||
if( opts.themeObj && opts.themeObj.delimeters ) {
|
Perform template-based resume generation using Underscore.js.
|
||||||
delims = _.mapObject( delims, function(val,key) {
|
@class UnderscoreGenerator
|
||||||
return new RegExp( val, "ig");
|
*/
|
||||||
|
var UnderscoreGenerator = module.exports = {
|
||||||
|
|
||||||
|
generate: function( json, jst, format, cssInfo, opts, theme ) {
|
||||||
|
|
||||||
|
// Tweak underscore's default template delimeters
|
||||||
|
var delims = (opts.themeObj && opts.themeObj.delimeters) || opts.template;
|
||||||
|
if( opts.themeObj && opts.themeObj.delimeters ) {
|
||||||
|
delims = _.mapObject( delims, function(val,key) {
|
||||||
|
return new RegExp( val, "ig");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
_.templateSettings = delims;
|
||||||
|
|
||||||
|
// Strip {# comments #}
|
||||||
|
jst = jst.replace( delims.comment, '');
|
||||||
|
|
||||||
|
// Compile and run the template. TODO: avoid unnecessary recompiles.
|
||||||
|
var compiled = _.template(jst);
|
||||||
|
var ret = compiled({
|
||||||
|
r: format === 'html' || format === 'pdf' ? json.markdownify() : json,
|
||||||
|
filt: opts.filters,
|
||||||
|
XML: require('xml-escape'),
|
||||||
|
RAW: json,
|
||||||
|
cssInfo: cssInfo,
|
||||||
|
headFragment: opts.headFragment || ''
|
||||||
});
|
});
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
_.templateSettings = delims;
|
|
||||||
|
|
||||||
// Strip {# comments #}
|
|
||||||
jst = jst.replace( delims.comment, '');
|
|
||||||
// Compile and run the template. TODO: avoid unnecessary recompiles.
|
|
||||||
var compiled = _.template(jst);
|
|
||||||
var ret = compiled({
|
|
||||||
r: format === 'html' || format === 'pdf' ? json.markdownify() : json,
|
|
||||||
filt: opts.filters,
|
|
||||||
XML: require('xml-escape'),
|
|
||||||
RAW: json,
|
|
||||||
cssInfo: cssInfo,
|
|
||||||
headFragment: opts.headFragment || ''
|
|
||||||
});
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}());
|
}());
|
||||||
|
@ -143,7 +143,7 @@ Definition of the TemplateGenerator class.
|
|||||||
single: function( json, jst, format, cssInfo, opts, theme ) {
|
single: function( json, jst, format, cssInfo, opts, theme ) {
|
||||||
this.opts.freezeBreaks && ( jst = freeze(jst) );
|
this.opts.freezeBreaks && ( jst = freeze(jst) );
|
||||||
var eng = require( '../eng/' + theme.engine + '-generator' );
|
var eng = require( '../eng/' + theme.engine + '-generator' );
|
||||||
var result = eng( json, jst, format, cssInfo, opts, theme );
|
var result = eng.generate( json, jst, format, cssInfo, opts, theme );
|
||||||
this.opts.freezeBreaks && ( result = unfreeze(result) );
|
this.opts.freezeBreaks && ( result = unfreeze(result) );
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user