From 70822b178e06ef2b251d7b7b399bb03e122f79cb Mon Sep 17 00:00:00 2001 From: Able <abl3theabove@gmail.com> Date: Thu, 20 Feb 2025 03:59:08 -0600 Subject: [PATCH] FMT: mix fmt --- lib/client_handler.ex | 50 +++++++++++++++++-------------------------- lib/templating.ex | 6 +----- test/rl_repo_test.exs | 2 -- 3 files changed, 21 insertions(+), 37 deletions(-) diff --git a/lib/client_handler.ex b/lib/client_handler.ex index 34666ec..fe80f21 100644 --- a/lib/client_handler.ex +++ b/lib/client_handler.ex @@ -8,10 +8,10 @@ defmodule RlRepo.ClientHandler do Logger.info("Processing client request.") client_socket - |> read_request - |> create_response() - |> create_response_header() - |> write_response(client_socket) + |> read_request + |> create_response() + |> create_response_header() + |> write_response(client_socket) end def read_request(client_socket) do @@ -24,47 +24,37 @@ defmodule RlRepo.ClientHandler do def create_response(request) do # TODO: Split off the info I need from the request body and I guess pass it around also Logger.info("REQUEST BODY #{request}") - Logger.info("Building response body.") - - # TODO: Handle routing here. - a = String.split(request, "\n\r") - # Logger.info a - [get_line | rest] = a + [get_line | rest] = String.split(request, "\n\r") b = String.split(get_line, " ") [request_type | rest] = b [path | rest] = rest Logger.info("#{request_type} #{path}") - # Parse path + # Parse path ignoring leading and trailing slash split_path = String.split(path, "/", trim: true) - # Ignore the first slash. - # [_ | rest ] = split_path split_path_length = length(split_path) - ret = - case split_path_length do - 1 -> - RlRepo.Router.parse_1_segment_path(rest) - |> RlRepo.Router.route_1(request_type) + case split_path_length do + 1 -> + RlRepo.Router.parse_1_segment_path(rest) + |> RlRepo.Router.route_1(request_type) - 3 -> - RlRepo.Router.parse_3_segment_path(rest) - |> RlRepo.Router.route_3(request_type) + 3 -> + RlRepo.Router.parse_3_segment_path(rest) + |> RlRepo.Router.route_3(request_type) - 4 -> - RlRepo.Router.parse_4_segment_path(rest) - |> RlRepo.Router.route_4(request_type) + 4 -> + RlRepo.Router.parse_4_segment_path(rest) + |> RlRepo.Router.route_4(request_type) - # Note: Error handling. - _ -> - RlRepo.Router.status_404() - end - - ret + # Note: Error handling. + _ -> + RlRepo.Router.status_404() + end end def create_return_code_string(return_code) do diff --git a/lib/templating.ex b/lib/templating.ex index 1456d6a..d9a68e4 100644 --- a/lib/templating.ex +++ b/lib/templating.ex @@ -10,12 +10,8 @@ defmodule RlRepo.Template do def inner_template(body, replacements) do # TODO: Check if there is any actual placeholders - v = String.contains?(body, "~(") - # Logger.info(v) - + # v = String.contains?(body, "~(") len = body |> String.split("~(") |> length() - # Logger.info(body) - template_step(replacements, body, len) end diff --git a/test/rl_repo_test.exs b/test/rl_repo_test.exs index 86dc74d..e21d0a8 100644 --- a/test/rl_repo_test.exs +++ b/test/rl_repo_test.exs @@ -10,12 +10,10 @@ defmodule RlRepoTest do assert RlRepo.Template.inner_template(body, placeholders) == "DONE" end - test "multi template replace" do body = "~(replace)abc~(replace)" placeholders = %{"replace" => "DONE"} assert RlRepo.Template.inner_template(body, placeholders) == "DONEabcDONE" end - end