EEx.function_from_file
You're seeing just the macro
function_from_file
, go back to EEx module for more information.
Link to this macro
function_from_file(kind, name, file, args \\ [], options \\ [])
View Source (macro)Generates a function definition from the file contents.
The first argument is the kind of the generated function (:def
or :defp
).
The name
argument is the name that the generated function will have.
file
is the path to the EEx template file. args
is a list of arguments
that the generated function will accept. They will be available inside the EEx
template. options
is a list of EEx compilation options (see the module documentation).
This function is useful in case you have templates but you want to precompile inside a module for speed.
Examples
# sample.eex
<%= a + b %>
# sample.ex
defmodule Sample do
require EEx
EEx.function_from_file(:def, :sample, "sample.eex", [:a, :b])
end
# iex
Sample.sample(1, 2)
#=> "3"