Created
June 26, 2019 18:45
-
-
Save mrmurphy/892e8f456628928295dd8a2217b13949 to your computer and use it in GitHub Desktop.
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
module Gift = | |
Email_Template.Make({ | |
let name = "gift"; | |
type data = { | |
quantity: int, | |
total: string, | |
year: int, | |
code: string, | |
}; | |
// TODO: Put a real encoder in here | |
let data_encode = Obj.magic; | |
}); |
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
open Pom; | |
module type Cfg = { | |
let name: string; | |
type data; | |
let data_encode: data => Js.Json.t; | |
}; | |
module Make = (Cfg: Cfg) => { | |
let html = Node.Fs.readFileAsUtf8Sync("./" ++ Cfg.name ++ ".html"); | |
let text = Node.Fs.readFileAsUtf8Sync("./" ++ Cfg.name ++ ".txt"); | |
let render = (data: Cfg.data): (string, string) => { | |
let interpolatedHtml = | |
Template.interpolate(html, data->Cfg.data_encode |> Obj.magic); | |
let interpolatedText = | |
Template.interpolate(text, data->Cfg.data_encode |> Obj.magic); | |
(interpolatedHtml, interpolatedText); | |
}; | |
let send = (~subject: string, ~to_: string, ~data: Cfg.data): pom(unit) => { | |
let (html, text) = render(data); | |
SES.sendEmail({SES.receiver: to_, subject, html, text}) | |
->Pom.fromJsPromise; | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment