Last active
August 16, 2021 23:30
-
-
Save jfhbrook/b38278c9ba4b485ec6a8eb3224191875 to your computer and use it in GitHub Desktop.
Is there a module that does this already?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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