Fix phx_link, phx_button, submit, phx_label markup (#20)

The tests for phx_link were not testing the correct behavior, which is how this slipped by.
This commit is contained in:
Shritesh 2019-08-27 20:51:10 -05:00 committed by Mitchell Hanberg
parent 26bd319420
commit dbb26a6d58
3 changed files with 16 additions and 40 deletions

View file

@ -117,12 +117,7 @@ defmodule Temple.Form do
"""
defmacro submit(do: block) do
quote location: :keep do
{:safe, content} =
temple do
unquote(block)
end
{:safe, input} = Phoenix.HTML.Form.submit(do: content)
{:safe, input} = Phoenix.HTML.Form.submit(do: temple(do: unquote(block)))
Utils.put_buffer(var!(buff, Temple.Tags), input)
end
@ -141,12 +136,7 @@ defmodule Temple.Form do
"""
defmacro submit(opts, do: block) do
quote location: :keep do
{:safe, content} =
temple do
unquote(block)
end
{:safe, input} = Phoenix.HTML.Form.submit(unquote(opts), do: content)
{:safe, input} = Phoenix.HTML.Form.submit(unquote(opts), do: temple(do: unquote(block)))
Utils.put_buffer(var!(buff, Temple.Tags), input)
end
@ -176,12 +166,8 @@ defmodule Temple.Form do
"""
defmacro phx_label(form, field, do: block) do
quote location: :keep do
{:safe, content} =
temple do
unquote(block)
end
{:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field]), do: content)
{:safe, input} =
Phoenix.HTML.Form.label(unquote_splicing([form, field]), do: temple(do: unquote(block)))
Utils.put_buffer(var!(buff, Temple.Tags), input)
end
@ -200,12 +186,10 @@ defmodule Temple.Form do
"""
defmacro phx_label(form, field, opts, do: block) do
quote location: :keep do
{:safe, content} =
temple do
unquote(block)
end
{:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field, opts]), do: content)
{:safe, input} =
Phoenix.HTML.Form.label(unquote_splicing([form, field, opts]),
do: temple(do: unquote(block))
)
Utils.put_buffer(var!(buff, Temple.Tags), input)
end

View file

@ -11,12 +11,9 @@ defmodule Temple.Link do
"""
defmacro phx_link(opts, do: block) do
quote location: :keep do
{:safe, content} =
temple do
unquote(block)
end
{:safe, link} = HTML.Link.link(content, unquote(opts))
{:safe, link} =
temple(do: unquote(block))
|> HTML.Link.link(unquote(opts))
Utils.put_buffer(var!(buff, Temple.Tags), link)
end
@ -35,12 +32,7 @@ defmodule Temple.Link do
"""
defmacro phx_button(opts, do: block) do
quote location: :keep do
{:safe, content} =
temple do
unquote(block)
end
{:safe, link} = HTML.Link.button(content, unquote(opts))
{:safe, link} = HTML.Link.button(temple(do: unquote(block)), unquote(opts))
Utils.put_buffer(var!(buff, Temple.Tags), link)
end

View file

@ -40,9 +40,9 @@ defmodule Temple.LinkTest do
assert String.starts_with?(actual, ~s{<a})
assert actual =~ ~s{href="/hello"}
assert actual =~ ~s{&lt;div&gt;&lt;div&gt;}
assert actual =~ ~s{<div><div>}
assert actual =~ ~s{hi}
assert actual =~ ~s{&lt;/div&gt;&lt;/div&gt;}
assert actual =~ ~s{</div></div>}
assert String.ends_with?(actual, ~s{</a>})
end
@ -124,9 +124,9 @@ defmodule Temple.LinkTest do
assert String.starts_with?(actual, ~s{<button})
assert actual =~ ~s{data-to="/hello"}
assert actual =~ ~s{data-method="post"}
assert actual =~ ~s{&lt;div&gt;&lt;div&gt;}
assert actual =~ ~s{<div><div>}
assert actual =~ ~s{hi}
assert actual =~ ~s{&lt;/div&gt;&lt;/div&gt;}
assert actual =~ ~s{</div></div>}
assert String.ends_with?(actual, ~s{</button>})
end