summaryrefslogtreecommitdiff
path: root/lib/views.ml
diff options
context:
space:
mode:
authorMarius Peter <marius.peter@tutanota.com>2025-06-15 16:30:36 +0200
committerMarius Peter <marius.peter@tutanota.com>2025-06-15 16:30:36 +0200
commit6e07594aace8bc2c6f99219b4022a68291201aad (patch)
tree45273d8853b780fd55228b858f652e415ef790fa /lib/views.ml
parentce1110973e02d803e747ffc49572db1abf709923 (diff)
Refactor Git_presenters to Resolvers.
What this module really does is resolve Git types to values usable by ogit views.
Diffstat (limited to 'lib/views.ml')
-rw-r--r--lib/views.ml81
1 files changed, 39 insertions, 42 deletions
diff --git a/lib/views.ml b/lib/views.ml
index e65a249..fc211c5 100644
--- a/lib/views.ml
+++ b/lib/views.ml
@@ -11,8 +11,6 @@ type body_data = {
}
module Components = struct
- open Dream_html
-
module Topnav = struct
type t = None | Summary | Log | Files | Refs
@@ -36,23 +34,21 @@ module Components = struct
end
module Page = struct
- open Dream_html
- open HTML
-
- let header title subtitle =
- let subtitle =
- if String.starts_with ~prefix:"Unnamed repository" subtitle then ""
- else subtitle
+ let page_header header1 header2 =
+ let header2 =
+ if String.starts_with ~prefix:"Unnamed repository" header2 then ""
+ else header2
in
- null [ h1 [] [ txt "%s" title ]; h2 [] [ txt "%s" subtitle ] ]
+ HTML.(null [ h1 [] [ txt "%s" header1 ]; h2 [] [ txt "%s" header2 ] ])
- let footer () =
+ let page_footer () =
let today = Unix.localtime (Unix.time ()) in
let year = string_of_int (today.Unix.tm_year + 1900) in
let footer_text = Printf.sprintf "Copyright %s %s" year config.user in
- footer [] [ txt "%s" footer_text ]
+ HTML.footer [] [ txt "%s" footer_text ]
let render ?(page_title = "Ogit") body_data =
+ let open HTML in
html []
[
head []
@@ -64,10 +60,10 @@ module Page = struct
];
body []
[
- header body_data.title body_data.subtitle;
+ page_header body_data.title body_data.subtitle;
body_data.topnav;
div [ id "main" ] body_data.content;
- footer ();
+ page_footer ();
];
]
end
@@ -76,7 +72,7 @@ let root () =
let all_repositories =
let repos =
Sys.readdir config.git_project_root
- |> Array.to_list (* |> List.sort String.compare *)
+ |> Array.to_list |> List.sort String.compare
in
let li_of_repo repo =
HTML.li [] [ Routes.link_to (Routes.Repo repo) (txt "%s" repo) ]
@@ -94,7 +90,7 @@ let root () =
respond @@ Page.render body_data
module Repo = struct
- open Git_presenters
+ open Resolvers
let page_title repo = Printf.sprintf "%s — %s" repo (repo_description repo)
let li_of_author author = HTML.(li [] [ txt "%s" author ])
@@ -242,29 +238,30 @@ module Repo = struct
end
let error_page message =
- HTML.(
- html []
- [
- head []
- [
- title [] "Fatal error";
- link [ rel "stylesheet"; href "/static/styles.css" ];
- link
- [ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ];
- ];
- body []
- [
- h1 [] [ txt "Fatal Error" ];
- div
- [ id "main" ]
- [
- p [] [ b [] [ txt "%s" message ] ];
- p []
- [
- txt
- "Your best course of action is to press the 'back' \
- button in your browser.";
- ];
- ];
- ];
- ])
+ let open HTML in
+ respond
+ @@ html []
+ [
+ head []
+ [
+ title [] "Fatal error";
+ link [ rel "stylesheet"; href "/static/styles.css" ];
+ link
+ [ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ];
+ ];
+ body []
+ [
+ h1 [] [ txt "Fatal Error" ];
+ div
+ [ id "main" ]
+ [
+ p [] [ b [] [ txt "%s" message ] ];
+ p []
+ [
+ txt
+ "Your best course of action is to press the 'back' \
+ button in your browser.";
+ ];
+ ];
+ ];
+ ]
Copyright 2019--2025 Marius PETER