compileTemplates.js 857 B

12345678910111213141516171819202122232425262728
  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. console.log("Helpers:", config.helpers);
  14. config.helpers.map(helper => {
  15. console.log("helper:", eval(helper.content.toString()));
  16. const evalledhelper = require("../../" + helper.path);
  17. Handlebars.registerHelper(helper.name, eval(helper.content.toString()));
  18. });
  19. }
  20. if (config.partials) {
  21. config.partials.map(partial =>
  22. Handlebars.registerPartial(partial.name, partial.content)
  23. );
  24. }
  25. return item => compileTemplates(config, item);
  26. };
  27. module.exports = compileTemplates;