Skip to content

Commit 30daf49

Browse files
committed
Add research page
1 parent 900efff commit 30daf49

File tree

9 files changed

+84
-1
lines changed

9 files changed

+84
-1
lines changed

Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,6 @@ install_assets:
1010

1111
dev:
1212
iex -S mix phx.server
13+
14+
clean:
15+
rm -rf ./_build
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
defmodule ComponentsGuide.HTTPClient do
2+
use Tesla #, only: [:get]
3+
4+
plug Tesla.Middleware.FollowRedirects, max_redirects: 3
5+
plug Tesla.Middleware.Timeout, timeout: 30_000
6+
7+
end

apps/components_guide/mix.exs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ defmodule ComponentsGuide.MixProject do
3939
{:cachex, "~> 3.1"},
4040
{:ecto, "~> 3.1.4"},
4141
{:httpotion, "~> 3.1.0"},
42-
{:jason, "~> 1.0"}
42+
{:jason, "~> 1.0"},
43+
{:tesla, "~> 1.3.0"},
4344
]
4445
end
4546

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
defmodule ComponentsGuideWeb.ResearchController do
2+
use ComponentsGuideWeb, :controller
3+
4+
alias ComponentsGuide.HTTPClient
5+
6+
def index(conn, %{"q" => query}) do
7+
query = query |> String.trim()
8+
9+
case query do
10+
"" ->
11+
render(conn, "empty.html")
12+
13+
query ->
14+
results = load_results(query)
15+
render(conn, "index.html", %{query: query, results: results})
16+
end
17+
end
18+
19+
def index(conn, _params) do
20+
index(conn, %{"q" => ""})
21+
end
22+
23+
defp load_results(query) when is_binary(query) do
24+
url = "https://html.spec.whatwg.org/"
25+
result = HTTPClient.get(url)
26+
{:ok, response} = result
27+
html = response.body
28+
html
29+
end
30+
end

apps/components_guide_web/lib/components_guide_web/router.ex

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

2020
get "/", LandingController, :index
2121

22+
get "/research", ResearchController, :index
23+
2224
get "/concepts", ConceptsController, :index
2325

2426
get "/links", LinksController, :index
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<header class="text-white">
2+
<section class="container px-6 pt-12 pb-12">
3+
<h2 class="mx-auto max-w-4xl text-5xl text-center font-bold leading-tight text-shadow">
4+
<%= "Research 🔍 specs and implementations" %>
5+
</h2>
6+
</section>
7+
</header>
8+
9+
<div class="bg-white py-16">
10+
<div class="container px-6">
11+
<h1>No query</h1>
12+
</div>
13+
</div>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<header class="text-white">
2+
<section class="container px-6 pt-12 pb-12">
3+
<h2 class="mx-auto max-w-4xl text-5xl text-center font-bold leading-tight text-shadow">
4+
<%= "Research 🔍 specs and implementations" %>
5+
</h2>
6+
</section>
7+
</header>
8+
9+
<div class="bg-white py-16">
10+
<div class="container px-6">
11+
<h1>
12+
Results for
13+
<strong><%= @query %></strong>:
14+
</h1>
15+
<%= @results %>
16+
</div>
17+
</div>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule ComponentsGuideWeb.ResearchView do
2+
use ComponentsGuideWeb, :view
3+
4+
def results(query) do
5+
~E"""
6+
Content!
7+
"""
8+
end
9+
end

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@
2525
"plug_crypto": {:hex, :plug_crypto, "1.0.0", "18e49317d3fa343f24620ed22795ec29d4a5e602d52d1513ccea0b07d8ea7d4d", [:mix], [], "hexpm", "73c1682f0e414cfb5d9b95c8e8cd6ffcfdae699e3b05e1db744e58b7be857759"},
2626
"ranch": {:hex, :ranch, "1.7.1", "6b1fab51b49196860b733a49c07604465a47bdb78aa10c1c16a3d199f7f8c881", [:rebar3], [], "hexpm", "451d8527787df716d99dc36162fca05934915db0b6141bbdac2ea8d3c7afc7d7"},
2727
"sleeplocks": {:hex, :sleeplocks, "1.1.1", "3d462a0639a6ef36cc75d6038b7393ae537ab394641beb59830a1b8271faeed3", [:rebar3], [], "hexpm", "84ee37aeff4d0d92b290fff986d6a95ac5eedf9b383fadfd1d88e9b84a1c02e1"},
28+
"tesla": {:hex, :tesla, "1.3.3", "26ae98627af5c406584aa6755ab5fc96315d70d69a24dd7f8369cfcb75094a45", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "~> 4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2648f1c276102f9250299e0b7b57f3071c67827349d9173f34c281756a1b124c"},
2829
"unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm", "6c7729a2d214806450d29766abc2afaa7a2cbecf415be64f36a6691afebb50e5"},
2930
}

0 commit comments

Comments
 (0)