onelixir

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:

  1. In EEx.eval_file if I want to pass a functions option, what should I do?
  2. Where does the functions option 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

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. :slight_smile:

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

stefanluptak

Sorry, I have no knowledge of that and have no time to research it. Maybe someone else could help with that. :pray:

Where Next?

Popular in Questions Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
tduccuong
Hi, is there any work on GUI with Elixir, that is similar to Electron/Javascript? My idea is to bundle Phoenix and BEAM into a single se...
New
logicmason
Hi there, I'm working through my first release with elixir/phoenix. I've built a release with distillery and found that it crashes when I...
New
dokuzbir
Hello, I am trying to convert my lists to string without losing brackets.For start i have 3 map. They look like these buyer = %{ id: ...
New
polypush135
As many of you may have realized by now (sorry for all the posts here) I’ve been working on a db problem where I’m trying to aggregate a ...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
LegitStack
I’m trying to make a websocket server in Phoenix or raw Elixir. I heard about gun, I think I could use cowboy, but since I’m not that sma...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
shahryarjb
Hello, I get Persian date from my client and convert it to normal calendar like this: def jalali_string_to_miladi_english_number(persi...
New
sorentwo
Hello! tl;dr Announcing Oban, an Ecto based job processing library with a focus on reliability and historical observability. After spen...
977 41022 311
New
senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
William
I would like to know that is there any online source for learning Phoenix Framework for building E-Commerce Store? Any advantage on build...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
AstonJ
We’ve put together this wiki for Phoenix LiveView - please feel free to add any info you feel is worth including. What is Phoenix LiveV...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
magnetic
Hey :wave:t3: Elixir community, I’ve been learning Elixir, and working on some side projects. My editor of choice is VSCode, and althoug...
New

We're in Beta

About us Mission Statement