From 6658535cf610d6c1d99dae20e98ced14a920dbb2 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 18 May 2025 17:02:32 +0200 Subject: Modularize everything. --- lib/handlers.ml | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'lib/handlers.ml') diff --git a/lib/handlers.ml b/lib/handlers.ml index 95aecd3..321c693 100644 --- a/lib/handlers.ml +++ b/lib/handlers.ml @@ -6,41 +6,39 @@ let ( let* ) m f = let msg = Format.asprintf "%a" Git_unix.Store.pp_error e in Views.error_page msg |> Dream_html.respond -let ogit_root _req = Views.ogit_root () |> Dream_html.respond +let root _req = Views.root () |> Dream_html.respond -let repo_summary req = - let repo_path = Dream.param req "repo_name" in - let branches = [ "bing"; "bong" ] in - let* commits = Git_helpers.recent_commits repo_path 10 in - Views.repo_summary repo_path branches commits |> Dream_html.respond +module Repo = struct + let repo_path req = Dream.param req "repo_name" -let repo_commit req = - let repo_path = Dream.param req "repo_name" in - let id = match Dream.query req "id" with Some id -> id | None -> "" in - let* commit = Git_helpers.get_commit repo_path id in - Views.repo_commit repo_path commit |> Dream_html.respond + let summary req = + let branches = Git_helpers.Branch.all_branches (repo_path req) in + let* commits = Git_helpers.Commit.recent_commits (repo_path req) 10 in + let authors = [ "John Pork"; "Sebastian Jellybean" ] in + Views.Repo.summary (repo_path req) branches commits authors + |> Dream_html.respond -(* let repo_tree req = *) -(* let repo_name = Dream.param req "repo_name" in *) -(* let path = Git_helpers.full_path repo_name in *) -(* let dir_path = Dream.target req in *) -(* Views.repo_tree ~repo_path:path dir_path |> Dream_html.respond *) + let refs req = Views.Repo.refs (repo_path req) |> Dream_html.respond + let log req = Views.Repo.log (repo_path req) |> Dream_html.respond + let tree req = Views.Repo.tree (repo_path req) |> Dream_html.respond -(* let repo_blob req = *) -(* let repo_name = Dream.param req "repo_name" in *) -(* let path = Git_helpers.full_path repo_name in *) -(* let blob_path = Dream.query req "path" |> Option.value ~default:"" in *) -(* Views.repo_blob repo_name blob_path |> Dream_html.respond *) + let commit req = + let id = match Dream.query req "id" with Some id -> id | None -> "" in + let* commit = Git_helpers.Commit.of_id (repo_path req) id in + Views.Repo.commit (repo_path req) commit |> Dream_html.respond +end let all_handlers = [ - Dream.get "/" ogit_root; + Dream.get "/" root; Dream.scope "/:repo_name" [] - [ - Dream.get "/" repo_summary; - Dream.get "/commit/" repo_commit; - (* Dream.get "/tree" repo_tree; *) - (* Dream.get "/blob" repo_blob; *) - ]; + Repo. + [ + Dream.get "/" summary; + Dream.get "/refs/" refs; + Dream.get "/log/" log; + Dream.get "/tree/" tree; + Dream.get "/commit/" commit; + ]; Dream.get "/static/**" (Dream.static "./lib/static"); ] -- cgit v1.2.3