Skip to content

Commit

Permalink
remove :ecto from .formatter.exs see: #2 (comment)
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jan 12, 2023
1 parent 19a50ce commit 0dfcfe6
Show file tree
Hide file tree
Showing 27 changed files with 306 additions and 185 deletions.
2 changes: 1 addition & 1 deletion .formatter.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[
import_deps: [:ecto, :phoenix],
import_deps: [:phoenix],
plugins: [Phoenix.LiveView.HTMLFormatter],
inputs: [
"*.{heex,ex,exs}",
Expand Down
6 changes: 4 additions & 2 deletions config/dev.exs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ config :app, AppWeb.Endpoint,
check_origin: false,
code_reloader: true,
debug_errors: true,
secret_key_base: "bv1heeBXJGvlEsc6SI66xUox+004UlT+aRAH+UlGgMxGuGMXCbEK32pVx0QNlJxN",
secret_key_base:
"bv1heeBXJGvlEsc6SI66xUox+004UlT+aRAH+UlGgMxGuGMXCbEK32pVx0QNlJxN",
watchers: [
esbuild: {Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
esbuild:
{Esbuild, :install_and_run, [:default, ~w(--sourcemap=inline --watch)]},
tailwind: {Tailwind, :install_and_run, [:default, ~w(--watch)]}
]

Expand Down
3 changes: 2 additions & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import Config
# manifest is generated by the `mix phx.digest` task,
# which you should run after static files are built and
# before starting your production server.
config :app, AppWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
config :app, AppWeb.Endpoint,
cache_static_manifest: "priv/static/cache_manifest.json"

# Do not print debug messages in production
config :logger, level: :info
Expand Down
3 changes: 2 additions & 1 deletion config/test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import Config
# you can enable the server option below.
config :app, AppWeb.Endpoint,
http: [ip: {127, 0, 0, 1}, port: 4002],
secret_key_base: "lrn6ftfPZu7KSTQ54v4foc/gq2FgYfB9/ckQw+Hhi/NNcUM7nf/mUlTqZWJOXAoK",
secret_key_base:
"lrn6ftfPZu7KSTQ54v4foc/gq2FgYfB9/ckQw+Hhi/NNcUM7nf/mUlTqZWJOXAoK",
server: false

# Print only warnings and errors during test
Expand Down
5 changes: 3 additions & 2 deletions example.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ Or navigate directly to it:
![stripe-test-api-keys](https://user-images.githubusercontent.com/194400/211688826-429d2905-49f9-4974-8654-08b3607b43f5.png)

> **Note**: don't worry, these `API Keys` aren't valid.
> This is just for illustration purposes.
The **_Test_ API keys** will be used later.
Save them and don't share them with anyone.
Expand Down Expand Up @@ -90,8 +91,8 @@ you will be able to see the default landing page.
We want the `person` using the `App` to be able to log in.
We will check if they have *paid* or not
for using the `App`.
If he hasn't, he is redirected to a `buy` page.
If he has, he will have access to it!
If they haven't, they are redirected to a `buy` page.
If they have, they will have access to it!

It's a simple `App`, for sure.
But it's still important
Expand Down
24 changes: 18 additions & 6 deletions lib/app/users.ex
Original file line number Diff line number Diff line change
@@ -1,27 +1,39 @@
defmodule UsersTable do

alias Pockets

@table (if Mix.env() == :prod do :users_table else :users_test_table end)
@filepath (if Mix.env() == :prod do "cache.dets" else "cache_test.dets" end)
@table (if Mix.env() == :prod do
:users_table
else
:users_test_table
end)
@filepath (if Mix.env() == :prod do
"cache.dets"
else
"cache_test.dets"
end)

def init() do
case Pockets.new(@table, @filepath) do
# Not testing creating a table because when testing, it loads a sample table.
# coveralls-ignore-start
{:ok, set} -> {:ok, set}
{:ok, set} ->
{:ok, set}

# coveralls-ignore-end
{:error, _} ->
Pockets.open(@table, @filepath)
end
end

def create_user(%{:stripe_id => stripe_id, :person_id => person_id, :status => status}) do
def create_user(%{
:stripe_id => stripe_id,
:person_id => person_id,
:status => status
}) do
Pockets.put(@table, person_id, %{stripe_id: stripe_id, status: status})
end

def fetch_user(person_id) do
Pockets.get(@table, person_id)
end

end
137 changes: 107 additions & 30 deletions lib/app_web/components/core_components.ex
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,16 @@ defmodule AppWeb.CoreComponents do

def modal(assigns) do
~H"""
<div id={@id} phx-mounted={@show && show_modal(@id)} class="relative z-50 hidden">
<div id={"#{@id}-bg"} class="fixed inset-0 bg-zinc-50/90 transition-opacity" aria-hidden="true" />
<div
id={@id}
phx-mounted={@show && show_modal(@id)}
class="relative z-50 hidden"
>
<div
id={"#{@id}-bg"}
class="fixed inset-0 bg-zinc-50/90 transition-opacity"
aria-hidden="true"
/>
<div
class="fixed inset-0 overflow-y-auto"
aria-labelledby={"#{@id}-title"}
Expand Down Expand Up @@ -79,15 +87,24 @@ defmodule AppWeb.CoreComponents do
</div>
<div id={"#{@id}-content"}>
<header :if={@title != []}>
<h1 id={"#{@id}-title"} class="text-lg font-semibold leading-8 text-zinc-800">
<h1
id={"#{@id}-title"}
class="text-lg font-semibold leading-8 text-zinc-800"
>
<%= render_slot(@title) %>
</h1>
<p :if={@subtitle != []} class="mt-2 text-sm leading-6 text-zinc-600">
<p
:if={@subtitle != []}
class="mt-2 text-sm leading-6 text-zinc-600"
>
<%= render_slot(@subtitle) %>
</p>
</header>
<%= render_slot(@inner_block) %>
<div :if={@confirm != [] or @cancel != []} class="ml-6 mb-4 flex items-center gap-5">
<div
:if={@confirm != [] or @cancel != []}
class="ml-6 mb-4 flex items-center gap-5"
>
<.button
:for={confirm <- @confirm}
id={"#{@id}-confirm"}
Expand Down Expand Up @@ -125,12 +142,22 @@ defmodule AppWeb.CoreComponents do
attr :id, :string, default: "flash", doc: "the optional id of flash container"
attr :flash, :map, default: %{}, doc: "the map of flash messages to display"
attr :title, :string, default: nil
attr :kind, :atom, values: [:info, :error], doc: "used for styling and flash lookup"
attr :autoshow, :boolean, default: true, doc: "whether to auto show the flash on mount"

attr :kind, :atom,
values: [:info, :error],
doc: "used for styling and flash lookup"

attr :autoshow, :boolean,
default: true,
doc: "whether to auto show the flash on mount"

attr :close, :boolean, default: true, doc: "whether the flash can be closed"
attr :rest, :global, doc: "the arbitrary HTML attributes to add to the flash container"

slot :inner_block, doc: "the optional inner block that renders the flash message"
attr :rest, :global,
doc: "the arbitrary HTML attributes to add to the flash container"

slot :inner_block,
doc: "the optional inner block that renders the flash message"

def flash(assigns) do
~H"""
Expand All @@ -142,12 +169,17 @@ defmodule AppWeb.CoreComponents do
role="alert"
class={[
"fixed hidden top-2 right-2 w-80 sm:w-96 z-50 rounded-lg p-3 shadow-md shadow-zinc-900/5 ring-1",
@kind == :info && "bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900",
@kind == :error && "bg-rose-50 p-3 text-rose-900 shadow-md ring-rose-500 fill-rose-900"
@kind == :info &&
"bg-emerald-50 text-emerald-800 ring-emerald-500 fill-cyan-900",
@kind == :error &&
"bg-rose-50 p-3 text-rose-900 shadow-md ring-rose-500 fill-rose-900"
]}
{@rest}
>
<p :if={@title} class="flex items-center gap-1.5 text-[0.8125rem] font-semibold leading-6">
<p
:if={@title}
class="flex items-center gap-1.5 text-[0.8125rem] font-semibold leading-6"
>
<Heroicons.information_circle :if={@kind == :info} mini class="h-4 w-4" />
<Heroicons.exclamation_circle :if={@kind == :error} mini class="h-4 w-4" />
<%= @title %>
Expand All @@ -159,7 +191,10 @@ defmodule AppWeb.CoreComponents do
class="group absolute top-2 right-1 p-2"
aria-label={gettext("close")}
>
<Heroicons.x_mark solid class="h-5 w-5 stroke-current opacity-40 group-hover:opacity-70" />
<Heroicons.x_mark
solid
class="h-5 w-5 stroke-current opacity-40 group-hover:opacity-70"
/>
</button>
</div>
"""
Expand All @@ -179,7 +214,10 @@ defmodule AppWeb.CoreComponents do
</.simple_form>
"""
attr :for, :any, default: nil, doc: "the datastructure for the form"
attr :as, :any, default: nil, doc: "the server side parameter to collect all input under"

attr :as, :any,
default: nil,
doc: "the server side parameter to collect all input under"

attr :rest, :global,
include: ~w(autocomplete name rel action enctype method novalidate target),
Expand All @@ -193,7 +231,10 @@ defmodule AppWeb.CoreComponents do
<.form :let={f} for={@for} as={@as} {@rest}>
<div class="space-y-8 bg-white mt-10">
<%= render_slot(@inner_block, f) %>
<div :for={action <- @actions} class="mt-2 flex items-center justify-between gap-6">
<div
:for={action <- @actions}
class="mt-2 flex items-center justify-between gap-6"
>
<%= render_slot(action, f) %>
</div>
</div>
Expand Down Expand Up @@ -249,18 +290,31 @@ defmodule AppWeb.CoreComponents do

attr :type, :string,
default: "text",
values: ~w(checkbox color date datetime-local email file hidden month number password
values:
~w(checkbox color date datetime-local email file hidden month number password
range radio search select tel text textarea time url week)

attr :value, :any
attr :field, :any, doc: "a %Phoenix.HTML.Form{}/field name tuple, for example: {f, :email}"

attr :field, :any,
doc: "a %Phoenix.HTML.Form{}/field name tuple, for example: {f, :email}"

attr :errors, :list
attr :checked, :boolean, doc: "the checked flag for checkbox inputs"
attr :prompt, :string, default: nil, doc: "the prompt for select inputs"
attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"
attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs"
attr :rest, :global, include: ~w(autocomplete disabled form max maxlength min minlength

attr :options, :list,
doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"

attr :multiple, :boolean,
default: false,
doc: "the multiple flag for select inputs"

attr :rest, :global,
include:
~w(autocomplete disabled form max maxlength min minlength
pattern placeholder readonly required size step)

slot :inner_block

def input(%{field: {f, field}} = assigns) do
Expand All @@ -277,10 +331,16 @@ defmodule AppWeb.CoreComponents do
end

def input(%{type: "checkbox"} = assigns) do
assigns = assign_new(assigns, :checked, fn -> input_equals?(assigns.value, "true") end)
assigns =
assign_new(assigns, :checked, fn ->
input_equals?(assigns.value, "true")
end)

~H"""
<label phx-feedback-for={@name} class="flex items-center gap-4 text-sm leading-6 text-zinc-600">
<label
phx-feedback-for={@name}
class="flex items-center gap-4 text-sm leading-6 text-zinc-600"
>
<input type="hidden" name={@name} value="false" />
<input
type="checkbox"
Expand Down Expand Up @@ -387,7 +447,10 @@ defmodule AppWeb.CoreComponents do
def error(assigns) do
~H"""
<p class="phx-no-feedback:hidden mt-3 flex gap-3 text-sm leading-6 text-rose-600">
<Heroicons.exclamation_circle mini class="mt-0.5 h-5 w-5 flex-none fill-rose-500" />
<Heroicons.exclamation_circle
mini
class="mt-0.5 h-5 w-5 flex-none fill-rose-500"
/>
<%= render_slot(@inner_block) %>
</p>
"""
Expand All @@ -404,7 +467,10 @@ defmodule AppWeb.CoreComponents do

def header(assigns) do
~H"""
<header class={[@actions != [] && "flex items-center justify-between gap-6", @class]}>
<header class={[
@actions != [] && "flex items-center justify-between gap-6",
@class
]}>
<div>
<h1 class="text-lg font-semibold leading-8 text-zinc-800">
<%= render_slot(@inner_block) %>
Expand Down Expand Up @@ -436,16 +502,21 @@ defmodule AppWeb.CoreComponents do
attr :label, :string
end

slot :action, doc: "the slot for showing user actions in the last table column"
slot :action,
doc: "the slot for showing user actions in the last table column"

def table(assigns) do
~H"""
<div id={@id} class="overflow-y-auto px-4 sm:overflow-visible sm:px-0">
<table class="mt-11 w-[40rem] sm:w-full">
<thead class="text-left text-[0.8125rem] leading-6 text-zinc-500">
<tr>
<th :for={col <- @col} class="p-0 pb-4 pr-6 font-normal"><%= col[:label] %></th>
<th class="relative p-0 pb-4"><span class="sr-only"><%= gettext("Actions") %></span></th>
<th :for={col <- @col} class="p-0 pb-4 pr-6 font-normal">
<%= col[:label] %>
</th>
<th class="relative p-0 pb-4">
<span class="sr-only"><%= gettext("Actions") %></span>
</th>
</tr>
</thead>
<tbody class="relative divide-y divide-zinc-100 border-t border-zinc-200 text-sm leading-6 text-zinc-700">
Expand Down Expand Up @@ -505,7 +576,9 @@ defmodule AppWeb.CoreComponents do
<div class="mt-14">
<dl class="-my-4 divide-y divide-zinc-100">
<div :for={item <- @item} class="flex gap-4 py-4 sm:gap-8">
<dt class="w-1/4 flex-none text-[0.8125rem] leading-6 text-zinc-500"><%= item.title %></dt>
<dt class="w-1/4 flex-none text-[0.8125rem] leading-6 text-zinc-500">
<%= item.title %>
</dt>
<dd class="text-sm leading-6 text-zinc-700"><%= render_slot(item) %></dd>
</div>
</dl>
Expand Down Expand Up @@ -565,7 +638,9 @@ defmodule AppWeb.CoreComponents do
|> JS.show(to: "##{id}")
|> JS.show(
to: "##{id}-bg",
transition: {"transition-all transform ease-out duration-300", "opacity-0", "opacity-100"}
transition:
{"transition-all transform ease-out duration-300", "opacity-0",
"opacity-100"}
)
|> show("##{id}-container")
|> JS.focus_first(to: "##{id}-content")
Expand All @@ -575,7 +650,9 @@ defmodule AppWeb.CoreComponents do
js
|> JS.hide(
to: "##{id}-bg",
transition: {"transition-all transform ease-in duration-200", "opacity-100", "opacity-0"}
transition:
{"transition-all transform ease-in duration-200", "opacity-100",
"opacity-0"}
)
|> hide("##{id}-container")
|> JS.hide(to: "##{id}", transition: {"block", "block", "hidden"})
Expand Down
3 changes: 2 additions & 1 deletion lib/app_web/components/layouts/app.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@
phx-disconnected={show("#disconnected")}
phx-connected={hide("#disconnected")}
>
Attempting to reconnect <Heroicons.arrow_path class="ml-1 w-3 h-3 inline animate-spin" />
Attempting to reconnect
<Heroicons.arrow_path class="ml-1 w-3 h-3 inline animate-spin" />
</.flash>
<%= @inner_content %>
</div>
Expand Down
7 changes: 6 additions & 1 deletion lib/app_web/components/layouts/root.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@
<%= assigns[:page_title] || "App" %>
</.live_title>
<link phx-track-static rel="stylesheet" href={~p"/assets/app.css"} />
<script defer phx-track-static type="text/javascript" src={~p"/assets/app.js"}>
<script
defer
phx-track-static
type="text/javascript"
src={~p"/assets/app.js"}
>
</script>
</head>
<body class="bg-white antialiased">
Expand Down
Loading

0 comments on commit 0dfcfe6

Please sign in to comment.