From b6fdc5595da925d75e8c097e965a280ae9114a4e Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 4 Jan 2014 18:03:54 -0500 Subject: [PATCH] removed handlebars dependency for emailer, using ANDREWBARS now --- package.json | 1 - public/src/utils.js | 2 +- public/templates/emails/footer.tpl | 10 ----- public/templates/emails/header.tpl | 26 ----------- .../templates/emails/{reset.hbs => reset.tpl} | 4 +- ...eset_plaintext.hbs => reset_plaintext.tpl} | 4 +- .../emails/{welcome.hbs => welcome.tpl} | 8 ++-- ...me_plaintext.hbs => welcome_plaintext.tpl} | 8 ++-- src/emailer.js | 44 +++---------------- 9 files changed, 20 insertions(+), 87 deletions(-) delete mode 100644 public/templates/emails/footer.tpl delete mode 100644 public/templates/emails/header.tpl rename public/templates/emails/{reset.hbs => reset.tpl} (80%) rename public/templates/emails/{reset_plaintext.hbs => reset_plaintext.tpl} (88%) rename public/templates/emails/{welcome.hbs => welcome.tpl} (60%) rename public/templates/emails/{welcome_plaintext.hbs => welcome_plaintext.tpl} (59%) diff --git a/package.json b/package.json index cee921bd0f..e268311415 100644 --- a/package.json +++ b/package.json @@ -45,7 +45,6 @@ "cron": "~1.0.1", "semver": "~2.2.1", "string": "~1.7.0", - "handlebars": "~1.2.1", "xregexp": "~2.0.0" }, "optionalDependencies": { diff --git a/public/src/utils.js b/public/src/utils.js index 01698fe932..c3e0ffbc4a 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -99,7 +99,7 @@ str = str.replace(/^\s+|\s+$/g, ''); // trim str = str.toLowerCase(); - str = XRegExp.replace(str, invalidChars, ''); + str = XRegExp.replace(str, invalidChars, '-'); str = str.replace(/\s+/g, '-') // collapse whitespace and replace by - str = str.replace(/-+/g, '-'); // collapse dashes diff --git a/public/templates/emails/footer.tpl b/public/templates/emails/footer.tpl deleted file mode 100644 index 5fd5205487..0000000000 --- a/public/templates/emails/footer.tpl +++ /dev/null @@ -1,10 +0,0 @@ - - -
-

- This email was sent by NodeBB. If it does not apply to you, please ignore it. -

- \ No newline at end of file diff --git a/public/templates/emails/header.tpl b/public/templates/emails/header.tpl deleted file mode 100644 index 9c3bf39b76..0000000000 --- a/public/templates/emails/header.tpl +++ /dev/null @@ -1,26 +0,0 @@ -
-

- NodeBB -

-
diff --git a/public/templates/emails/reset.hbs b/public/templates/emails/reset.tpl similarity index 80% rename from public/templates/emails/reset.hbs rename to public/templates/emails/reset.tpl index 0974092869..1d00a3db06 100644 --- a/public/templates/emails/reset.hbs +++ b/public/templates/emails/reset.tpl @@ -11,10 +11,10 @@

- {{reset_link}} + {reset_link}

Thanks!
- {{site_title}} + {site_title}

\ No newline at end of file diff --git a/public/templates/emails/reset_plaintext.hbs b/public/templates/emails/reset_plaintext.tpl similarity index 88% rename from public/templates/emails/reset_plaintext.hbs rename to public/templates/emails/reset_plaintext.tpl index 066b496491..2e6bfd3b3b 100644 --- a/public/templates/emails/reset_plaintext.hbs +++ b/public/templates/emails/reset_plaintext.tpl @@ -4,7 +4,7 @@ We received a request to reset your password, possibly because you have forgotte To continue with the password reset, please click on the following link: - {RESET_LINK} + {reset_link} Thanks! -NodeBB \ No newline at end of file +{site_title} \ No newline at end of file diff --git a/public/templates/emails/welcome.hbs b/public/templates/emails/welcome.tpl similarity index 60% rename from public/templates/emails/welcome.hbs rename to public/templates/emails/welcome.tpl index efe1f039fe..8a2944286c 100644 --- a/public/templates/emails/welcome.hbs +++ b/public/templates/emails/welcome.tpl @@ -1,9 +1,9 @@

- Hello {{username}}, + Hello {username},

- Thank you for registering with {{site_title}}! + Thank you for registering with {site_title}!

@@ -11,10 +11,10 @@

- {{confirm_link}} + {confirm_link}

Thanks!
- {{site_title}} + {site_title}

\ No newline at end of file diff --git a/public/templates/emails/welcome_plaintext.hbs b/public/templates/emails/welcome_plaintext.tpl similarity index 59% rename from public/templates/emails/welcome_plaintext.hbs rename to public/templates/emails/welcome_plaintext.tpl index 68e2176bfd..24906a2900 100644 --- a/public/templates/emails/welcome_plaintext.hbs +++ b/public/templates/emails/welcome_plaintext.tpl @@ -1,11 +1,11 @@ -Hello {{username}}, +Hello {username}, -Thank you for registering with {{site_title}}! +Thank you for registering with {site_title}! To fully activate your account, we need to verify that you own the email address you registered with. Please click on the following link: - {{confirm_link}} + {confirm_link} Thanks! -{{site_title}} \ No newline at end of file +{site_title} \ No newline at end of file diff --git a/src/emailer.js b/src/emailer.js index ec8dffc33c..90ee01b481 100644 --- a/src/emailer.js +++ b/src/emailer.js @@ -2,57 +2,27 @@ var User = require('./user'), Plugins = require('./plugins'), Meta = require('./meta'), - Handlebars = require('handlebars'), fs = require('fs'), async = require('async'), path = require('path'), - Emailer = {}, - templates = {}; + Emailer = {}; -var prepareTemplate = function(template, callback) { - if (templates[template] === undefined) { - var templatePath = path.join(__dirname, '../public/templates/emails/' + template + '.hbs'); - - fs.exists(templatePath, function(exists) { - if (exists) { - fs.readFile(templatePath, function(err, fileStream) { - if (!err) { - templates[template] = Handlebars.compile(fileStream.toString()); - } else { - templates[template] = null; - } - - callback(); - }); - } else { - templates[template] = null; - callback(); - } - }); +var render = function(template, params, callback) { + if (templates[template] !== null) { + callback(null, templates[template].parse(params)); } else { - // Template loaded already - callback(); + callback(null, null); } } -var render = function(template, params, callback) { - prepareTemplate(template, function() { - if (templates[template] !== null) { - callback(null, templates[template](params)); - } else { - callback(null, null); - } - }); -} - Emailer.send = function(template, uid, params) { async.parallel({ html: function(next) { - render(template, params, next); + render('emails/' + template, params, next); }, plaintext: function(next) { - render(template + '_plaintext', params, next); + render('emails/' + template + '_plaintext', params, next); } }, function(err, results) { User.getUserField(uid, 'email', function(err, email) {