Just like Phoenix.View, this PR compiles the EEx templates ahead of time during Elixir compilation.
Pros/Cons
The main purpose of making this change is:
To allow depends_on?(app, :mix, :foo) instead of depends_on?.(app, :mix, :foo) (Note the . in the last example)
To allow users to call any function in the Blueprint (or imported into it) in any template – calling fun_name(app) rather than having to call MyApp.Uniform.Blueprint.fun_name(app).
The tradeoff is that the implementation is a bit more complicated.
Implementation Details
It adds them as functions in Blueprint just like Phoenix.View places the templates in the View module.
Specifically, it creates functions whose name is the path of the template.
So if your templates directory is lib/my_app/uniform/templates and you have a template config/runtime.exs.eex, it will compile like this under the hood:
defmodule MyApp.Uniform.Blueprint do
def :"config/runtime.exs"(app) do
# function that returns rendered template from `lib/my_app/uniform/templates/config/runtime.exs.eex`
end
end
(Of course, that pseudocode syntax won't compile because you can't create function names like that without macros.)
Just like Phoenix.View, this PR compiles the EEx templates ahead of time during Elixir compilation.
Pros/Cons
The main purpose of making this change is:
depends_on?(app, :mix, :foo)
instead ofdepends_on?.(app, :mix, :foo)
(Note the.
in the last example)Blueprint
(orimport
ed into it) in any template – callingfun_name(app)
rather than having to callMyApp.Uniform.Blueprint.fun_name(app)
.The tradeoff is that the implementation is a bit more complicated.
Implementation Details
It adds them as functions in
Blueprint
just like Phoenix.View places the templates in theView
module.Specifically, it creates functions whose name is the path of the template.
So if your templates directory is
lib/my_app/uniform/templates
and you have a templateconfig/runtime.exs.eex
, it will compile like this under the hood:(Of course, that pseudocode syntax won't compile because you can't create function names like that without macros.)