Skip to content

Commit

Permalink
Preload all templates within template module.
Browse files Browse the repository at this point in the history
  • Loading branch information
xward committed Oct 5, 2023
1 parent 2b92a79 commit baa82d5
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions lib/phoenix_ddos/template/template_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ defmodule PhoenixDDoS.TemplateHelper do

require Logger

@templates [__DIR__, "/*.eex"]
|> Path.join()
|> Path.wildcard()
|> Map.new(fn file_name ->
{Path.basename(file_name, ".eex"), File.read!(file_name)}
end)

def compile(context, template_name) do
Code.put_compiler_option(:ignore_module_conflict, true)

template_name
|> template()
|> EEx.eval_file(Keyword.new(context))
@templates[template_name]
|> EEx.eval_string(Keyword.new(context))
# |> inspect_code()
|> Code.compile_string()

Expand All @@ -22,8 +28,6 @@ defmodule PhoenixDDoS.TemplateHelper do
"[#{Enum.map_join(list, ", ", fn e -> inspect(e) end)}]"
end

defp template(name), do: [__DIR__, "/#{name}.eex"]

# --------------------------------------------------------------
# debug generated code
# --------------------------------------------------------------
Expand Down

0 comments on commit baa82d5

Please sign in to comment.