Skip to content

Commit

Permalink
Merge pull request #19 from nicjansma/master
Browse files Browse the repository at this point in the history
ejs support for include directive
  • Loading branch information
niftylettuce committed Dec 6, 2012
2 parents 0114f48 + 4207a79 commit a011802
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 15 deletions.
9 changes: 7 additions & 2 deletions Readme.md
@@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions examples/templates/footer/html.ejs
@@ -0,0 +1,2 @@
</body>
</html>
1 change: 1 addition & 0 deletions examples/templates/footer/text.ejs
@@ -0,0 +1 @@

2 changes: 2 additions & 0 deletions examples/templates/header/html.ejs
@@ -0,0 +1,2 @@
<html>
<body>
1 change: 1 addition & 0 deletions examples/templates/header/text.ejs
@@ -0,0 +1 @@

6 changes: 2 additions & 4 deletions examples/templates/newsletter/html.ejs
@@ -1,5 +1,3 @@
<html>
<body>
<% include ../header/html %>
<h1>Hi there <%= name.first %> <%= name.last %></h1>
</body>
</html>
<% include ../footer/html %>
2 changes: 2 additions & 0 deletions examples/templates/newsletter/text.ejs
@@ -1 +1,3 @@
<% include ../header/text %>
Hi there <%= name.first %> <%= name.last %>.
<% include ../footer/text %>
6 changes: 2 additions & 4 deletions examples/templates/pasta-dinner/html.ejs
@@ -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 %>
2 changes: 2 additions & 0 deletions examples/templates/pasta-dinner/text.ejs
@@ -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 %>
8 changes: 5 additions & 3 deletions lib/main.js
Expand Up @@ -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') {
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
};
Expand Down
5 changes: 3 additions & 2 deletions package.json
@@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit a011802

Please sign in to comment.