Skip to content

Node.js based forum software built for the modern web

removed handlebars dependency for emailer, using ANDREWBARS now

Julian Lamb6fdc5595da9
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 @@
-
- </div>
- <hr />
- <p style="
- font-size: 10px;
- padding: 6px 12px;
- ">
- This email was sent by NodeBB. If it does not apply to you, please ignore it.
- </p>
-</div>
\ 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 @@
-<div style="
- width: 640px;
- border: 1px solid #666;
- margin: 0 auto;
- font-family: 'Helvetica Neue',Helvetica,Arial,sans-serif;
- background: #f6f6f6;
-">
- <h1 style="
- background-color: #1b1b1b;
- margin: 0;
- padding: 6px 12px;
- font-size: 20px;
- background-image: -moz-linear-gradient(top,#222,#111);
- background-image: -webkit-gradient(linear,0 0,0 100%,from(#222),to(#111));
- background-image: -webkit-linear-gradient(top,#222,#111);
- background-image: -o-linear-gradient(top,#222,#111);
- background-image: linear-gradient(to bottom,#222,#111);
- color: #777;
- font-weight: normal;
- ">
- NodeBB
- </h1>
- <div style="
- padding: 20px;
- color: #333;
- ">
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 @@
</p>
<blockquote>
- {{reset_link}}
+ {reset_link}
</blockquote>
<p>
Thanks!<br />
- <strong>{{site_title}}</strong>
+ <strong>{site_title}</strong>
</p>
\ 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 @@
<p>
- Hello {{username}},
+ Hello {username},
</p>
<p>
- <strong>Thank you for registering with {{site_title}}!</strong>
+ <strong>Thank you for registering with {site_title}!</strong>
</p>
<p>
@@ -11,10 +11,10 @@
</p>
<blockquote>
- {{confirm_link}}
+ {confirm_link}
</blockquote>
<p>
Thanks!<br />
- <strong>{{site_title}}</strong>
+ <strong>{site_title}</strong>
</p>
\ 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) {