TEMPLATE: Added button page and handled first post request.
This commit is contained in:
parent
55c7c87ebf
commit
4a9f59717b
|
@ -7,7 +7,7 @@
|
|||
<body>
|
||||
<center>
|
||||
<h1>404 Not Found</h1>
|
||||
<p>Some Reason: ~(reason)</p>
|
||||
<p>Reason: ~(reason)</p>
|
||||
</center>
|
||||
</body>
|
||||
</html>
|
10
assets/html/button-page.html
Normal file
10
assets/html/button-page.html
Normal file
|
@ -0,0 +1,10 @@
|
|||
~(reason)
|
||||
|
||||
<form action="/action_page" method="get">
|
||||
<label for="fname">First name:</label>
|
||||
<input type="text" id="fname" name="fname"><br><br>
|
||||
<label for="lname">Last name:</label>
|
||||
<input type="text" id="lname" name="lname"><br><br>
|
||||
<button type="submit">Submit</button>
|
||||
<button type="submit" formmethod="post">Submit using POST</button>
|
||||
</form>
|
|
@ -11,9 +11,19 @@ defmodule RlRepo.Router do
|
|||
end
|
||||
|
||||
def route_1(path, request_type) do
|
||||
{200, "text/html", "Hi"}
|
||||
if request_type == "POST" do
|
||||
Logger.info("Post request handled!")
|
||||
end
|
||||
|
||||
if path == "/favicon.ico" do
|
||||
{200, "afdssadf", "1112"}
|
||||
end
|
||||
placeholders = %{"reason" => "Unknown"}
|
||||
|
||||
{200, "text/html", RlRepo.Template.template("button-page", placeholders)}
|
||||
end
|
||||
|
||||
|
||||
def route_3(path, request_type) do
|
||||
Logger.info("#{request_type}")
|
||||
{repo_name, pkg_name, action} = path
|
||||
|
|
|
@ -4,10 +4,19 @@ defmodule RlRepo.Template do
|
|||
def template(template_name, replacements) do
|
||||
Logger.info("Loading template #{template_name}")
|
||||
{:ok, body} = File.read("assets/html/#{template_name}.html")
|
||||
|
||||
len = body |> String.split("~(") |> length()
|
||||
|
||||
template_step(replacements, body, len)
|
||||
# TODO: Check if there is any actual placeholders
|
||||
v = String.contains?(body, "~(")
|
||||
Logger.info v
|
||||
# if v do
|
||||
len = body |> String.split("~(") |> length()
|
||||
Logger.info body
|
||||
# TODO: Math this out to be equal to the number of splits
|
||||
# if len >= 2 do
|
||||
template_step(replacements, body, len)
|
||||
# Logger.info "Len greater 2"
|
||||
# end
|
||||
# end
|
||||
# body
|
||||
end
|
||||
|
||||
def template_step(replacements, body, steps_left) do
|
||||
|
|
Loading…
Reference in a new issue