1
0
mirror of https://github.com/JuanCanham/HackMyResume.git synced 2024-07-07 02:00:06 +01:00
HackMyResume/src/eng/handlebars-generator.js

57 lines
1.4 KiB
JavaScript
Raw Normal View History

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.
@class HandlebarsGenerator
2015-12-17 15:15:59 +00:00
*/
var HandlebarsGenerator = module.exports = {
2015-12-17 15:15:59 +00:00
generate: function( json, jst, format, cssInfo, opts, theme ) {
// Pre-compile any partials present in the 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.
registerHelpers( theme );
2015-12-17 15:15:59 +00:00
// Compile and run the Handlebars template.
var template = HANDLEBARS.compile(jst);
var encData = json;
( format === 'html' || format === 'pdf' ) && (encData = json.markdownify());
( format === 'doc' ) && (encData = json.xmlify());
return template({
r: encData,
RAW: json,
filt: opts.filters,
cssInfo: cssInfo,
2015-12-31 00:45:50 +00:00
opts: opts,
headFragment: opts.headFragment || ''
});
2015-12-17 15:15:59 +00:00
}
};
2015-12-17 15:15:59 +00:00
2015-12-06 21:19:55 +00:00
}());