Packages

Fermo project generator. Provides a `mix fermo.new` task to bootstrap a new Fermo project with the standard dependencies for use with DatoCMS.

Current section

Files

Jump to
fermo_new lib fermo new generator.ex
Raw

lib/fermo/new/generator.ex

defmodule Fermo.New.Generator do
defmacro __using__(_env) do
quote do
import Mix.Generator
@before_compile unquote(__MODULE__)
end
end
defmacro __before_compile__(env) do
root = Path.expand("../../../templates/new", __DIR__)
templates = Module.get_attribute(env.module, :templates)
templates_ast =
for source <- templates do
path = Path.join(root, source)
compiled = EEx.compile_file(path)
quote do
@external_resource unquote(path)
@file unquote(path)
def render(unquote(source), var!(assigns))
when is_list(var!(assigns)),
do: unquote(compiled)
end
end
quote do
unquote(templates_ast)
end
end
end