From 1f599f5f6dd9ac0bb7c71619dabd432a0a942289 Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Wed, 15 Jul 2020 23:23:12 -0400 Subject: [PATCH] Handle expressions with do blocks that aren't if/unless/for --- CHANGELOG.md | 4 ++++ lib/temple/parser.ex | 13 ++++++++++--- test/temple_test.exs | 11 +++++++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c3832c1..18c4f28 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/temple/parser.ex b/lib/temple/parser.ex index babaf4d..2b40f1f 100644 --- a/lib/temple/parser.ex +++ b/lib/temple/parser.ex @@ -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 diff --git a/test/temple_test.exs b/test/temple_test.exs index 3544b32..5866dd1 100644 --- a/test/temple_test.exs +++ b/test/temple_test.exs @@ -342,4 +342,15 @@ defmodule TempleTest do assert result == ~s{
">yay!
} 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 %>
<% end %>} + end end