documentation/lib/get_template.js
Tom MacWright c24a9b88a4 Enable jsdoc rule and enforce it.
Also:

* Moves reduction out of parsers so that they don't have awkward
  function signatures
2015-09-28 20:36:07 -04:00

23 lines
610 B
JavaScript

'use strict';
var fs = require('fs');
var path = require('path');
/**
* Get a Handlebars template file out of a theme and compile it into
* a template function
*
* @param {Object} Handlebars handlebars instance
* @param {string} themeModule base directory of themey
* @param {string} name template name
* @returns {Function} template function
*/
module.exports = function getTemplate(Handlebars, themeModule, name) {
try {
return Handlebars
.compile(fs.readFileSync(path.join(themeModule, name), 'utf8'));
} catch (e) {
throw new Error('Template file ' + name + ' missing');
}
};