Handle expressions with do blocks that aren't if/unless/for

This commit is contained in:
Mitchell Hanberg 2020-07-15 23:23:12 -04:00
parent 3c787297e5
commit 1f599f5f6d
3 changed files with 25 additions and 3 deletions

View file

@ -2,6 +2,10 @@
## Master
## 0.6.0-alpha.3
- Compile functions/macros that take blocks that are not if/unless/for
## 0.6.0-alpha.2
### Component API

View file

@ -393,9 +393,16 @@ defmodule Temple.Parser do
end
},
%{
name: :for_if_unless,
applicable?: fn {name, _, _} ->
name in [:for, :if, :unless]
name: :do_expressions,
applicable?: fn
{_, _, [_, [{:do, _} | _]]} ->
true
{_, _, [[{:do, _} | _]]} ->
true
{_, _, _} ->
false
end,
parse: fn {name, meta, args}, buffer ->
import Temple.Parser.Private

View file

@ -342,4 +342,15 @@ defmodule TempleTest do
assert result == ~s{<div class="<%= [class: "boom"][:class] %>">yay!</div>}
end
test "normal functions with blocks should be treated like if expressions" do
result =
temple do
leenk to: "/route", class: "foo" do
div class: "hi"
end
end
assert result == ~s{<%= leenk(to: "/route", class: "foo") do %><div class="hi"></div><% end %>}
end
end