make emails more efficient
continuous-integration/drone/push Build is passing Details

This commit is contained in:
shibao 2023-04-14 19:02:06 -04:00
parent f00dc50215
commit 1276635a3e
4 changed files with 16 additions and 21 deletions

View File

@ -29,33 +29,28 @@ defmodule Memex.Email do
def generate_email("welcome", user, %{"url" => url}) do
user
|> base_email(dgettext("emails", "confirm your memEx account"))
|> html_email(:confirm_email_html, %{user: user, url: url})
|> text_email(:confirm_email_text, %{user: user, url: url})
|> render_body(:confirm_email, %{user: user, url: url})
end
def generate_email("reset_password", user, %{"url" => url}) do
user
|> base_email(dgettext("emails", "reset your memEx password"))
|> html_email(:reset_password_html, %{user: user, url: url})
|> text_email(:reset_password_text, %{user: user, url: url})
|> render_body(:reset_password, %{user: user, url: url})
end
def generate_email("update_email", user, %{"url" => url}) do
user
|> base_email(dgettext("emails", "update your memEx email"))
|> html_email(:update_email_html, %{user: user, url: url})
|> text_email(:update_email_text, %{user: user, url: url})
|> render_body(:update_email, %{user: user, url: url})
end
defp html_email(email, atom, assigns) do
heex = apply(EmailHTML, atom, [assigns])
html = render_to_string(Layouts, "email_html", "html", email: email, inner_content: heex)
email |> html_body(html)
end
defp render_body(email, template, assigns) do
html_heex = apply(EmailHTML, String.to_existing_atom("#{template}_html"), [assigns])
html = render_to_string(Layouts, "email_html", "html", email: email, inner_content: html_heex)
defp text_email(email, atom, assigns) do
heex = apply(EmailHTML, atom, [assigns])
text = render_to_string(Layouts, "email_text", "text", email: email, inner_content: heex)
email |> text_body(text)
text_heex = apply(EmailHTML, String.to_existing_atom("#{template}_text"), [assigns])
text = render_to_string(Layouts, "email_text", "text", email: email, inner_content: text_heex)
email |> html_body(html) |> text_body(text)
end
end

View File

@ -71,7 +71,7 @@ msgstr ""
msgid "confirm your memEx account"
msgstr ""
#: lib/memex/accounts/email.ex:38
#: lib/memex/accounts/email.ex:37
#, elixir-autogen, elixir-format, fuzzy
msgid "reset your memEx password"
msgstr ""
@ -86,7 +86,7 @@ msgstr ""
msgid "this email was sent from memEx at %{url}"
msgstr ""
#: lib/memex/accounts/email.ex:45
#: lib/memex/accounts/email.ex:43
#, elixir-autogen, elixir-format, fuzzy
msgid "update your memEx email"
msgstr ""

View File

@ -71,7 +71,7 @@ msgstr ""
msgid "confirm your memEx account"
msgstr ""
#: lib/memex/accounts/email.ex:38
#: lib/memex/accounts/email.ex:37
#, elixir-autogen, elixir-format
msgid "reset your memEx password"
msgstr ""
@ -86,7 +86,7 @@ msgstr ""
msgid "this email was sent from memEx at %{url}"
msgstr ""
#: lib/memex/accounts/email.ex:45
#: lib/memex/accounts/email.ex:43
#, elixir-autogen, elixir-format
msgid "update your memEx email"
msgstr ""

View File

@ -72,7 +72,7 @@ msgstr ""
msgid "confirm your memEx account"
msgstr ""
#: lib/memex/accounts/email.ex:38
#: lib/memex/accounts/email.ex:37
#, elixir-autogen, elixir-format, fuzzy
msgid "reset your memEx password"
msgstr ""
@ -87,7 +87,7 @@ msgstr ""
msgid "this email was sent from memEx at %{url}"
msgstr ""
#: lib/memex/accounts/email.ex:45
#: lib/memex/accounts/email.ex:43
#, elixir-autogen, elixir-format, fuzzy
msgid "update your memEx email"
msgstr ""