Permalink
Browse files

Added support for overriding EJS defaults

  • Loading branch information...
1 parent 6f88a87 commit f4598183c4814528dc0bc7d555bbfe83d4753405 @niftylettuce committed Aug 7, 2012
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/main.js
View
@@ -14,10 +14,15 @@ var path = require('path')
, fs = require('fs')
, async = require('async')
, ejs = require('ejs')
- , juice = require('juice');
+ , juice = require('juice')
+ , _ = require('underscore');
// # Email Template
-var EmailTemplate = function(templateDirectory, done) {
+var EmailTemplate = function(templateDirectory, defaults, done) {
+
+ if (typeof defaults === 'function') done = defaults;
+
+ var that = this;
this.html = '';
this.text = '';
@@ -29,6 +34,7 @@ var EmailTemplate = function(templateDirectory, done) {
text = that.text;
stylesheet = that.stylesheet;
}
+ locals = _.defaults(locals, (typeof defaults === 'object') ? defaults : {});
html = ejs.render(html, locals);
text = (text) ? ejs.render(text, locals) : '';
if (stylesheet) html = juice(html, stylesheet);
@@ -41,7 +47,6 @@ var EmailTemplate = function(templateDirectory, done) {
return done(new Error('templateDirectory is undefined'));
// Ensure the `templateDirectory` is a valid directory path
- var that = this;
fs.stat(templateDirectory, function(err, stats) {
if (err) return done(new Error(err));

0 comments on commit f459818

Please sign in to comment.