Skip to content

Commit fb89d55

Browse files
author
José Valim
committed
Support middle expressions on trim mode, closes #5752
Signed-off-by: José Valim <[email protected]>
1 parent 8618d8e commit fb89d55

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

lib/eex/lib/eex/compiler.ex

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,9 @@ defmodule EEx.Compiler do
9090
{contents, start, list}
9191
end
9292
end
93-
93+
defp look_ahead_text([{:middle_expr, line, _, chars} | t], _start, contents) do
94+
{contents ++ chars, line, t}
95+
end
9496
defp look_ahead_text(t, start, contents) do
9597
{contents, start, t}
9698
end

lib/eex/lib/eex/tokenizer.ex

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,6 @@ defmodule EEx.Tokenizer do
181181
# If trim mode is enabled and the token is on a line with
182182
# only itself and whitespace, trim the whitespace around it,
183183
# including the line break following it if there is one.
184-
185184
defp trim_if_needed(rest, line, opts, buffer, acc) do
186185
original = {rest, line, buffer}
187186
if opts[:trim] do

lib/eex/test/eex_test.exs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,19 @@ foo
331331
assert_eval expected, string, [], trim: true
332332
end
333333

334+
test "trim mode with middle expression" do
335+
string = """
336+
<%= cond do %>
337+
<% false -> %>
338+
this
339+
<% true -> %>
340+
that
341+
<% end %>
342+
"""
343+
expected = " that\n"
344+
assert_eval expected, string, [], trim: true
345+
end
346+
334347
test "evaluates the source from a given file" do
335348
filename = Path.join(__DIR__, "fixtures/eex_template.eex")
336349
result = EEx.eval_file(filename)

0 commit comments

Comments
 (0)