Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/1027
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Sep 28, 2024
1 parent 2a4c108 commit ae64d76
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lib/render.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ defmodule Bonfire.Mailer.Render do

email
|> Bonfire.Mailer.html_body(render_templated("mjml", mod, assigns, template, layout, opts))
|> Bonfire.Mailer.text_body(render_templated("text", template, mod, assigns, opts))
|> Bonfire.Mailer.text_body(render_templated("text", mod, assigns, template, layout, opts))
end

# TODO: put the following functions somewhere else?
Expand All @@ -35,6 +35,7 @@ defmodule Bonfire.Mailer.Render do
|> to_binary()
|> mjml_to_html()
end
|> debug()
end

def render_templated(format, mod, assigns, template, layout, opts) do
Expand All @@ -46,6 +47,7 @@ defmodule Bonfire.Mailer.Render do
maybe_with_layout(format, binary, assigns, layout)
|> to_binary()
end
|> debug()
end

def maybe_with_layout(_format, inner_content, assigns, nil), do: inner_content
Expand All @@ -67,12 +69,19 @@ defmodule Bonfire.Mailer.Render do
# Phoenix.Template.render_to_string(mod, "#{template}_#{format}", format, assigns)
# end
def render_to_string(mod, template, format, assigns) do
case Types.maybe_to_atom!("#{template}_#{format}") do
template_fn = "#{template}_#{format}"

case Types.maybe_to_atom!(template_fn) do
nil ->
warn(
template_fn,
"No such template known (there should be a function defined with that name in module `#{mod}`)"
)

nil

template ->
Utils.maybe_apply(mod, template, [assigns], fallback_return: "")
template_fn ->
Utils.maybe_apply(mod, template_fn, [assigns], fallback_return: "")
end
end

Expand Down

0 comments on commit ae64d76

Please sign in to comment.