compileTemplates.js 688 B

12345678910111213141516171819202122232425
  1. const Handlebars = require("handlebars");
  2. const handlebarsCompiler = Handlebars.compile;
  3. function compileTemplates(config, item) {
  4. return new Promise(function(resolve) {
  5. resolve({
  6. ...item,
  7. template: handlebarsCompiler(item.content)
  8. });
  9. });
  10. }
  11. compileTemplates.withConfig = function(config) {
  12. if (config.helpers) {
  13. config.helpers.map(helper => {
  14. Handlebars.registerHelper(helper.name, eval(helper.content.toString()));
  15. });
  16. }
  17. if (config.partials) {
  18. config.partials.map(partial =>
  19. Handlebars.registerPartial(partial.name, partial.content)
  20. );
  21. }
  22. return item => compileTemplates(config, item);
  23. };
  24. module.exports = compileTemplates;