Skip to content

Commit 6c92c39

Browse files
committed
Remove Section module, has been replaced by Components
1 parent 702c176 commit 6c92c39

File tree

1 file changed

+47
-95
lines changed

1 file changed

+47
-95
lines changed

lib/components_guide_web/controllers/research_controller.ex

Lines changed: 47 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,6 @@ defmodule ComponentsGuideWeb.ResearchController do
103103
index(conn, %{"q" => ""})
104104
end
105105

106-
defp h2(text) do
107-
content_tag(:h2, text, class: "text-2xl font-bold mb-4")
108-
end
109-
110106
defp present_results(results) when is_binary(results) do
111107
results
112108
end
@@ -184,7 +180,7 @@ defmodule ComponentsGuideWeb.ResearchController do
184180

185181
results ->
186182
content_tag(:article, [
187-
h2("HTML spec"),
183+
content_tag(:h2, "HTML spec"),
188184
results |> present_results()
189185
])
190186
end
@@ -196,14 +192,7 @@ defmodule ComponentsGuideWeb.ResearchController do
196192
[]
197193

198194
results ->
199-
content_tag(:article, [
200-
h2("ARIA Practices"),
201-
Enum.map(results, fn %{heading: heading} ->
202-
Section.card([
203-
content_tag(:h3, heading)
204-
])
205-
end)
206-
])
195+
View.aria_practices(results)
207196
end
208197
end
209198

@@ -213,29 +202,13 @@ defmodule ComponentsGuideWeb.ResearchController do
213202
[]
214203

215204
results ->
216-
content_tag(:article, [
217-
h2("HTML ARIA"),
218-
Enum.map(results, fn %{heading: heading, implicit_semantics: implicit_semantics} ->
219-
Section.card([
220-
content_tag(:h3, heading, class: "text-2xl"),
221-
content_tag(
222-
:dl,
223-
[
224-
content_tag(:dt, "Implicit semantics"),
225-
content_tag(:dd, "#{implicit_semantics}")
226-
]
227-
)
228-
])
229-
end)
230-
])
205+
View.html_aria(results)
231206
end
232207
end
233208

234209
defp static(query) do
235210
for result <- Static.search_for(query) do
236-
result
237-
|> View.render_static()
238-
|> Phoenix.HTML.Safe.to_iodata() |> Phoenix.HTML.raw()
211+
result |> View.render_static() |> Phoenix.HTML.Safe.to_iodata() |> Phoenix.HTML.raw()
239212
end
240213
end
241214

@@ -246,10 +219,10 @@ defmodule ComponentsGuideWeb.ResearchController do
246219
bundlephobia(query),
247220
typescript_dom(query),
248221
caniuse(query),
249-
static(query)
222+
static(query),
250223
# html_spec(query),
251-
# aria_practices(query),
252-
# html_aria(query)
224+
aria_practices(query),
225+
html_aria(query)
253226
]
254227
|> Enum.map(fn el -> el |> Phoenix.HTML.Safe.to_iodata() |> Phoenix.HTML.raw() end)
255228
end
@@ -264,23 +237,24 @@ defmodule ComponentsGuideWeb.ResearchView do
264237
defmodule Components do
265238
use ComponentsGuideWeb, :component
266239

267-
# attr :title, :string, required: true
268-
attr :source, :string, required: true
269-
attr :source_url, :string, required: true
240+
attr(:source, :string, required: true)
241+
attr(:source_url, :string, required: true)
270242

271243
slot(:title)
272244
slot(:inner_block, required: true)
273245

274246
def card(assigns) do
275247
~H"""
276248
<article class="relative mb-4 flex flex-col gap-4 p-4 text-xl text-white bg-violet-900/25 border border-violet-900 rounded shadow-lg">
277-
<h3 class="text-2xl"><%= render_slot(@title) %></h3>
249+
<h3 class="pr-16 text-2xl"><%= render_slot(@title) %></h3>
278250
<a href={@source_url} class="hover:underline absolute top-0 right-0 mt-4 mr-4 text-sm opacity-75"><%= @source %></a>
279251
<%= render_slot(@inner_block) %>
280252
</article>
281253
"""
282254
end
283255

256+
slot(:item)
257+
284258
def description_list(assigns) do
285259
~H"""
286260
<dl>
@@ -298,53 +272,6 @@ defmodule ComponentsGuideWeb.ResearchView do
298272
end
299273
end
300274

301-
defmodule Section do
302-
def card(children) do
303-
content_tag(
304-
:article,
305-
children,
306-
class:
307-
"relative mb-4 flex flex-col gap-4 p-4 text-xl text-white bg-violet-900/25 border border-violet-900 rounded-lg shadow-lg"
308-
)
309-
end
310-
311-
def card_source(title, href) do
312-
content_tag(:a, title,
313-
href: href,
314-
class: "hover:underline absolute top-0 right-0 mt-4 mr-4 text-sm opacity-75"
315-
)
316-
end
317-
318-
def unordered_list(items, attrs \\ []) do
319-
children =
320-
Enum.map(items, fn text ->
321-
content_tag(:li, text)
322-
end)
323-
324-
content_tag(:ul, children, attrs)
325-
end
326-
327-
def description_list(items) do
328-
children =
329-
items
330-
|> Stream.filter(fn {_title, value} -> value != nil end)
331-
|> Enum.map(fn {title, value} ->
332-
content_tag(:div, [
333-
content_tag(:dt, title, class: "text-base font-bold"),
334-
case value do
335-
list when is_list(list) ->
336-
for item <- list, do: content_tag(:dd, item, class: "text-base pl-4")
337-
338-
value ->
339-
content_tag(:dd, value, class: "text-base pl-4")
340-
end
341-
])
342-
end)
343-
344-
content_tag(:dl, children)
345-
end
346-
end
347-
348275
defdelegate card(assigns), to: Components
349276
defdelegate description_list(assigns), to: Components
350277

@@ -491,16 +418,12 @@ defmodule ComponentsGuideWeb.ResearchView do
491418
~H"""
492419
<.card source="RFC" source_url="https://www.rfc-editor.org">
493420
<:title><%= "#{@name} Spec" %></:title>
494-
<%= Section.description_list([
495-
{"Specs",
496-
@specs
497-
|> Enum.map(fn
498-
"rfc" <> _ = spec -> link(spec, to: "https://tools.ietf.org/html/" <> spec)
499-
spec -> spec
500-
end)
501-
|> Section.unordered_list(class: "flex list-disc ml-4 space-x-8")},
502-
{"Media (MIME) Type", Keyword.get(@metadata, :media_type)}
503-
]) %>
421+
<.description_list>
422+
<:item title="Specs" data={for(spec <- @specs, do: link(spec, to: "https://tools.ietf.org/html/" <> spec))} />
423+
<:item title="Media (MIME) Type">
424+
<%= Keyword.get(@metadata, :media_type) %>
425+
</:item>
426+
</.description_list>
504427
</.card>
505428
"""
506429
end
@@ -536,4 +459,33 @@ defmodule ComponentsGuideWeb.ResearchView do
536459
super_tiny_icon(info)
537460
end
538461
end
462+
463+
def aria_practices(results) do
464+
assigns = %{results: results}
465+
466+
~H"""
467+
<%= for result <- @results do %>
468+
<.card source="ARIA Practices" source_url="https://www.w3.org/TR/wai-aria-practices/">
469+
<:title><%= result.heading %></:title>
470+
</.card>
471+
<% end %>
472+
"""
473+
end
474+
475+
def html_aria(results) do
476+
assigns = %{results: results}
477+
478+
~H"""
479+
<%= for result <- @results do %>
480+
<.card source="HTML ARIA" source_url="https://www.w3.org/TR/html-aria/">
481+
<:title><%= result.heading %></:title>
482+
<.description_list>
483+
<:item title="Implicit semantics">
484+
<%= result.implicit_semantics %>
485+
</:item>
486+
</.description_list>
487+
</.card>
488+
<% end %>
489+
"""
490+
end
539491
end

0 commit comments

Comments
 (0)