From 8ab5f20f532bc6e9de38ee457b0ef8dd30c80374 Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Sun, 19 Jan 2025 20:00:18 +0100 Subject: Initial commit for ogit. --- lib/handlers/dune | 8 ++++++++ lib/handlers/handlers.ml | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/helpers/dune | 9 +++++++++ lib/helpers/file_helpers.ml | 7 +++++++ lib/helpers/html_helpers.ml | 18 ++++++++++++++++++ lib/layouts/dune | 16 ++++++++++++++++ lib/layouts/header.eml.html | 3 +++ lib/layouts/topnav.eml.html | 11 +++++++++++ 8 files changed, 115 insertions(+) create mode 100644 lib/handlers/dune create mode 100644 lib/handlers/handlers.ml create mode 100644 lib/helpers/dune create mode 100644 lib/helpers/file_helpers.ml create mode 100644 lib/helpers/html_helpers.ml create mode 100644 lib/layouts/dune create mode 100644 lib/layouts/header.eml.html create mode 100644 lib/layouts/topnav.eml.html (limited to 'lib') diff --git a/lib/handlers/dune b/lib/handlers/dune new file mode 100644 index 0000000..ae64b71 --- /dev/null +++ b/lib/handlers/dune @@ -0,0 +1,8 @@ +(library + (name handlers) + (public_name ogit.handlers) + (libraries + dream + ogit.helpers + ogit.layouts) + (modules handlers)) diff --git a/lib/handlers/handlers.ml b/lib/handlers/handlers.ml new file mode 100644 index 0000000..7142439 --- /dev/null +++ b/lib/handlers/handlers.ml @@ -0,0 +1,43 @@ +(* Page layout function *) +let page_layout ~content = + "" + ^ Layouts.Header.header () + ^ Layouts.Topnav.topnav () + ^ "
" ^ content ^ "
" + ^ "" + +let root _ = + let content = + "

Available Repositories

" + in + Dream.html (page_layout ~content) + +let repo_root _ = + (* let repo_name = Dream.param request "repo_name" in *) + let content = + "
\n" + ^ "\n" + ^ "\n" + ^ "\n" + ^ "\n" + ^ "\n" + ^ "\n" + ^ "\n" + ^ "\n" + ^ "
BranchCommit messageAuthorAge
masterEnsure session[:id] before scoring: all tests now pass.Marius Peter2 weeks
 
TagDownloadAuthorAge
v1.0commit 175111f9d8...Marius Peter2 weeks
 
AgeCommit messageAuthor
2025-01-02Ensure session[:id] before scoring: all tests now pass.HEADmasterMarius Peter
" + in + Dream.html (page_layout ~content) + +let repo_tree request = + let repo_name = Dream.param request "repo_name" in + let repo_path = Filename.concat (Unix.getenv "HOME") ("git/" ^ repo_name) in + let content = + if Sys.file_exists repo_path && Sys.is_directory repo_path then + let files = Helpers.File_helpers.list_files repo_path in + "

Browsing repository: " ^ repo_name ^ "

" + else + "

Repository not found: " ^ repo_name ^ "

" + in + Dream.html (page_layout ~content) diff --git a/lib/helpers/dune b/lib/helpers/dune new file mode 100644 index 0000000..a8c1733 --- /dev/null +++ b/lib/helpers/dune @@ -0,0 +1,9 @@ +(library + (name helpers) + (public_name ogit.helpers) + (libraries + unix + ogit.layouts) + (modules + html_helpers + file_helpers)) diff --git a/lib/helpers/file_helpers.ml b/lib/helpers/file_helpers.ml new file mode 100644 index 0000000..892d807 --- /dev/null +++ b/lib/helpers/file_helpers.ml @@ -0,0 +1,7 @@ +let list_files dir = + try + Array.to_list (Sys.readdir dir) + |> List.map (fun file -> Printf.sprintf "
  • %s
  • " file) + |> String.concat "" + with _ -> + "
  • Error: Unable to read directory
  • " diff --git a/lib/helpers/html_helpers.ml b/lib/helpers/html_helpers.ml new file mode 100644 index 0000000..da5addc --- /dev/null +++ b/lib/helpers/html_helpers.ml @@ -0,0 +1,18 @@ +(* Helper function to generate links for repositories *) +let generate_repo_links () = + let git_dir = Filename.concat (Unix.getenv "HOME") "git" in + if Sys.file_exists git_dir && Sys.is_directory git_dir then + Sys.readdir git_dir + |> Array.to_list + |> List.map (fun repo -> Printf.sprintf "
  • %s
  • " repo repo) + |> String.concat "" + else + "
  • Error: '~/git' directory not found.
  • " + +(* Page layout function *) +let page_layout ~content = + "" + ^ Layouts.Header.header () + ^ Layouts.Topnav.topnav () + ^ "
    " ^ content ^ "
    " + ^ "" diff --git a/lib/layouts/dune b/lib/layouts/dune new file mode 100644 index 0000000..ee236ea --- /dev/null +++ b/lib/layouts/dune @@ -0,0 +1,16 @@ +(library + (name layouts) + (public_name ogit.layouts) + (modules header topnav)) + +; Rule to preprocess header.eml.html +(rule + (targets header.ml) + (deps header.eml.html) + (action (run dream_eml %{deps} --workspace %{workspace_root}))) + +; Rule to preprocess topnav.eml.html +(rule + (targets topnav.ml) + (deps topnav.eml.html) + (action (run dream_eml %{deps} --workspace %{workspace_root}))) diff --git a/lib/layouts/header.eml.html b/lib/layouts/header.eml.html new file mode 100644 index 0000000..d7bf4ef --- /dev/null +++ b/lib/layouts/header.eml.html @@ -0,0 +1,3 @@ +let header _ = +

    ogit

    +

    Your mobile-friendly Git repository viewer.

    diff --git a/lib/layouts/topnav.eml.html b/lib/layouts/topnav.eml.html new file mode 100644 index 0000000..a9f0864 --- /dev/null +++ b/lib/layouts/topnav.eml.html @@ -0,0 +1,11 @@ +let topnav _ = + -- cgit v1.2.3