Skip to content

Commit

Permalink
fix: fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
ripple0328 committed Sep 20, 2024
1 parent 7e7ab00 commit e5375af
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 57 deletions.
8 changes: 2 additions & 6 deletions config/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,9 @@ config :mime, :types, %{
"text/swiftui" => ["swiftui"]
}

config :phoenix, :template_engines, [
neex: LiveViewNative.Engine
]
config :phoenix, :template_engines, neex: LiveViewNative.Engine

config :phoenix_template, :format_encoders, [
swiftui: Phoenix.HTML.Engine
]
config :phoenix_template, :format_encoders, swiftui: Phoenix.HTML.Engine

# Import environment specific config. This must remain at the bottom
# of this file so it overrides the configuration defined above.
Expand Down
59 changes: 31 additions & 28 deletions lib/gatherly_native.ex
Original file line number Diff line number Diff line change
Expand Up @@ -120,46 +120,49 @@ defmodule GatherlyNative do
end

defp helpers(format) do
gettext_quoted = quote do
import GatherlyWeb.Gettext
end

gettext_quoted =
quote do
import GatherlyWeb.Gettext
end

plugin = LiveViewNative.fetch_plugin!(format)

plugin_component_quoted = try do
Code.ensure_compiled!(plugin.component)
plugin_component_quoted =
try do
Code.ensure_compiled!(plugin.component)

quote do
import unquote(plugin.component)
quote do
import unquote(plugin.component)
end
rescue
_ -> nil
end
rescue
_ -> nil
end

live_form_quoted = quote do
import LiveViewNative.LiveForm.Component
end
live_form_quoted =
quote do
import LiveViewNative.LiveForm.Component
end

core_component_module = Module.concat([GatherlyWeb, CoreComponents, plugin.module_suffix])

core_component_quoted = try do
Code.ensure_compiled!(core_component_module)
core_component_quoted =
try do
Code.ensure_compiled!(core_component_module)

quote do
import unquote(core_component_module)
quote do
import unquote(core_component_module)
end
rescue
_ -> nil
end
rescue
_ -> nil
end

[
gettext_quoted,
plugin_component_quoted,
live_form_quoted,
core_component_quoted,
verified_routes()
]

gettext_quoted,
plugin_component_quoted,
live_form_quoted,
core_component_quoted,
verified_routes()
]
end

@doc """
Expand Down
61 changes: 38 additions & 23 deletions lib/gatherly_web/components/core_components.swiftui.ex
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ defmodule GatherlyWeb.CoreComponents.SwiftUI do

attr :type, :string,
default: "TextField",
values: ~w(TextFieldLink DatePicker MultiDatePicker Picker SecureField Slider Stepper TextEditor TextField Toggle hidden)
values:
~w(TextFieldLink DatePicker MultiDatePicker Picker SecureField Slider Stepper TextEditor TextField Toggle hidden)

attr :field, Phoenix.HTML.FormField,
doc: "a form field struct retrieved from the form, for example: `@form[:email]`"
Expand All @@ -75,8 +76,7 @@ defmodule GatherlyWeb.CoreComponents.SwiftUI do
default: "on",
values: ~w(on off)

attr :rest, :global,
include: ~w(disabled step)
attr :rest, :global, include: ~w(disabled step)

slot :inner_block

Expand All @@ -88,11 +88,22 @@ defmodule GatherlyWeb.CoreComponents.SwiftUI do
|> assign_new(:value, fn -> field.value end)
|> assign(
:rest,
Map.put(assigns.rest, :style, [
Map.get(assigns.rest, :style, ""),
(if assigns.readonly or Map.get(assigns.rest, :disabled, false), do: "disabled(true)", else: ""),
(if assigns.autocomplete == "off", do: "textInputAutocapitalization(.never) autocorrectionDisabled()", else: "")
] |> Enum.join(" "))
Map.put(
assigns.rest,
:style,
[
Map.get(assigns.rest, :style, ""),
if(assigns.readonly or Map.get(assigns.rest, :disabled, false),
do: "disabled(true)",
else: ""
),
if(assigns.autocomplete == "off",
do: "textInputAutocapitalization(.never) autocorrectionDisabled()",
else: ""
)
]
|> Enum.join(" ")
)
)
|> input()
end
Expand Down Expand Up @@ -420,7 +431,7 @@ defmodule GatherlyWeb.CoreComponents.SwiftUI do

slot :inner_block, required: true

def button(%{ type: "submit" } = assigns) do
def button(%{type: "submit"} = assigns) do
~LVN"""
<Section>
<LiveSubmitButton style={[
Expand Down Expand Up @@ -553,7 +564,9 @@ defmodule GatherlyWeb.CoreComponents.SwiftUI do

attr :url, :string, required: true
attr :rest, :global
slot :empty, doc: """

slot :empty,
doc: """
The empty state that will render before has successfully been downloaded.
<.image url={~p"/assets/images/logo.png"}>
Expand All @@ -564,30 +577,32 @@ defmodule GatherlyWeb.CoreComponents.SwiftUI do
[See SwiftUI docs](https://developer.apple.com/documentation/swiftui/asyncimagephase/success(_:))
"""
slot :success, doc: """

slot :success,
doc: """
The success state that will render when the image has successfully been downloaded.
<.image url={~p"/assets/images/logo.png"}>
<:success class="main-logo"/>
</.image>
[See SwiftUI docs](https://developer.apple.com/documentation/swiftui/asyncimagephase/success(_:))
"""
do
""" do
attr :class, :string
attr :style, :string
end
slot :failure, doc: """
The failure state that will render when the image fails to downloaded.

<.image url={~p"/assets/images/logo.png"}>
<:failure class="image-fail"/>
</.image>
slot :failure,
doc: """
The failure state that will render when the image fails to downloaded.
[See SwiftUI docs](https://developer.apple.com/documentation/swiftui/asyncimagephase/failure(_:))
<.image url={~p"/assets/images/logo.png"}>
<:failure class="image-fail"/>
</.image>
"""
do
[See SwiftUI docs](https://developer.apple.com/documentation/swiftui/asyncimagephase/failure(_:))
""" do
attr :class, :string
attr :style, :string
end
Expand All @@ -604,7 +619,7 @@ defmodule GatherlyWeb.CoreComponents.SwiftUI do
"""
end

defp image_success(%{ slot: [%{ inner_block: nil }] } = assigns) do
defp image_success(%{slot: [%{inner_block: nil}]} = assigns) do
~LVN"""
<AsyncImage image template="phase.success" :for={slot <- @slot} class={Map.get(slot, :class)} {%{ style: Map.get(slot, :style) }} />
"""
Expand All @@ -618,7 +633,7 @@ defmodule GatherlyWeb.CoreComponents.SwiftUI do
"""
end

defp image_failure(%{ slot: [%{ inner_block: nil }] } = assigns) do
defp image_failure(%{slot: [%{inner_block: nil}]} = assigns) do
~LVN"""
<AsyncImage error template="phase.failure" :for={slot <- @slot} class={Map.get(slot, :class)} {%{ style: Map.get(slot, :style) }} />
"""
Expand Down

0 comments on commit e5375af

Please sign in to comment.