Skip to content

Commit 4cb2cbf

Browse files
committed
Improve html aria spec search
1 parent 6f6bdce commit 4cb2cbf

File tree

3 files changed

+65
-8
lines changed

3 files changed

+65
-8
lines changed

apps/components_guide/lib/components_guide/research/spec.ex

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,48 @@ defmodule ComponentsGuide.Research.Spec do
4040
url = "https://www.w3.org/TR/html-aria/"
4141
{:ok, document} = Source.html_document_at(url)
4242

43-
document
44-
|> Floki.find(
45-
"#document-conformance-requirements-for-use-of-aria-attributes-in-html table tbody tr"
46-
)
47-
# |> Floki.find("#id-#{query}")
48-
|> Floki.raw_html()
43+
html_elements =
44+
document
45+
|> Floki.find(
46+
"#document-conformance-requirements-for-use-of-aria-attributes-in-html table tbody"
47+
)
48+
|> Floki.find("tr")
49+
50+
# |> Floki.find("[id*='#{query}']")
51+
# |> Floki.find("tr:fl-contains('#{query}')")
52+
53+
html_elements =
54+
Enum.filter(html_elements, fn
55+
el = {"tr", _attrs, _children} ->
56+
Floki.text(el) |> String.contains?(query)
57+
58+
_ ->
59+
false
60+
end)
61+
62+
# html_elements =
63+
# Floki.traverse_and_update(html_elements, fn
64+
# el = {"tr", _attrs, _children} ->
65+
# case Floki.text(el) |> String.contains?(query) do
66+
# true -> el
67+
# false -> nil
68+
# end
69+
70+
# el ->
71+
# el
72+
# end)
73+
74+
results =
75+
Enum.map(html_elements, fn el ->
76+
html_feature = Floki.find(el, "td:first-of-type")
77+
implicit_semantics = Floki.find(el, "td:nth-of-type(2)")
78+
79+
%{
80+
heading: html_feature |> Floki.text(),
81+
implicit_semantics: implicit_semantics |> Floki.text(),
82+
html: el
83+
}
84+
end)
4985
end
5086

5187
def search_for(:wai_aria_practices, query) when is_binary(query) do

apps/components_guide_web/lib/components_guide_web/controllers/research_controller.ex

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ defmodule ComponentsGuideWeb.ResearchController do
7272
%{"error" => %{"code" => "PackageNotFoundError"}} ->
7373
content_tag(:p, "Not found")
7474

75+
%{"error" => _} ->
76+
[]
77+
7578
other ->
7679
inspect(other)
7780
end
@@ -132,6 +135,24 @@ defmodule ComponentsGuideWeb.ResearchController do
132135
end
133136
end
134137

138+
defp html_aria(query) do
139+
case Spec.search_for(:html_aria_spec, query) do
140+
results ->
141+
Enum.map(results, fn %{heading: heading, implicit_semantics: implicit_semantics} ->
142+
Section.card([
143+
content_tag(:h3, heading, class: "text-2xl"),
144+
content_tag(
145+
:dl,
146+
[
147+
content_tag(:dt, "Implicit semantics", class: "font-bold"),
148+
content_tag(:dd, "#{implicit_semantics}")
149+
]
150+
)
151+
])
152+
end)
153+
end
154+
end
155+
135156
defp load_results(query) when is_binary(query) do
136157
# ComponentsGuide.Research.Source.clear_cache()
137158
[
@@ -153,7 +174,7 @@ defmodule ComponentsGuideWeb.ResearchController do
153174
]),
154175
content_tag(:article, [
155176
h2("HTML ARIA"),
156-
Spec.search_for(:html_aria_spec, query) |> present_results()
177+
html_aria(query)
157178
])
158179
]
159180
end

apps/components_guide_web/lib/components_guide_web/templates/research/index.html.eex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<li><%= link("button", to: "?q=button") %>
1515
<li><%= link("contentinfo", to: "?q=contentinfo") %>
1616
<li><%= link("dialog", to: "?q=dialog") %>
17-
<li><%= link("menuitem", to: "?q=menuitem") %>
17+
<li><%= link("menu", to: "?q=menu") %>
1818
</ul>
1919
</dd>
2020
<dt>Third-party</dt>

0 commit comments

Comments
 (0)