-
Notifications
You must be signed in to change notification settings - Fork 145
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(notifications): refactor email formatter
- Loading branch information
1 parent
74e9ef1
commit dbe95fa
Showing
2 changed files
with
53 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use handlebars::Handlebars; | ||
use serde_json::json; | ||
|
||
pub struct EmailFomatter<'a> { | ||
handlebars: Handlebars<'a>, | ||
} | ||
|
||
impl EmailFomatter<'_> { | ||
pub fn new() -> Self { | ||
let mut handlebars = Handlebars::new(); | ||
// add error handling | ||
handlebars | ||
.register_template_file("identification", "./templates/identification.hbs") | ||
.expect("Template should be present"); | ||
handlebars | ||
.register_template_file("base", "./templates/layouts/base.hbs") | ||
.expect("Template should be present"); | ||
handlebars | ||
.register_template_file("styles", "./templates/partials/styles.hbs") | ||
.expect("Template should be present"); | ||
|
||
// add error handling | ||
EmailFomatter { handlebars } | ||
} | ||
|
||
pub fn generic_email_template(&self, subject: &str, body: &str) -> String { | ||
let data = json!({ | ||
"subject": subject, | ||
"body": body, | ||
}); | ||
self.handlebars | ||
.render("identification", &data) | ||
.expect("Template should be present") | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_generic_email_template() { | ||
let email_formatter = EmailFomatter::new(); | ||
let title = "title"; | ||
let body = "body"; | ||
email_formatter.generic_email_template(title, body); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters