我正在使用EEx进行邮件模板化......
我已将其集成到我的模块中,如下所示:
defmodule Blackbox.ReportHandler do
use GenServer
import Swoosh.Email
@email EEx.compile_file("web/templates/mail.html.eex")
def init([actions: actions]) do
{:ok, %{actions: actions, name: "none_yet", report: []}}
end
[...]
def handle_info({:test_step, :done, true}, s) do
email = @email |> Code.eval_quoted([name: s.name, report: s.report]) |> elem(0)
sent = new()
...
由于它在Blackbox.ReportHandler(即已经更改)时编译EEx文件,我需要在控制台中手动重新加载模块,或者在ReportHandler模块上更改一些内容,以便这次再次编译,最多可以日期EEx文件。
有没有办法将ReportHandler的编译链接到另一个文件的修改?
答案 0 :(得分:4)
@external_resource
模块属性就是这样的:
指定当前模块的外部资源。
有时,模块会嵌入外部文件中的信息。这个 attribute允许模块注释哪些外部资源具有 已被使用。
像Mix这样的工具可以使用此信息来确保模块 在任何外部资源发生变化的情况下重新编译。
因此,您需要添加此模块属性以使mix在文件更改时重新编译模块:
@external_resource "web/templates/mail.html.eex"