email-templates
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -1,2 +0,1 @@ | ||
// node-email-templates | ||
@@ -18,7 +17,12 @@ // Copyright (c) 2012 Nick Baugh <niftylettuce@gmail.com> | ||
, 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 = ''; | ||
@@ -28,3 +32,3 @@ this.text = ''; | ||
this.render = function(locals, html, text, stylesheet, callback) { | ||
if (html instanceof Function) { | ||
if (typeof html === 'function') { | ||
callback = html; | ||
@@ -35,6 +39,7 @@ html = that.html; | ||
} | ||
locals = _.defaults(locals, (typeof defaults === 'object') ? defaults : {}); | ||
html = ejs.render(html, locals); | ||
text = (text) ? ejs.render(text, locals) : ''; | ||
if (stylesheet) html = juice(html, stylesheet); | ||
if (html instanceof Function) callback = html; | ||
if (typeof html === 'function') callback = html; | ||
return callback(null, html, text); | ||
@@ -48,3 +53,2 @@ }; | ||
// Ensure the `templateDirectory` is a valid directory path | ||
var that = this; | ||
fs.stat(templateDirectory, function(err, stats) { | ||
@@ -61,6 +65,6 @@ | ||
var batchEmail = false; | ||
if (typeof locals !== 'undefined' && locals instanceof Function) { | ||
if (typeof locals !== 'undefined' && typeof locals === 'function') { | ||
callback = locals; | ||
locals = {}; | ||
} else if (typeof callback !== 'undefined' && callback instanceof Function) { | ||
} else if (typeof callback !== 'undefined' && typeof callback === 'function') { | ||
if (typeof locals === 'undefined' || !locals instanceof Object) { | ||
@@ -160,4 +164,4 @@ locals = {}; | ||
module.exports = function(templateDirectory, done) { | ||
return new EmailTemplate(templateDirectory, done); | ||
module.exports = function(templateDirectory, defaults, done) { | ||
return new EmailTemplate(templateDirectory, defaults, done); | ||
}; |
{ | ||
"name": "email-templates" | ||
, "description": "Node.js module for rendering beautiful emails with ejs templates and email-friendly inline CSS using juice." | ||
, "version": "0.0.1" | ||
, "version": "0.0.2" | ||
, "author": "Nick Baugh <niftylettuce@gmail.com>" | ||
@@ -23,3 +23,4 @@ , "contributors": [ | ||
, "async": "0.1.22" | ||
, "underscore": "1.3.3" | ||
} | ||
} |
# node-email-templates | ||
# node-email-templates <sup>0.0.2</sup> | ||
Node.js module for rendering beautiful emails with [ejs][1] templates and email-friendly inline CSS using [juice][2]. | ||
**NEW**: Added support for custom EJS options such as opening and closing tags (instead of `<%` and `%>`). See documentation below for more information. | ||
## Email Templates | ||
@@ -10,2 +12,19 @@ | ||
## Installation | ||
### Unix/OS X | ||
```bash | ||
npm install email-templates | ||
``` | ||
### Windows | ||
```bash | ||
npm install email-templates-windows | ||
``` | ||
## Quick start | ||
@@ -23,3 +42,14 @@ | ||
# EJS Custom Tags | ||
Want to use different opening and closing tags instead of the EJS's default `<%` and `%>`?. | ||
```js | ||
... | ||
emailTemplates(templatesDir, { open: '{{', close: '}}' }, function(err, template) { | ||
... | ||
``` | ||
**NOTE**: You can also pass <a href="https://github.com/visionmedia/ejs#options" target="_blank">other options from EJS's documentation</a>. | ||
# Usage | ||
@@ -31,6 +61,6 @@ | ||
var path = require('path') | ||
, templateDir = path.join(__dirname, 'templates') | ||
, templatesDir = path.join(__dirname, 'templates') | ||
, emailTemplates = require('email-templates'); | ||
emailTemplates(templatesDir, function(err, templates) { | ||
emailTemplates(templatesDir, function(err, template) { | ||
@@ -37,0 +67,0 @@ // Render a single email with one template |
25671
358
367
4
+ Addedunderscore@1.3.3
+ Addedunderscore@1.3.3(transitive)