Permalink
Browse files

Merge pull request #19 from nicjansma/master

ejs support for include directive
  • Loading branch information...
2 parents 0114f48 + 4207a79 commit a011802a91406141a5029578b7bce77836164ce0 @niftylettuce niftylettuce committed Dec 6, 2012
View
@@ -1,8 +1,11 @@
-# node-email-templates <sup>0.0.6</sup>
+# node-email-templates <sup>0.0.7</sup>
Node.js module for rendering beautiful emails with [ejs][1] templates and email-friendly inline CSS using [juice][2].
+**v0.0.7**:
+* Added support for ejs's `include` directive thanks to @nicjansma
+
**v0.0.6**:
* Fixed batch problem (`...has no method slice`) thanks to @vekexasia
@@ -52,7 +55,8 @@ npm install email-templates-windows
* `html.ejs` - html + [ejs][1] version of your email template (**required**)
* `text.ejs` - text + [ejs][1] version of your email template (**optional**)
* `style.css` - stylesheet for the template, which will render `html.ejs` with inline CSS (**optional**)
-5. Utilize one of the examples below for your respective email module and start sending beautiful emails!
+5. You may use the `include` directive from ejs (for example, to include a common header or footer). See the `/examples` folder for details.
+6. Utilize one of the examples below for your respective email module and start sending beautiful emails!
# EJS Custom Tags
@@ -366,6 +370,7 @@ emailTemplates(templatesDir, function(err, template) {
* Nick Baugh <niftylettuce@gmail.com>
* Andrea Baccega <vekexasia@gmail.com>
+* Nic Jansma (http://nicj.net)
## License
@@ -0,0 +1,2 @@
+ </body>
+</html>
@@ -0,0 +1 @@
+
@@ -0,0 +1,2 @@
+<html>
+ <body>
@@ -0,0 +1 @@
+
@@ -1,5 +1,3 @@
-<html>
- <body>
+<% include ../header/html %>
<h1>Hi there <%= name.first %> <%= name.last %></h1>
- </body>
-</html>
+<% include ../footer/html %>
@@ -1 +1,3 @@
+<% include ../header/text %>
Hi there <%= name.first %> <%= name.last %>.
+<% include ../footer/text %>
@@ -1,7 +1,5 @@
-<html>
- <body>
+<% include ../header/html %>
<h1>You are invited to our weekly pasta dinner!</h1>
<h2>This week's pasta is: <%= pasta %></h2>
<h3>We hope to see you there!</h3>
- </body>
-</body>
+<% include ../footer/html %>
@@ -1,5 +1,7 @@
+<% include ../header/text %>
You are invited to join our weekly pasta dinner!
This week's pasta is: <%= pasta %>
We hope to see you there!
+<% include ../footer/text %>
View
@@ -31,7 +31,7 @@ var EmailTemplate = function(templateDirectory, defaults, done) {
this.text = '';
this.stylesheet = '';
this.bufferType = ''
- this.render = function(locals, html, text, stylesheet, bufferType, callback) {
+ this.render = function(locals, templatePath, html, text, stylesheet, bufferType, callback) {
// Check if `bufferType` is a function (callback), or string
var isBuffer = false
if (typeof bufferType === 'function') {
@@ -59,7 +59,9 @@ var EmailTemplate = function(templateDirectory, defaults, done) {
if (!text) text = that.text
if (!stylesheet) stylesheet = that.stylesheet
locals = _.defaults(locals, (typeof defaults === 'object') ? defaults : {});
+ locals.filename = path.join(templatePath, 'html.ejs');
html = ejs.render(html, locals);
+ locals.filename = path.join(templatePath, 'text.ejs');
text = (text) ? ejs.render(text, locals) : '';
if (stylesheet) html = juice(html, stylesheet);
@@ -128,9 +130,9 @@ var EmailTemplate = function(templateDirectory, defaults, done) {
return callback(null, that.render);
}
if (isBuffer) {
- that.render(locals, null, null, null, bufferType, callback)
+ that.render(locals, templatePath, null, null, null, bufferType, callback)
} else {
- that.render(locals, null, null, null, callback)
+ that.render(locals, templatePath, null, null, null, callback)
}
//that.render(locals, callback);
};
View
@@ -1,11 +1,12 @@
{
"name": "email-templates"
, "description": "Node.js module for rendering beautiful emails with ejs templates and email-friendly inline CSS using juice."
- , "version": "0.0.6"
+ , "version": "0.0.7"
, "author": "Nick Baugh <niftylettuce@gmail.com>"
, "contributors": [
{ "name": "Nick Baugh", "email": "niftylettuce@gmail.com" }
, { "name": "Andrea Baccega", "email": "vekexasia@gmail.com" }
+ , { "name": "Nic Jansma", "web": "http://nicj.net" }
]
, "keywords": [ "node-email-templates", "ejs", "email", "templates", "email-templates", "juice", "inline", "css" ]
, "homepage": "https://github.com/niftylettuce/node-email-templates"
@@ -18,7 +19,7 @@
}
, "main": "lib/main.js"
, "dependencies": {
- "ejs": "0.7.1"
+ "ejs": "0.8.3"
, "juice": "https://github.com/niftylettuce/juice/tarball/master"
, "async": "0.1.22"
, "underscore": "1.3.3"

0 comments on commit a011802

Please sign in to comment.