Skip to content

Commit

Permalink
fix: Format code.
Browse files Browse the repository at this point in the history
  • Loading branch information
GSMLG-BOT committed Apr 15, 2022
1 parent 7343a8e commit 7a37b11
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 8 deletions.
5 changes: 4 additions & 1 deletion lib/phoenix_webcomponent.ex
Expand Up @@ -324,7 +324,10 @@ defmodule Phoenix.WebComponent do

defp attr_escape({:safe, data}), do: data
defp attr_escape(nil), do: []
defp attr_escape(other) when is_binary(other), do: Phoenix.WebComponent.Engine.encode_to_iodata!(other)

defp attr_escape(other) when is_binary(other),
do: Phoenix.WebComponent.Engine.encode_to_iodata!(other)

defp attr_escape(other), do: Phoenix.WebComponent.Safe.to_iodata(other)

@doc """
Expand Down
5 changes: 4 additions & 1 deletion lib/phoenix_webcomponent/engine.ex
Expand Up @@ -21,7 +21,10 @@ defmodule Phoenix.WebComponent.Engine do
def encode_to_iodata!({:safe, body}), do: body
def encode_to_iodata!(nil), do: ""
def encode_to_iodata!(bin) when is_binary(bin), do: html_escape(bin)
def encode_to_iodata!(list) when is_list(list), do: Phoenix.WebComponent.Safe.List.to_iodata(list)

def encode_to_iodata!(list) when is_list(list),
do: Phoenix.WebComponent.Safe.List.to_iodata(list)

def encode_to_iodata!(other), do: Phoenix.WebComponent.Safe.to_iodata(other)

@doc false
Expand Down
1 change: 1 addition & 0 deletions lib/phoenix_webcomponent/form.ex
Expand Up @@ -663,6 +663,7 @@ defmodule Phoenix.WebComponent.Form do
"""
def wc_textarea(form, field, opts \\ []) do
{value, opts} = Keyword.pop(opts, :value, input_value(form, field))

opts =
opts
|> Keyword.put_new(:id, input_id(form, field))
Expand Down
6 changes: 4 additions & 2 deletions lib/phoenix_webcomponent/form_data.ex
Expand Up @@ -37,14 +37,16 @@ defprotocol Phoenix.WebComponent.FormData do
Returns the HTML5 validations that would apply to
the given field.
"""
@spec input_validations(t, Phoenix.WebComponent.Form.t(), Phoenix.WebComponent.Form.field()) :: Keyword.t()
@spec input_validations(t, Phoenix.WebComponent.Form.t(), Phoenix.WebComponent.Form.field()) ::
Keyword.t()
def input_validations(data, form, field)

@doc """
Receives the given field and returns its input type (:text_input,
:select, etc). Returns `nil` if the type is unknown.
"""
@spec input_type(t, Phoenix.WebComponent.Form.t(), Phoenix.WebComponent.Form.field()) :: atom | nil
@spec input_type(t, Phoenix.WebComponent.Form.t(), Phoenix.WebComponent.Form.field()) ::
atom | nil
def input_type(data, form, field)
end

Expand Down
5 changes: 4 additions & 1 deletion lib/phoenix_webcomponent/link.ex
Expand Up @@ -83,7 +83,10 @@ defmodule Phoenix.WebComponent.Link do
else
{csrf_token, opts} = Keyword.pop(opts, :csrf_token, true)
opts = Keyword.put_new(opts, :rel, "nofollow")
[data: data] = Phoenix.WebComponent.link_attributes(to, method: method, csrf_token: csrf_token)

[data: data] =
Phoenix.WebComponent.link_attributes(to, method: method, csrf_token: csrf_token)

content_tag(:a, text, [data: data, href: data[:to]] ++ opts)
end
end
Expand Down
11 changes: 9 additions & 2 deletions test/phoenix_html/engine_test.exs
Expand Up @@ -5,7 +5,11 @@ defmodule Phoenix.WebComponent.EngineTest do
def unsafe(do: {:safe, content}), do: content

test "encode_to_iodata!" do
assert Phoenix.WebComponent.Engine.encode_to_iodata!("<foo>") == [[[] | "&lt;"], "foo" | "&gt;"]
assert Phoenix.WebComponent.Engine.encode_to_iodata!("<foo>") == [
[[] | "&lt;"],
"foo" | "&gt;"
]

assert Phoenix.WebComponent.Engine.encode_to_iodata!({:safe, "<foo>"}) == "<foo>"
assert Phoenix.WebComponent.Engine.encode_to_iodata!(123) == "123"
end
Expand Down Expand Up @@ -71,7 +75,10 @@ defmodule Phoenix.WebComponent.EngineTest do

defp eval(string, assigns \\ %{}) do
{:safe, io} =
EEx.eval_string(string, [assigns: assigns], file: __ENV__.file, engine: Phoenix.WebComponent.Engine)
EEx.eval_string(string, [assigns: assigns],
file: __ENV__.file,
engine: Phoenix.WebComponent.Engine
)

IO.iodata_to_binary(io)
end
Expand Down
5 changes: 4 additions & 1 deletion test/phoenix_html/form_test.exs
Expand Up @@ -426,7 +426,10 @@ defmodule Phoenix.WebComponent.FormTest do
end

test "generates hidden fields for lists from the given form" do
form = %{Phoenix.WebComponent.FormData.to_form(conn(), []) | hidden: [field: ["a", "b", "c"]]}
form = %{
Phoenix.WebComponent.FormData.to_form(conn(), [])
| hidden: [field: ["a", "b", "c"]]
}

assert hidden_inputs_for(form) ==
[
Expand Down

0 comments on commit 7a37b11

Please sign in to comment.