diff --git a/demo-template-partials.js b/demo-template-partials.js new file mode 100644 index 0000000..abf489f --- /dev/null +++ b/demo-template-partials.js @@ -0,0 +1,34 @@ +var email = require("./lib/node_mailer"); + +email.send({ + host : "localhost", // smtp server hostname + port : "25", // smtp server port + domain : "localhost", // domain used by client to identify itself to server + to : "marak.squires@gmail.com", + from : "obama@whitehouse.gov", + subject : "node_mailer test email", + template : "./templates/sample-partials.txt", // path to template name + data : { + "username": "Billy Bob", + "color": function(){ + var arr = ["purple", "red", "green", "yellow"]; + return arr[Math.floor(Math.random()*3)]; + }, + "animal": "monkey", + "adverb": "quickly", + "noun": "hot lava", + "cats": { + "plural_noun": "cats", + "verb": "rule", + "proper_noun": "Internet" + } + }, + partials: {"cats": "{{plural_noun}} {{verb}} the {{proper_noun}}"}, + authentication : "login", // auth login is supported; anything else is no auth + username : undefined, // username + password : undefined, // password + debug: true // log level per message + }, + function(err, result){ + if(err){ console.log(err); } + }); diff --git a/lib/node_mailer.js b/lib/node_mailer.js index e1ccb43..ed09aa8 100644 --- a/lib/node_mailer.js +++ b/lib/node_mailer.js @@ -119,7 +119,7 @@ exports.send = function node_mail(message, callback) { // If the template is already fully loaded in the cahe if (_templateCache[message.template].loaded) { // Use the cached template and send the email - message.html = mustache.to_html(_templateCache[message.template].template, message.data); + message.html = mustache.to_html(_templateCache[message.template].template, message.data, message.partials); dispatchMail(message, server, callback); } else { @@ -146,7 +146,7 @@ exports.send = function node_mail(message, callback) { // "Drain" the queue _templateCache[message.template].queue.push(message); _templateCache[message.template].queue.forEach(function(msg, i){ - msg.html = mustache.to_html(_templateCache[message.template].template, msg.data); + msg.html = mustache.to_html(_templateCache[message.template].template, msg.data, message.partials); dispatchMail(msg, server, callback); }); diff --git a/templates/sample-partials.txt b/templates/sample-partials.txt new file mode 100644 index 0000000..fb05490 --- /dev/null +++ b/templates/sample-partials.txt @@ -0,0 +1,9 @@ +Hello {{username}}, + +This is a sample template of the node mailer. + +It uses mustache templating to do basic search and replaces. + +The {{color}} {{animal}} {{adverb}} ran over the {{noun}}. + +Also, {{>cats}}. \ No newline at end of file