2015-12-06 21:19:55 +00:00
|
|
|
/**
|
2015-12-17 15:15:59 +00:00
|
|
|
Definition of the HandlebarsGenerator class.
|
|
|
|
@license MIT. Copyright (c) 2015 James Devlin / FluentDesk.
|
|
|
|
@module handlebars-generator.js
|
2015-12-06 21:19:55 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
|
|
|
|
|
2015-12-17 15:15:59 +00:00
|
|
|
|
|
|
|
var _ = require('underscore')
|
|
|
|
, HANDLEBARS = require('handlebars')
|
|
|
|
, FS = require('fs')
|
2015-12-18 15:10:30 +00:00
|
|
|
, registerHelpers = require('./handlebars-helpers');
|
2015-12-17 15:15:59 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Perform template-based resume generation using Handlebars.js.
|
|
|
|
@method generate
|
|
|
|
*/
|
2015-12-17 01:13:27 +00:00
|
|
|
module.exports = function( json, jst, format, cssInfo, opts, theme ) {
|
|
|
|
|
2015-12-17 15:15:59 +00:00
|
|
|
// Pre-compile any partials present in the theme.
|
2015-12-17 01:13:27 +00:00
|
|
|
_.each( theme.partials, function( el ) {
|
|
|
|
var tplData = FS.readFileSync( el.path, 'utf8' );
|
|
|
|
var compiledTemplate = HANDLEBARS.compile( tplData );
|
|
|
|
HANDLEBARS.registerPartial( el.name, compiledTemplate );
|
|
|
|
});
|
|
|
|
|
2015-12-17 15:15:59 +00:00
|
|
|
// Register necessary helpers.
|
|
|
|
registerHelpers();
|
|
|
|
|
|
|
|
// Compile and run the Handlebars template.
|
|
|
|
var template = HANDLEBARS.compile(jst);
|
|
|
|
return template({
|
|
|
|
r: json,
|
|
|
|
filt: opts.filters,
|
|
|
|
cssInfo: cssInfo,
|
|
|
|
headFragment: opts.headFragment || ''
|
|
|
|
});
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-12-06 21:19:55 +00:00
|
|
|
}());
|