Add link_to route generator.

Commit
ffae61af1a13862ffc2bf9415313f5da3d90d38e
Author
Marius Peter <marius.peter@tutanota.com>
Author date
Committer
Marius Peter <marius.peter@tutanota.com>
Committer date
Changed files
lib/dune
index 0b351c09..8a236952 100644..100644
@@ -2,4 +2,6 @@
2 2
3 3 (library
4 4 (name ogit)
5 Removed: (libraries dream dream-html git-unix toml))
5 Added: (libraries dream dream-html git-unix toml)
6 Added: (preprocess (pps dream-html.ppx)))
7 Added:
lib/routes.ml
index 00000000..0778c18f 000000..100644
@@ -0,0 +1,30 @@
1 Added: (* -*- mode: tuareg; -*- *)
2 Added:
3 Added: open Dream_html
4 Added: open HTML
5 Added:
6 Added: type t =
7 Added: | Root
8 Added: | Repo of string
9 Added: | Tag of string * string
10 Added: | Commit of string * string
11 Added: | Tree of string * string * string
12 Added: | Blob of string * string * string
13 Added:
14 Added: let%path root_path = "/"
15 Added: let%path repo_path = "/%s"
16 Added: let%path tag_path = "/%s/refs/%s"
17 Added: let%path commit_path = "/%s/commit/%s"
18 Added: let%path tree_path = "/%s/tree/%s/%s"
19 Added: let%path blob_path = "/%s/blob/%s/%s"
20 Added:
21 Added: let path_attr = function
22 Added: | Root -> path_attr href root_path
23 Added: | Repo repo -> path_attr href repo_path repo
24 Added: | Tag (repo, branch) -> path_attr href tag_path repo branch
25 Added: | Commit (repo, commit) -> path_attr href commit_path repo commit
26 Added: | Tree (repo, commit, path) -> path_attr href tree_path repo commit path
27 Added: | Blob (repo, commit, path) -> path_attr href blob_path repo commit path
28 Added:
29 Added: let link_to label route = a [ path_attr route ] [ txt "%s" label ]
30 Added: let li_of_repo repo = li [] [ link_to repo (Repo repo) ]
lib/views.ml
index 986aa351..33654eae 100644..100644
@@ -82,10 +82,8 @@
82 82 Sys.readdir config.git_project_root
83 83 |> Array.to_list |> List.sort String.compare
84 84 in
85 Removed: let li_of_repo repo =
86 Removed: HTML.(li [] [ a [ href "%s/" repo ] [ txt "%s" repo ] ])
87 Removed: in
88 Removed: HTML.(div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ])
85 Added: HTML.(
86 Added: div [ id "repositories" ] [ ul [] @@ List.map Routes.li_of_repo repos ])
89 87 in
90 88 let body_data =
91 89 {
@@ -100,25 +98,25 @@
100 98 module Repo = struct
101 99 let page_title repo = Printf.sprintf "%s — %s" repo (repo_description repo)
102 100
101 Added: let li_of_branch repo branch =
102 Added: HTML.(li [] [ Routes.link_to branch.name (Tag (repo, branch.name)) ])
103 Added:
104 Added: let li_of_commit repo commit =
105 Added: match commit.message with
106 Added: | Some msg ->
107 Added: HTML.(
108 Added: li []
109 Added: [
110 Added: Routes.link_to
111 Added: (commit.short_hash ^ " - " ^ msg)
112 Added: (Commit (repo, commit.hash));
113 Added: ])
114 Added: | None -> HTML.(li [] [ txt "%s" commit.short_hash ])
115 Added:
103 116 let summary repo branches commits authors =
104 Removed: let li_of_branch branch =
105 Removed: HTML.(li [] [ a [ href "%s" branch.name ] [ txt "%s" branch.name ] ])
106 Removed: in
107 Removed: let li_of_commit commit =
108 Removed: match commit.message with
109 Removed: | Some msg ->
110 Removed: HTML.(
111 Removed: li []
112 Removed: [
113 Removed: a
114 Removed: [ href "commit/?id=%s" commit.hash ]
115 Removed: [ txt "%s %s" commit.short_hash msg ];
116 Removed: ])
117 Removed: | None -> HTML.(li [] [ a [ href "" ] [ txt "caca!!" ] ])
118 Removed: in
119 Removed: let li_of_author author =
120 Removed: HTML.(li [] [ a [ href "" ] [ txt "%s" author ] ])
121 Removed: in
117 Added: let li_of_branch = li_of_branch repo in
118 Added: let li_of_commit = li_of_commit repo in
119 Added: let li_of_author author = HTML.(li [] [ txt "%s" author ]) in
122 120 let content =
123 121 HTML.
124 122 [
@@ -139,9 +137,7 @@
139 137 }
140 138
141 139 let refs repo branches =
142 Removed: let li_of_branch branch =
143 Removed: HTML.(li [] [ a [ href "%s" branch.name ] [ txt "%s" branch.name ] ])
144 Removed: in
140 Added: let li_of_branch = li_of_branch repo in
145 141 let content =
146 142 HTML.[ h3 [] [ txt "Branches" ]; ul [] (List.map li_of_branch branches) ]
147 143 in
@@ -154,18 +150,7 @@
154 150 }
155 151
156 152 let log repo commits =
157 Removed: let li_of_commit commit =
158 Removed: match commit.message with
159 Removed: | Some msg ->
160 Removed: HTML.(
161 Removed: li []
162 Removed: [
163 Removed: a
164 Removed: [ href "commit/?id=%s" commit.hash ]
165 Removed: [ txt "%s %s" commit.short_hash msg ];
166 Removed: ])
167 Removed: | None -> HTML.(li [] [ a [ href "" ] [ txt "caca!!" ] ])
168 Removed: in
153 Added: let li_of_commit = li_of_commit repo in
169 154 let content =
170 155 HTML.
171 156 [ h3 [] [ txt "All commits" ]; ul [] (List.map li_of_commit commits) ]