Elixir : 有没有强制重新编译的例程?

The*_*uad 0 elixir

我正在使用 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()
...
Run Code Online (Sandbox Code Playgroud)

由于它在 Blackbox.ReportHandler(即已更改)时编译 EEx 文件,因此我需要在控制台中手动重新加载模块,或者更改 ReportHandler 模块上的某些内容,以便这次使用最新的 EEx 文件再次编译.

有没有办法将 ReportHandler 的编译链接到另一个文件的修改?

Dog*_*ert 8

@external_resource模块属性是为正是这一点:

为当前模块指定一个外部资源。

有时,模块会嵌入来自外部文件的信息。该属性允许模块注释使用了哪些外部资源。

Mix 等工具可能会使用此信息来确保在任何外部资源发生更改时重新编译模块。

来源

因此,如果该文件发生更改,您只需添加此模块属性即可混合重新编译模块:

@external_resource "web/templates/mail.html.eex"
Run Code Online (Sandbox Code Playgroud)