First commit

This commit is contained in:
2025-03-16 20:30:59 -07:00
parent bf6cec2349
commit 6d0ef91d82
56 changed files with 4676 additions and 0 deletions
@@ -0,0 +1,24 @@
defmodule VocabAssistantWeb.ErrorHTML do
@moduledoc """
This module is invoked by your endpoint in case of errors on HTML requests.
See config/config.exs.
"""
use VocabAssistantWeb, :html
# If you want to customize your error pages,
# uncomment the embed_templates/1 call below
# and add pages to the error directory:
#
# * lib/vocab_assistant_web/controllers/error_html/404.html.heex
# * lib/vocab_assistant_web/controllers/error_html/500.html.heex
#
# embed_templates "error_html/*"
# The default is to render a plain text page based on
# the template name. For example, "404.html" becomes
# "Not Found".
def render(template, _assigns) do
Phoenix.Controller.status_message_from_template(template)
end
end
@@ -0,0 +1,21 @@
defmodule VocabAssistantWeb.ErrorJSON do
@moduledoc """
This module is invoked by your endpoint in case of errors on JSON requests.
See config/config.exs.
"""
# If you want to customize a particular status code,
# you may add your own clauses, such as:
#
# def render("500.json", _assigns) do
# %{errors: %{detail: "Internal Server Error"}}
# end
# By default, Phoenix returns the status message from
# the template name. For example, "404.json" becomes
# "Not Found".
def render(template, _assigns) do
%{errors: %{detail: Phoenix.Controller.status_message_from_template(template)}}
end
end
@@ -0,0 +1,21 @@
defmodule VocabAssistantWeb.PageController do
use VocabAssistantWeb, :controller
@sentences %{
"fox" => "The quick brown **fox** jumps over the lazy dog.",
"dog" => "The lazy **dog** jumps over the quick brown fox."
}
def home(conn, %{"word" => word}) do
sentence_md = @sentences[word] || VocabAssistant.generate_sentence(word)
{:ok, sentence, _messages} =
Earmark.as_html(sentence_md, compact_output: true, inner_html: true)
render(conn, :home, sentence: sentence, word: word)
end
def home(conn, _params) do
render(conn, :home, sentence: "Enter a word above to generate a sentence.")
end
end
@@ -0,0 +1,10 @@
defmodule VocabAssistantWeb.PageHTML do
@moduledoc """
This module contains pages rendered by PageController.
See the `page_html` directory for all templates available.
"""
use VocabAssistantWeb, :html
embed_templates "page_html/*"
end
@@ -0,0 +1,13 @@
<.flash_group flash={@flash} />
<div class="flex flex-col gap-4">
<h1 class="text-3xl font-bold">Welcome to Vocab Assistant</h1>
<form class="flex flex-row gap-4" method="GET" action={"/"}>
<input type="text" name="word" placeholder="Word" value={@word}/>
<button type="submit">Generate</button>
</form>
<div>
<p class="text-lg">
<%= raw @sentence %>
</p>
</div>
</div>