@@ -53,24 +53,27 @@ defmodule ComponentsGuideWeb.ResearchController do
5353 % { "name" => name , "size" => size , "gzip" => size_gzip , "version" => version } ->
5454 emerging_3g_ms = floor ( size_gzip / 50 )
5555
56- Section . card ( [
57- content_tag ( :h3 , "#{ name } @#{ version } " , class: "text-2xl" ) ,
58- content_tag (
59- :dl ,
60- [
61- content_tag ( :dt , "Minified" , class: "font-bold" ) ,
62- content_tag ( :dd , "#{ size } " ) ,
63- content_tag ( :dt , "Minified + Gzipped" , class: "font-bold" ) ,
64- content_tag ( :dd , "#{ size_gzip } " ) ,
65- content_tag ( :dt , "Emerging 3G (50kB/s)" , class: "font-bold" ) ,
66- content_tag ( :dd , "#{ emerging_3g_ms } ms" )
67- ] ,
68- class: "grid grid-flow-col grid-rows-2"
69- )
56+ content_tag ( :article , [
57+ h2 ( "Bundlephobia" ) ,
58+ Section . card ( [
59+ content_tag ( :h3 , "#{ name } @#{ version } " , class: "text-2xl" ) ,
60+ content_tag (
61+ :dl ,
62+ [
63+ content_tag ( :dt , "Minified" , class: "font-bold" ) ,
64+ content_tag ( :dd , "#{ size } " ) ,
65+ content_tag ( :dt , "Minified + Gzipped" , class: "font-bold" ) ,
66+ content_tag ( :dd , "#{ size_gzip } " ) ,
67+ content_tag ( :dt , "Emerging 3G (50kB/s)" , class: "font-bold" ) ,
68+ content_tag ( :dd , "#{ emerging_3g_ms } ms" )
69+ ] ,
70+ class: "grid grid-flow-col grid-rows-2"
71+ )
72+ ] )
7073 ] )
7174
72- % { "error" => % { "code" => "PackageNotFoundError" } } ->
73- content_tag ( :p , "Not found" )
75+ # %{"error" => %{"code" => "PackageNotFoundError"}} ->
76+ # content_tag(:p, "Not found")
7477
7578 % { "error" => _ } ->
7679 [ ]
@@ -119,63 +122,79 @@ defmodule ComponentsGuideWeb.ResearchController do
119122
120123 defp caniuse ( query ) do
121124 case Spec . search_for ( :caniuse , query ) do
125+ [ ] ->
126+ [ ]
127+
122128 results ->
123- CanIUse . present ( results )
129+ content_tag ( :article , [
130+ h2 ( "Can I Use" ) ,
131+ CanIUse . present ( results )
132+ ] )
133+ end
134+ end
135+
136+ defp html_spec ( query ) do
137+ case Spec . search_for ( :whatwg_html_spec , query ) do
138+ [ ] ->
139+ [ ]
140+
141+ results ->
142+ content_tag ( :article , [
143+ h2 ( "HTML spec" ) ,
144+ results |> present_results ( )
145+ ] )
124146 end
125147 end
126148
127149 defp aria_practices ( query ) do
128150 case Spec . search_for ( :wai_aria_practices , query ) do
151+ [ ] ->
152+ [ ]
153+
129154 results ->
130- Enum . map ( results , fn % { heading: heading } ->
131- Section . card ( [
132- content_tag ( :h3 , heading )
133- ] )
134- end )
155+ content_tag ( :article , [
156+ h2 ( "ARIA Practices" ) ,
157+ Enum . map ( results , fn % { heading: heading } ->
158+ Section . card ( [
159+ content_tag ( :h3 , heading )
160+ ] )
161+ end )
162+ ] )
135163 end
136164 end
137165
138166 defp html_aria ( query ) do
139167 case Spec . search_for ( :html_aria_spec , query ) do
168+ [ ] ->
169+ [ ]
170+
140171 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 )
172+ content_tag ( :article , [
173+ h2 ( "HTML ARIA" ) ,
174+ Enum . map ( results , fn % { heading: heading , implicit_semantics: implicit_semantics } ->
175+ Section . card ( [
176+ content_tag ( :h3 , heading , class: "text-2xl" ) ,
177+ content_tag (
178+ :dl ,
179+ [
180+ content_tag ( :dt , "Implicit semantics" , class: "font-bold" ) ,
181+ content_tag ( :dd , "#{ implicit_semantics } " )
182+ ]
183+ )
184+ ] )
185+ end )
186+ ] )
153187 end
154188 end
155189
156190 defp load_results ( query ) when is_binary ( query ) do
157191 # ComponentsGuide.Research.Source.clear_cache()
158192 [
159- content_tag ( :article , [
160- h2 ( "Bundlephobia" ) ,
161- bundlephobia ( query )
162- ] ) ,
163- content_tag ( :article , [
164- h2 ( "Can I Use" ) ,
165- caniuse ( query )
166- ] ) ,
167- content_tag ( :article , [
168- h2 ( "HTML spec" ) ,
169- Spec . search_for ( :whatwg_html_spec , query ) |> present_results ( )
170- ] ) ,
171- content_tag ( :article , [
172- h2 ( "ARIA Practices" ) ,
173- aria_practices ( query )
174- ] ) ,
175- content_tag ( :article , [
176- h2 ( "HTML ARIA" ) ,
177- html_aria ( query )
178- ] )
193+ bundlephobia ( query ) ,
194+ caniuse ( query ) ,
195+ html_spec ( query ) ,
196+ aria_practices ( query ) ,
197+ html_aria ( query )
179198 ]
180199 end
181200end
0 commit comments