clean code

This commit is contained in:
zapashcanon 2022-12-06 00:12:14 +01:00
parent 97864116bb
commit 20f18bcd76
No known key found for this signature in database
GPG key ID: 8981C3C62D1D28F1
24 changed files with 99 additions and 894 deletions

View file

@ -1,6 +1,6 @@
open Tyxml
let render ~page_title ~scripts content =
let generic ~page_title ~scripts content =
let open Html in
let head =
head
@ -10,6 +10,26 @@ let render ~page_title ~scripts content =
]
@ scripts )
in
let body = body [ main [ content ] ] in
let body = body [ main [ div [ content ] ] ] in
let page = html head body in
Format.asprintf "%a@." (pp ~indent:true ()) page
let render ~title ~scripts content =
Dream.html @@ generic ~page_title:title ~scripts content
let err (status, msg) =
let code = Dream.status_to_int status in
Dream.html ~code @@ generic ~page_title:"Error" ~scripts:[] (Html.txt msg)
let error _error _debug_info suggested_response =
let status = Dream.status suggested_response in
let code = Dream.status_to_int status in
let reason = Dream.status_to_string status in
Dream.set_header suggested_response "Content-Type" Dream.text_html;
let content = Html.txt @@ Format.sprintf "%d: %s" code reason in
let body = generic ~page_title:"Error" ~scripts:[] content in
Dream.set_body suggested_response body;
Lwt.return suggested_response