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?

First Post! Switch mode

LostKobrakai

LostKobrakai

One can always look at the code, not just the documentation. Though it it hadn’t been documented it likely wasn’t supposed to be used.

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:

Last Post!

onelixir

onelixir

Thank you for your answer, I will try to refactor the code not to do this.

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement