Skip to content

Commit 240b168

Browse files
committed
Add searching of http status codes
1 parent fc1a5b3 commit 240b168

File tree

6 files changed

+105
-3
lines changed

6 files changed

+105
-3
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
defmodule ComponentsGuide.Research.Static do
2+
@http_statuses_list [
3+
{101, "Switching Protocols", ""},
4+
5+
{200, "OK", ""},
6+
{201, "Created", ""},
7+
{202, "Accepted", ""},
8+
{204, "No Content", ""},
9+
10+
{301, "Moved Permanently", ""},
11+
{302, "Found", ""},
12+
{303, "See Other", ""},
13+
{304, "Not Modified", ""},
14+
{307, "Temporary Redirect", ""},
15+
#{308, "Permanent Redirect", ""},
16+
17+
{400, "Bad Request", ""},
18+
{401, "Unauthorized", ""},
19+
{402, "Payment Required", ""},
20+
{403, "Forbidden", ""},
21+
{404, "Not Found", ""},
22+
{405, "Method Not Allowed", ""},
23+
{406, "Not Acceptable", ""},
24+
{409, "Conflict", ""},
25+
{410, "Gone", ""},
26+
{412, "Precondition Failed", ""},
27+
{422, "Unprocessable Entity", ""},
28+
{429, "Too Many Requests", ""},
29+
30+
{500, "Internal Server Error", ""},
31+
{501, "Not Implemented", ""},
32+
{502, "Bad Gateway", ""},
33+
{503, "Service Unavailable", ""},
34+
{504, "Gateway Timeout", ""},
35+
]
36+
37+
@http_statuses_map Map.new(@http_statuses_list, fn {status, name, description} -> {"#{status}", {name, description}} end)
38+
39+
@rfc_list [
40+
{"json", ["rfc8259", "rfc7159", "rfc4627"], "https://tools.ietf.org/html/rfc8259"},
41+
]
42+
43+
def search_for(query) when is_binary(query) do
44+
[
45+
search_for(:http_status, query)
46+
]
47+
end
48+
49+
defp search_for(:http_status, query) when is_binary(query) do
50+
query = query |> String.trim()
51+
case Map.get(@http_statuses_map, query) do
52+
nil ->
53+
nil
54+
55+
{name, description} ->
56+
{:ok, name, description}
57+
end
58+
end
59+
end
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
defmodule ComponentsGuideWeb.ElementsView do
2+
use ComponentsGuideWeb, :view
3+
end
4+
5+
defmodule ComponentsGuideWeb.ElementsController do
6+
use ComponentsGuideWeb, :controller
7+
8+
plug :put_root_layout, "turbo.html"
9+
plug :put_layout, false
10+
plug :put_view, ComponentsGuideWeb.IntegrationsView
11+
12+
def index(conn, %{"element_id" => "convertkit-form"}) do
13+
conn = merge_assigns(conn, frame_id: "convertkit-form")
14+
# conn = put_root_layout(conn, false)
15+
# conn = put_layout(conn, false)
16+
# rendered = Phoenix.View.render(ComponentsGuideWeb.IntegrationsView, "convertkit_form.html", [])
17+
# conn |> html(rendered)
18+
render(conn, "convertkit_form.html")
19+
end
20+
21+
def index(conn, params) do
22+
conn |> html("hello #{inspect(params)}")
23+
end
24+
end

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ defmodule ComponentsGuideWeb.ResearchController do
33
use Phoenix.HTML
44

55
alias ComponentsGuide.Research.Spec
6+
alias ComponentsGuide.Research.Static
67
alias ComponentsGuideWeb.ResearchView, as: View
78

89
def index(conn, %{"q" => query, "turbo" => _}) do
@@ -260,10 +261,26 @@ defmodule ComponentsGuideWeb.ResearchController do
260261
])
261262
end
262263
end
264+
265+
defp static(query) do
266+
for result <- Static.search_for(query) do
267+
case result do
268+
{:ok, name, description} ->
269+
Section.card([
270+
content_tag(:h3, name, class: "text-2xl"),
271+
content_tag(:p, description)
272+
])
273+
274+
_ ->
275+
""
276+
end
277+
end
278+
end
263279

264280
defp load_results(query) when is_binary(query) do
265281
# ComponentsGuide.Research.Source.clear_cache()
266282
[
283+
static(query),
267284
bundlephobia(query),
268285
npm_downloads(query),
269286
caniuse(query),

apps/components_guide_web/lib/components_guide_web/router.ex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ defmodule ComponentsGuideWeb.Router do
1616

1717
scope "/", ComponentsGuideWeb do
1818
pipe_through :browser
19+
20+
get "/elements/:element_id", ElementsController, :index
1921

2022
get "/", LandingController, :index
2123

apps/components_guide_web/lib/components_guide_web/templates/layout/_contentinfo.html.eex

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
<div class="X pt-8 pb-12">
77
<%= render ComponentsGuideWeb.IntegrationsView, "convertkit_form.html", [] %>
88
</div>
9-
10-
<turbo-frame id="footer" src="/random">
11-
</turbo-frame>
129

1310
<nav aria-label="Links">
1411
<ul class="list-none text-xs mt-4 leading-loose text-gray-500">
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<turbo-frame id="<%= @frame_id %>">
2+
<%= @inner_content %>
3+
</turbo-frame>

0 commit comments

Comments
 (0)