onelixir

onelixir

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?

Showing Posts 1 to 10

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.

onelixir

onelixir OP

I followed your suggestion, find out the source code here: do_eval, after that I cannot go further, It is not easy for me. :smiling_face_with_tear: Also, nothing mentioned cannot use :functions as an option.

onelixir

onelixir OP

Thank you so much! I will try to follow your step to see how to do without using :functions。

stefanluptak

stefanluptak

This option was there in Elixir 1.12.3 for the last time (see Code — Elixir v1.12.3)

It was then deprecated in the version 1.13.0 (see elixir/CHANGELOG.md at v1.13 · elixir-lang/elixir · GitHub)

onelixir

onelixir OP

Thank you so much! my searching ability is so weak… :sweat_smile:

The changelog just say:

  • [Code] Environment options in Code.eval_quoted/3 and Code.eval_string/3, such as :aliases and :tracers, have been deprecated in favor of passing an environment

I still don’t know what to do, if I cannot solve it, I have to just mark it and move on, until one day I can. :smiling_face_with_tear:

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.

onelixir

onelixir OP

Thank you for your explanation again, :sweat_smile:

I understand you now, but I still don’t know what the alternative way to do if the official doesn’t suggest we pass functions option? How to do that with env? I cannot just do EEx.eval_file("xxx.html.eex", [assigns: assigns], __ENV__). :smiling_face_with_tear:

stefanluptak

stefanluptak

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

LostKobrakai

LostKobrakai

That expects there to be an alternative. Maybe there is none and you’re expected to instead update the templates to not depend on the deprecated functionality.

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
water
I’m aware of 2 such projects, are there others? git: GitHub - team-alembic/realworld: A fullstack Phoenix LiveView application with back...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
peck
Hi everyone. My team and I have been working on a fairly modest app based around video streaming and chat, but we’ve landed a customer t...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
csmr
Hi all, I’m new here and would like to hear peoples views on my Elixir/Phoenix based game-engine! :smiley: Mutonex gamedesign was finish...
New
perzanko
Do we have maintainer of absinthe-graphql/dataloader here? We have a PR that we’d like to merge to the library. Relatively small additive...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
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
webofbits
With AI doing more of the implementation work, I’ve been wondering how much coding I should deliberately keep doing myself. My main conc...
#ai
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews