diff options
| author | Marius Peter <marius.peter@tutanota.com> | 2025-05-10 19:20:53 +0200 | 
|---|---|---|
| committer | Marius Peter <marius.peter@tutanota.com> | 2025-05-10 19:20:53 +0200 | 
| commit | ed813bd6035476a955dc8f1711889e7a4e62ed0d (patch) | |
| tree | eb34d09acc6d04cf2cce53ad8afe8756802c164e /lib | |
| parent | f94d27e3df990d9dd7dae69191dd05e5f691b0bb (diff) | |
Avoid opening HTML at the highest level in functions.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/views.ml | 82 | 
1 files changed, 39 insertions, 43 deletions
| diff --git a/lib/views.ml b/lib/views.ml index a362e40..cde27e7 100644 --- a/lib/views.ml +++ b/lib/views.ml @@ -14,7 +14,7 @@ module Layout = struct    let header title subtitle =      null [ h1 [] [ txt "%s" title ]; h2 [] [ txt "%s" subtitle ] ] -  let footer = +  let 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.author in @@ -37,16 +37,16 @@ module Layout = struct              header body_data.title body_data.subtitle;              body_data.topnav;              div [ id "main" ] body_data.content; -            footer; +            footer ();            ];        ]  end  module Components = struct    open Dream_html -  open HTML    let topnav repo_path current_path = +    let open HTML in      let li_of_a (path, text) =        let is_active = path = current_path in        let attrs = if is_active then [ id "active" ] else [] in @@ -74,23 +74,20 @@ end  let ogit_root () =    let open Dream_html in -  let open HTML in    let repositories_in directory = -    try -      let repos = -        Sys.readdir directory |> Array.to_list |> List.sort String.compare -      in -      let li_of_repo repo = li [] [ a [ href "%s/" repo ] [ txt "%s" repo ] ] in -      div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ] -    with Sys_error _ -> -      div [] [ txt "Error: Unable to read repository list." ] +    let repos = +      Sys.readdir directory |> Array.to_list |> List.sort String.compare +    in +    let li_of_repo repo = +      HTML.(li [] [ a [ href "%s/" repo ] [ txt "%s" repo ] ]) +    in +    HTML.(div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ])    in -    let body_data =      {        title = "Ogit";        subtitle = "Repositories for " ^ Config.author; -      topnav = null []; +      topnav = HTML.(null []);        content = [ repositories_in Config.git_directory ];      }    in @@ -98,50 +95,49 @@ let ogit_root () =  let repo_summary repo_path ~branches ~commits =    let open Dream_html in -  let open HTML in    let li_of_branch branch = -    li [] [ a [ href "%s" branch ] [ txt "%s" branch ] ] +    HTML.(li [] [ a [ href "%s" branch ] [ txt "%s" branch ] ])    in    let li_of_commit commit = -    li [] [ a [ href "%s" commit ] [ txt "%s" commit ] ] +    HTML.(li [] [ a [ href "%s" commit ] [ txt "%s" commit ] ])    in    let content = -    [ -      h3 [] [ txt "Branches" ]; -      ul [] (List.map li_of_branch branches); -      h3 [] [ txt "Recent commits" ]; -      ul [] (List.map li_of_commit commits); -    ] +    HTML. +      [ +        h3 [] [ txt "Branches" ]; +        ul [] (List.map li_of_branch branches); +        h3 [] [ txt "Recent commits" ]; +        ul [] (List.map li_of_commit commits); +      ]    in -  let body_data = +  Layout.application      {        title = repo_path;        subtitle = "Macaroniii";        topnav = Components.topnav repo_path "";        content;      } -  in -  Layout.application body_data  let error_page message =    let open Dream_html in -  let open HTML in -  html [] -    [ -      head [] -        [ -          title [] "Big error"; -          link [ rel "stylesheet"; href "/static/styles.css" ]; -          link [ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ]; -        ]; -      body [] -        [ -          h1 [] [ txt "Major error alert" ]; -          h2 [] [ txt "Major alert subtitle" ]; -          (* Components.topnav; *) -          div [ id "main" ] [ txt "%s" message ]; -        ]; -    ] +  HTML.( +    html [] +      [ +        head [] +          [ +            title [] "Big error"; +            link [ rel "stylesheet"; href "/static/styles.css" ]; +            link +              [ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ]; +          ]; +        body [] +          [ +            h1 [] [ txt "Major error alert" ]; +            h2 [] [ txt "Major alert subtitle" ]; +            (* Components.topnav; *) +            div [ id "main" ] [ txt "%s" message ]; +          ]; +      ])  let repo_tree repo_path = repo_summary repo_path  let repo_blob repo_path = repo_summary repo_path | 
