1.0.0 • Published 8 years ago

email-templates-as-promised v1.0.0

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

Build Status

email-templates-as-promised

Promisified version of email-templates

Instead of ...

emailTemplates(templatesDir, options, function(err, template) {
  var locals = { pasta: 'Spaghetti' };
  template('pasta-dinner', locals, function(err, html, text) {
    // rendered templates
  });
});

... just do

var render = emailTemplates(templatesDir, options);

var locals = { pasta: 'Spaghetti' };
var pastaDiner = render('pasta-dinner', locals).then(function(res) {
  // rendered templates
  // res == {
  //   html: '',
  //   text: ''
  // }
});

This way render function can easily be exported:

//emails.js

var render = emailTemplates(templatesDir, options);

module.exports.pastaDinner = function(locals) {
  return render('pasta-dinner', locals);
};

// usage

var emails = require('./emails');

emails.pastaDiner({ pasta: 'Spagetti' }).then(function(res) {
  // do something
});

Rendered templates are also cached by templatesDir.