Fix block style phx_link macros
This commit is contained in:
parent
fb5147ff97
commit
a372a64858
|
@ -114,10 +114,22 @@ defmodule Dsl.Form do
|
|||
@doc """
|
||||
Please see `Phoenix.HTML.Form.label/3` for details.
|
||||
"""
|
||||
defmacro phx_label(form, field, text_or_opts_or_block) do
|
||||
defmacro phx_label(form, field, do: block) do
|
||||
quote do
|
||||
{:safe, input} =
|
||||
Phoenix.HTML.Form.label(unquote_splicing([form, field, text_or_opts_or_block]))
|
||||
{:safe, content} =
|
||||
htm do
|
||||
unquote(block)
|
||||
end
|
||||
|
||||
{:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field]), do: content)
|
||||
|
||||
Utils.put_buffer(var!(buff, Dsl.Tags), input)
|
||||
end
|
||||
end
|
||||
|
||||
defmacro phx_label(form, field, text_or_opts) do
|
||||
quote do
|
||||
{:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field, text_or_opts]))
|
||||
|
||||
Utils.put_buffer(var!(buff, Dsl.Tags), input)
|
||||
end
|
||||
|
@ -126,10 +138,22 @@ defmodule Dsl.Form do
|
|||
@doc """
|
||||
Please see `Phoenix.HTML.Form.label/4` for details.
|
||||
"""
|
||||
defmacro phx_label(form, field, text_or_opts, opts_or_block) do
|
||||
defmacro phx_label(form, field, opts, do: block) do
|
||||
quote do
|
||||
{:safe, input} =
|
||||
Phoenix.HTML.Form.label(unquote_splicing([form, field, text_or_opts, opts_or_block]))
|
||||
{:safe, content} =
|
||||
htm do
|
||||
unquote(block)
|
||||
end
|
||||
|
||||
{:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field, opts]), do: content)
|
||||
|
||||
Utils.put_buffer(var!(buff, Dsl.Tags), input)
|
||||
end
|
||||
end
|
||||
|
||||
defmacro phx_label(form, field, text, opts) do
|
||||
quote do
|
||||
{:safe, input} = Phoenix.HTML.Form.label(unquote_splicing([form, field, text, opts]))
|
||||
|
||||
Utils.put_buffer(var!(buff, Dsl.Tags), input)
|
||||
end
|
||||
|
|
|
@ -504,14 +504,16 @@ defmodule Dsl.FormTest do
|
|||
{:safe, result} =
|
||||
htm do
|
||||
phx_label :user, :name do
|
||||
"Name"
|
||||
div do
|
||||
text "Name"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assert result =~ ~s{<label}
|
||||
assert String.starts_with?(result, ~s{<label})
|
||||
assert result =~ ~s{for="user_name"}
|
||||
assert result =~ ~s{Name}
|
||||
assert result =~ ~s{</label>}
|
||||
assert String.ends_with?(result, ~s{</label>})
|
||||
end
|
||||
|
||||
test "generates a phx_label/4 with text and opts" do
|
||||
|
@ -531,15 +533,17 @@ defmodule Dsl.FormTest do
|
|||
{:safe, result} =
|
||||
htm do
|
||||
phx_label :user, :name, class: "label-style" do
|
||||
"Name"
|
||||
div do
|
||||
text "Name"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
assert result =~ ~s{<label}
|
||||
assert String.starts_with?(result, ~s{<label})
|
||||
assert result =~ ~s{for="user_name"}
|
||||
assert result =~ ~s{class="label-style"}
|
||||
assert result =~ ~s{Name}
|
||||
assert result =~ ~s{</label>}
|
||||
assert String.ends_with?(result, ~s{</label>})
|
||||
end
|
||||
|
||||
test "generates a multiple_select tag" do
|
||||
|
|
Reference in a new issue