Skip to content

Instantly share code, notes, and snippets.

@mrmurphy
Created June 26, 2019 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrmurphy/892e8f456628928295dd8a2217b13949 to your computer and use it in GitHub Desktop.
Save mrmurphy/892e8f456628928295dd8a2217b13949 to your computer and use it in GitHub Desktop.
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;
});
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