Skip to content

Commit f1da4fe

Browse files
committed
Format everything
1 parent b558c0b commit f1da4fe

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+838
-442
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
%{
2-
"libcomponentsguide_rustler_math-v0.1.2-nif-2.16-aarch64-apple-darwin.so.tar.gz" => "sha256:0e30ecf8c0614f9c0fffc553683ecef147caf0737e57304d2a37532f3cf9657d",
2+
"libcomponentsguide_rustler_math-v0.1.2-nif-2.16-aarch64-apple-darwin.so.tar.gz" =>
3+
"sha256:0e30ecf8c0614f9c0fffc553683ecef147caf0737e57304d2a37532f3cf9657d"
34
}

config/runtime.exs

+4-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ if config_env() == :prod do
2525
You can generate one by calling: mix phx.gen.secret
2626
"""
2727

28-
host = System.get_env("PHX_HOST") || System.get_env("RENDER_EXTERNAL_HOSTNAME") || "components.guide"
28+
host =
29+
System.get_env("PHX_HOST") || System.get_env("RENDER_EXTERNAL_HOSTNAME") || "components.guide"
30+
2931
port = String.to_integer(System.get_env("PORT") || "4000")
3032

3133
config :components_guide, ComponentsGuideWeb.Endpoint,
@@ -69,5 +71,4 @@ if config_env() == :prod do
6971
# See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details.
7072
end
7173

72-
config :components_guide, :redis,
73-
url: System.get_env("REDIS_URL", "")
74+
config :components_guide, :redis, url: System.get_env("REDIS_URL", "")

lib/components_guide/content.ex

+14-17
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,28 @@ defmodule ComponentsGuide.Content do
66
@cache_name :content_cache
77

88
def list_content do
9-
query = Cachex.Query.create(true, { :key, :value })
9+
query = Cachex.Query.create(true, {:key, :value})
10+
1011
Cachex.stream!(@cache_name, query)
11-
|> Enum.map(fn {id, content} -> %Text{id: id, content: content} end)
12+
|> Enum.map(fn {id, content} -> %Text{id: id, content: content} end)
1213
end
1314

1415
def change_text(%Text{} = text) do
1516
Text.changeset(text)
1617
end
1718

1819
defp build_text(params) do
19-
with {:ok, text} <- %Text{}
20-
|> Text.changeset(params)
21-
|> Ecto.Changeset.apply_action(:insert)
22-
do
20+
with {:ok, text} <-
21+
%Text{}
22+
|> Text.changeset(params)
23+
|> Ecto.Changeset.apply_action(:insert) do
2324
{:ok, %Text{text | id: :crypto.hash(:sha256, text.content)}}
2425
end
2526
end
2627

2728
def create_text(params) do
2829
with {:ok, text} <- build_text(params),
29-
{:ok, _} <- Cachex.put(@cache_name, text.id, text.content)
30-
do
30+
{:ok, _} <- Cachex.put(@cache_name, text.id, text.content) do
3131
{:ok, text}
3232
end
3333
end
@@ -38,11 +38,10 @@ defmodule ComponentsGuide.Content do
3838

3939
def import_text(params) do
4040
with changeset <- TextImport.changeset(%TextImport{}, params),
41-
{:ok, text_import} <- Ecto.Changeset.apply_action(changeset, :insert),
42-
response <- get_url(text_import.url),
43-
{:ok, text} <- build_text(%{ content: response.body }),
44-
{:ok, _} <- Cachex.put(@cache_name, text.id, text.content)
45-
do
41+
{:ok, text_import} <- Ecto.Changeset.apply_action(changeset, :insert),
42+
response <- get_url(text_import.url),
43+
{:ok, text} <- build_text(%{content: response.body}),
44+
{:ok, _} <- Cachex.put(@cache_name, text.id, text.content) do
4645
{:ok, text}
4746
end
4847
end
@@ -51,17 +50,15 @@ defmodule ComponentsGuide.Content do
5150

5251
def get_text!(id_encoded) do
5352
with {:ok, id} <- decode_id(id_encoded),
54-
{:ok, content} <- Cachex.get(@cache_name, id)
55-
do
53+
{:ok, content} <- Cachex.get(@cache_name, id) do
5654
%Text{id: id, content: content}
5755
else
5856
_ -> raise Ecto.NoResultsError
5957
end
6058
end
6159

6260
def delete_text(id_encoded) do
63-
with {:ok, id} <- decode_id(id_encoded)
64-
do
61+
with {:ok, id} <- decode_id(id_encoded) do
6562
Cachex.del(@cache_name, id)
6663
end
6764
end

lib/components_guide/content/text.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ defmodule ComponentsGuide.Content.Text do
88

99
def changeset(%ComponentsGuide.Content.Text{} = text, params \\ %{}) do
1010
text
11-
|> cast(params, [:content])
12-
|> validate_required([:content])
11+
|> cast(params, [:content])
12+
|> validate_required([:content])
1313
end
1414

1515
def to_param(%ComponentsGuide.Content.Text{id: id}) do

lib/components_guide/content/text_import.ex

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ defmodule ComponentsGuide.Content.TextImport do
88

99
def changeset(%ComponentsGuide.Content.TextImport{} = text_import, params \\ %{}) do
1010
text_import
11-
|> cast(params, [:url])
12-
|> validate_required([:url])
11+
|> cast(params, [:url])
12+
|> validate_required([:url])
1313
end
1414
end

lib/components_guide/fetch.ex

+2-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,8 @@ defmodule ComponentsGuide.Fetch do
8282

8383
{conn, response} = do_request(conn, req, t)
8484

85-
response = Response.finish_timings(response, [:fetch, :load_many!, :request, :done], %{req: req})
85+
response =
86+
Response.finish_timings(response, [:fetch, :load_many!, :request, :done], %{req: req})
8687

8788
{conn, [response | results]}
8889
end)

lib/components_guide/git/pkt_line.ex

+10-7
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,19 @@ defmodule ComponentsGuide.Git.PktLine do
1010

1111
[oid, ref_raw | attrs_raw] ->
1212
[ref | _] = ref_raw |> String.split("\u0000")
13-
attrs = for attr_raw <- attrs_raw do
14-
# case String.split(attr_raw, ":", parts: 2) do
15-
case String.split(attr_raw, "=", parts: 2) do
16-
[attr] ->
17-
{attr, true}
13+
14+
attrs =
15+
for attr_raw <- attrs_raw do
16+
# case String.split(attr_raw, ":", parts: 2) do
17+
case String.split(attr_raw, "=", parts: 2) do
18+
[attr] ->
19+
{attr, true}
20+
1821
[key, value] ->
1922
{key, value}
20-
23+
end
2124
end
22-
end
25+
2326
%__MODULE__{oid: oid, ref: ref, attrs: attrs, attrs_raw: attrs_raw}
2427

2528
_ ->

lib/components_guide/research/spec.ex

+13-3
Original file line numberDiff line numberDiff line change
@@ -185,14 +185,21 @@ defmodule ComponentsGuide.Research.Spec do
185185
{:ok, db} = Exqlite.Sqlite3.open(":memory:")
186186
:ok = Exqlite.Sqlite3.execute(db, "CREATE VIRTUAL TABLE files USING FTS5(name, body)")
187187

188-
{:ok, statement} = Exqlite.Sqlite3.prepare(db, "insert into files (name, body) values (?, ?)")
188+
{:ok, statement} =
189+
Exqlite.Sqlite3.prepare(db, "insert into files (name, body) values (?, ?)")
190+
189191
:ok = Exqlite.Sqlite3.bind(db, statement, ["lib.dom.d.ts", source])
190192
:done = Exqlite.Sqlite3.step(db, statement)
191193
:ok = Exqlite.Sqlite3.release(db, statement)
192194

193195
# Prepare a select statement
194196
# {:ok, statement} = Exqlite.Sqlite3.prepare(db, "select highlight(files, 1, '<b>', '</b>') body from files where files match ? order by rank")
195-
{:ok, statement} = Exqlite.Sqlite3.prepare(db, "select snippet(files, 1, '', '', '…', 64) body from files where files match ? order by rank")
197+
{:ok, statement} =
198+
Exqlite.Sqlite3.prepare(
199+
db,
200+
"select snippet(files, 1, '', '', '…', 64) body from files where files match ? order by rank"
201+
)
202+
196203
# Not sure why we have to wrap in quotes: https://stackoverflow.com/questions/21596069/sqlite-full-text-search-queries-with-hyphens#comment109416178_21599291
197204
:ok = Exqlite.Sqlite3.bind(db, statement, [~s{"#{query}"}])
198205

@@ -207,7 +214,10 @@ defmodule ComponentsGuide.Research.Spec do
207214
Exqlite.Sqlite3.close(db)
208215

209216
duration = System.monotonic_time() - start
210-
IO.puts("SQLite create + text search took #{System.convert_time_unit(duration, :native, :millisecond)}ms")
217+
218+
IO.puts(
219+
"SQLite create + text search took #{System.convert_time_unit(duration, :native, :millisecond)}ms"
220+
)
211221

212222
{columns, rows}
213223
else

lib/components_guide/rustler/molten.ex

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ defmodule ComponentsGuide.Rustler.Molten do
1212

1313
def add(a, b), do: Native.add(a, b)
1414
def js(source), do: Native.js(source)
15+
1516
def typescript_module(source) do
1617
ref = make_ref()
1718
Native.typescript_module(source, self(), ref)

lib/components_guide/wasm/examples/examples_http_headers.ex

+12-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,17 @@ defmodule ComponentsGuide.Wasm.Examples.HTTPHeaders do
5050
s_max_age_seconds = age_seconds
5151
end
5252

53-
func to_string(), result: I32.String, locals: [start: I32, byte_count: I32, int_offset: I32] do
53+
func to_string(),
54+
result: I32.String,
55+
locals: [len: I32, start: I32, byte_count: I32, int_offset: I32] do
56+
len =
57+
I32.add([
58+
I32.when?(I32.ge_s(max_age_seconds, 0),
59+
do: I32.add(byte_size("max-age="), IntToString.u32toa_count(max_age_seconds)),
60+
else: 0
61+
)
62+
])
63+
5464
I32.when? private do
5565
const("private")
5666
else
@@ -94,7 +104,7 @@ defmodule ComponentsGuide.Wasm.Examples.HTTPHeaders do
94104
I32.when? immutable do
95105
const("immutable")
96106
else
97-
const("hello")
107+
const("max-age=0")
98108
end
99109
end
100110
end

lib/components_guide_web/components/calendar_component.ex

+32-18
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
defmodule ComponentsGuideWeb.CalendarComponent do
22
use ComponentsGuideWeb, :component
3-
3+
44
attr :current_date, Date, required: true
5-
5+
66
slot :cell_content
77

88
def calendar_grid(assigns) do
@@ -31,18 +31,25 @@ defmodule ComponentsGuideWeb.CalendarComponent do
3131
</tr>
3232
</thead>
3333
<tbody>
34-
<%= for week_offset <- -4..4 do %>
35-
<tr class="min-h-16 group">
36-
<%= for weekday <- 1..7 do %>
37-
<% date = Date.add(@current_row_start_date, week_offset * 7 + (weekday - 1)) %>
38-
<% current_day? = week_offset == 0 && @current_day_of_week == weekday %>
39-
<td aria-current={if current_day?, do: "date", else: "false"} class={td_class(%{current_day?: current_day?, weekday: weekday, week_offset: week_offset})}>
40-
<div class={td_text_class(week_offset, weekday, current_day?)}><%= Calendar.strftime(date, "%d %b") %></div>
41-
<%= render_slot(@cell_content, date) %>
42-
</td>
43-
<% end %>
44-
</tr>
45-
<% end %>
34+
<%= for week_offset <- -4..4 do %>
35+
<tr class="min-h-16 group">
36+
<%= for weekday <- 1..7 do %>
37+
<% date = Date.add(@current_row_start_date, week_offset * 7 + (weekday - 1)) %>
38+
<% current_day? = week_offset == 0 && @current_day_of_week == weekday %>
39+
<td
40+
aria-current={if current_day?, do: "date", else: "false"}
41+
class={
42+
td_class(%{current_day?: current_day?, weekday: weekday, week_offset: week_offset})
43+
}
44+
>
45+
<div class={td_text_class(week_offset, weekday, current_day?)}>
46+
<%= Calendar.strftime(date, "%d %b") %>
47+
</div>
48+
<%= render_slot(@cell_content, date) %>
49+
</td>
50+
<% end %>
51+
</tr>
52+
<% end %>
4653
</tbody>
4754
</table>
4855
"""
@@ -53,10 +60,17 @@ defmodule ComponentsGuideWeb.CalendarComponent do
5360
defp td_class(%{week_offset: 0}), do: "align-middle bg-green-900/25"
5461
defp td_class(_), do: "align-middle bg-black"
5562

56-
defp td_text_class(0, weekday, current_day?), do: "text-sm opacity-100 #{td_text_class_weekday(weekday, current_day?)}"
57-
defp td_text_class(week_offset, weekday, current_day?) when week_offset in [-1, 1], do: "text-sm opacity-90 #{td_text_class_weekday(weekday, current_day?)}"
58-
defp td_text_class(week_offset, weekday, current_day?) when week_offset in [-2, 2], do: "text-sm opacity-80 #{td_text_class_weekday(weekday, current_day?)}"
59-
defp td_text_class(_, weekday, current_day?), do: "text-sm opacity-75 #{td_text_class_weekday(weekday, current_day?)}"
63+
defp td_text_class(0, weekday, current_day?),
64+
do: "text-sm opacity-100 #{td_text_class_weekday(weekday, current_day?)}"
65+
66+
defp td_text_class(week_offset, weekday, current_day?) when week_offset in [-1, 1],
67+
do: "text-sm opacity-90 #{td_text_class_weekday(weekday, current_day?)}"
68+
69+
defp td_text_class(week_offset, weekday, current_day?) when week_offset in [-2, 2],
70+
do: "text-sm opacity-80 #{td_text_class_weekday(weekday, current_day?)}"
71+
72+
defp td_text_class(_, weekday, current_day?),
73+
do: "text-sm opacity-75 #{td_text_class_weekday(weekday, current_day?)}"
6074

6175
defp td_text_class_weekday(1, _current_day?), do: ""
6276
defp td_text_class_weekday(5, _current_day?), do: ""

lib/components_guide_web/components/core_components.ex

+4-1
Original file line numberDiff line numberDiff line change
@@ -219,8 +219,11 @@ defmodule ComponentsGuideWeb.CoreComponents do
219219
attr :prompt, :string, default: nil, doc: "the prompt for select inputs"
220220
attr :options, :list, doc: "the options to pass to Phoenix.HTML.Form.options_for_select/2"
221221
attr :multiple, :boolean, default: false, doc: "the multiple flag for select inputs"
222-
attr :rest, :global, include: ~w(autocomplete cols disabled form list max maxlength min minlength
222+
223+
attr :rest, :global,
224+
include: ~w(autocomplete cols disabled form list max maxlength min minlength
223225
pattern placeholder readonly required rows size step)
226+
224227
slot :inner_block
225228

226229
def input(%{field: %Phoenix.HTML.FormField{} = field} = assigns) do

0 commit comments

Comments
 (0)