onelixir
EEx.eval_file :functions option in eval is deprecated
Hello,
I am studying《Build Your Own Web Framework in Elixir》, In about chapter 7 when I follow the book write code like this:
def render(view_module, conn, file, assigns) do
functions = view_module.__info__(:functions)
contents =
file
|> html_file_path()
|> EEx.eval_file([assigns: assigns], functions: [{view_module, functions}])
Controller.render(conn, :html, contents)
end
I get a warning: warning: :functions option in eval is deprecated, and I checked the official document EEx.html#module-options, which doesn’t have functions options, I also check Elixir version before v1.10.0, also don’t have this option, my question is:
- In
EEx.eval_fileif I want to pass afunctionsoption, what should I do? - Where does the
functionsoption come from at the beginning? seems the document never wrote about this option, so how does the author of this book know this?
Most Liked
stefanluptak
First of all, I was dealing with a same/similar problem few weeks back, so your searching ability is not weak, I just already invested some time in it previously. ![]()
This :functions option is just a list of functions that will be automatically imported thus available to be used in your view without the full module path needed. For example, if you would provide something like functions: [{MyApp.MyModule, [hello: 0]}], (0 being the arity (number of args) of the foo function) then you can use <%= foo() %> in your template. Without the :functions option, you just have to do <%= MyApp.MyModule.foo() %>, that is all.
Hope this helps a bit.
stefanluptak
Sorry, I have no knowledge of that and have no time to research it. Maybe someone else could help with that. ![]()







