Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.5.0: Is API for EEx.Engine changed since 1.4? #6391

Closed
grych opened this issue Jul 27, 2017 · 2 comments
Closed

1.5.0: Is API for EEx.Engine changed since 1.4? #6391

grych opened this issue Jul 27, 2017 · 2 comments

Comments

@grych
Copy link
Contributor

grych commented Jul 27, 2017

Is it an expected behaviour of EEx.Engine that it includes an init value in the middle expressions? Before 1.5.0, init/1 value were added only at the beginning of the buffer, in the middle it was always empty string.

Observe the difference between 1.4.5 and 1.5.0 below:

Test engine

defmodule ExtendedEngine do
  use EEx.Engine

  def init(_) do
    "init:"
  end

  def handle_body(quoted) do
    quote do 
      unquote(quoted) <> ":end"
    end
  end
end

test.eex:

<%= for x <- ["A", "B"] do %><%= x %><% end %>

1.4.5:

Interactive Elixir (1.4.5) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> EEx.eval_file "text.eex", [], engine: ExtendedEngine
"init:AB\n:end"

1.5.0:

Interactive Elixir (1.5.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> EEx.eval_file "text.eex", [], engine: ExtendedEngine
"init:init:Ainit:B\n:end"

If it is expected, shouldn't be handle_body/1 called at the end of each middle expression? That would be consistent with init/1.

But I hope it is a bug, because previous behaviour was more intuitive.

Environment

  • Elixir & Erlang versions (elixir --version): Erlang/OTP 20, Elixir 1.4.5 and 1.5.0
  • Operating system: macOS Sierra

The change was introduced here: b620445

josevalim pushed a commit that referenced this issue Jul 29, 2017
Elixir v1.5.0 attempted to repurpose the value of init
to use throughout the engine but such was a breaking change.

To address this problem, we added handle_begin and
handle_end which were designed exactly to handle inner
buffers.

This comes with the benefit that EEx.Engine can now have
any data structure as state and no longer only quoted
expressions.

Closes #6391.
@josevalim josevalim reopened this Jul 29, 2017
@josevalim
Copy link
Member

Thank you for the report. @grych can you please give branch v1.5 (or master) a try? I want to make sure it will work as you expect.

@grych
Copy link
Contributor Author

grych commented Jul 30, 2017

Hi @josevalim,
Perfect!

Interactive Elixir (1.5.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>  EEx.eval_file "text.eex", [], engine: ExtendedEngine
"init:AB\n:end"

And it fixed my issue grych/drab#31. Thanks!

@grych grych closed this as completed Jul 30, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants