Handle expressions with do blocks that aren't if/unless/for
This commit is contained in:
parent
3c787297e5
commit
1f599f5f6d
3 changed files with 25 additions and 3 deletions
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## Master
|
## Master
|
||||||
|
|
||||||
|
## 0.6.0-alpha.3
|
||||||
|
|
||||||
|
- Compile functions/macros that take blocks that are not if/unless/for
|
||||||
|
|
||||||
## 0.6.0-alpha.2
|
## 0.6.0-alpha.2
|
||||||
|
|
||||||
### Component API
|
### Component API
|
||||||
|
|
|
@ -393,9 +393,16 @@ defmodule Temple.Parser do
|
||||||
end
|
end
|
||||||
},
|
},
|
||||||
%{
|
%{
|
||||||
name: :for_if_unless,
|
name: :do_expressions,
|
||||||
applicable?: fn {name, _, _} ->
|
applicable?: fn
|
||||||
name in [:for, :if, :unless]
|
{_, _, [_, [{:do, _} | _]]} ->
|
||||||
|
true
|
||||||
|
|
||||||
|
{_, _, [[{:do, _} | _]]} ->
|
||||||
|
true
|
||||||
|
|
||||||
|
{_, _, _} ->
|
||||||
|
false
|
||||||
end,
|
end,
|
||||||
parse: fn {name, meta, args}, buffer ->
|
parse: fn {name, meta, args}, buffer ->
|
||||||
import Temple.Parser.Private
|
import Temple.Parser.Private
|
||||||
|
|
|
@ -342,4 +342,15 @@ defmodule TempleTest do
|
||||||
|
|
||||||
assert result == ~s{<div class="<%= [class: "boom"][:class] %>">yay!</div>}
|
assert result == ~s{<div class="<%= [class: "boom"][:class] %>">yay!</div>}
|
||||||
end
|
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
|
end
|
||||||
|
|
Reference in a new issue