defmodule Mix.Tasks.Compile.Gin.Templates do use Mix.Task defstruct [:source] ####### # API # ####### def run(_) do Enum.map(Mix.Project.config[:"gin.templates"], &compile/1) end ########### # Private # ########### defp compile({source,data}) do target = String.trim_trailing(source, ".eex") head = head(source) body = EEx.eval_file(source, data) content = head <> body File.write(target, content) end defp head(source) do """ *Note: Do not edit this file; it's autogenerated. Instead, edit [#{source}](#{source}).* """ end end