Skip to content

Instantly share code, notes, and snippets.

@jfhbrook
Last active August 16, 2021 23:30
Show Gist options
  • Save jfhbrook/b38278c9ba4b485ec6a8eb3224191875 to your computer and use it in GitHub Desktop.
Save jfhbrook/b38278c9ba4b485ec6a8eb3224191875 to your computer and use it in GitHub Desktop.
Is there a module that does this already?
var fs = require('fs'),
ejs = require('ejs');l
module.exports = function(root) {
var templates = {};
fs.readdirSync(root).forEach(function (filename) {
templates[path.basename(filename)] = ejs.compile(
fs.readFileSync(path.join(root, filename))
);
});
return function render(name, vars) {
return templates[name](vars);
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment