From 6055829c2a6b9f001b74f6b2a474d99905bd09e6 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Thu, 29 Nov 2012 15:26:58 -0500 Subject: [PATCH 1/2] Updated to ejs 0.8.3, added support for include directive --- lib/main.js | 8 +++++--- package.json | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/main.js b/lib/main.js index 1d1124b..8a7c329 100644 --- a/lib/main.js +++ b/lib/main.js @@ -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); }; diff --git a/package.json b/package.json index 2e6d158..bd3626b 100644 --- a/package.json +++ b/package.json @@ -18,7 +18,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" From 4207a79ea81d643f8e4b7cbce72ee1d082bc0f62 Mon Sep 17 00:00:00 2001 From: Nic Jansma Date: Mon, 3 Dec 2012 12:29:57 -0500 Subject: [PATCH 2/2] Documentation and example update for ejs include directive --- Readme.md | 9 +++++++-- examples/templates/footer/html.ejs | 2 ++ examples/templates/footer/text.ejs | 1 + examples/templates/header/html.ejs | 2 ++ examples/templates/header/text.ejs | 1 + examples/templates/newsletter/html.ejs | 6 ++---- examples/templates/newsletter/text.ejs | 2 ++ examples/templates/pasta-dinner/html.ejs | 6 ++---- examples/templates/pasta-dinner/text.ejs | 2 ++ package.json | 3 ++- 10 files changed, 23 insertions(+), 11 deletions(-) create mode 100644 examples/templates/footer/html.ejs create mode 100644 examples/templates/footer/text.ejs create mode 100644 examples/templates/header/html.ejs create mode 100644 examples/templates/header/text.ejs diff --git a/Readme.md b/Readme.md index 8524604..9ac318a 100644 --- a/Readme.md +++ b/Readme.md @@ -1,8 +1,11 @@ -# node-email-templates 0.0.6 +# node-email-templates 0.0.7 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 * Andrea Baccega +* Nic Jansma (http://nicj.net) ## License diff --git a/examples/templates/footer/html.ejs b/examples/templates/footer/html.ejs new file mode 100644 index 0000000..43d6081 --- /dev/null +++ b/examples/templates/footer/html.ejs @@ -0,0 +1,2 @@ + + diff --git a/examples/templates/footer/text.ejs b/examples/templates/footer/text.ejs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/examples/templates/footer/text.ejs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/templates/header/html.ejs b/examples/templates/header/html.ejs new file mode 100644 index 0000000..255d9b8 --- /dev/null +++ b/examples/templates/header/html.ejs @@ -0,0 +1,2 @@ + + diff --git a/examples/templates/header/text.ejs b/examples/templates/header/text.ejs new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/examples/templates/header/text.ejs @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/examples/templates/newsletter/html.ejs b/examples/templates/newsletter/html.ejs index 0cac3ef..4b9242b 100644 --- a/examples/templates/newsletter/html.ejs +++ b/examples/templates/newsletter/html.ejs @@ -1,5 +1,3 @@ - - +<% include ../header/html %>

Hi there <%= name.first %> <%= name.last %>

- - +<% include ../footer/html %> \ No newline at end of file diff --git a/examples/templates/newsletter/text.ejs b/examples/templates/newsletter/text.ejs index 858ef96..8c6afde 100644 --- a/examples/templates/newsletter/text.ejs +++ b/examples/templates/newsletter/text.ejs @@ -1 +1,3 @@ +<% include ../header/text %> Hi there <%= name.first %> <%= name.last %>. +<% include ../footer/text %> \ No newline at end of file diff --git a/examples/templates/pasta-dinner/html.ejs b/examples/templates/pasta-dinner/html.ejs index df9546c..7cba7df 100644 --- a/examples/templates/pasta-dinner/html.ejs +++ b/examples/templates/pasta-dinner/html.ejs @@ -1,7 +1,5 @@ - - +<% include ../header/html %>

You are invited to our weekly pasta dinner!

This week's pasta is: <%= pasta %>

We hope to see you there!

- - +<% include ../footer/html %> \ No newline at end of file diff --git a/examples/templates/pasta-dinner/text.ejs b/examples/templates/pasta-dinner/text.ejs index e38314b..0771532 100644 --- a/examples/templates/pasta-dinner/text.ejs +++ b/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 %> \ No newline at end of file diff --git a/package.json b/package.json index bd3626b..183b94f 100644 --- a/package.json +++ b/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 " , "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"