[OCaml] Mobile-friendly clone of cgit.
Refactor views.
Changed files
lib/handlers.ml
@@ -29,7 +29,7 @@
29
29
30
30
let file_id req =
31
31
let repo = Dream.param req "repo" in
32
Removed:
let id = Dream.param req "repo" in
32
Added:
let id = Dream.param req "id" in
33
33
let* blob = Resolvers.Blob.of_id repo id in
34
34
Views.Repo.file repo blob
35
35
@@ -56,7 +56,7 @@
56
56
get "/summary/" summary;
57
57
get "/log/" log;
58
58
get "/files/" files_at_head;
59
Removed:
get "/files/:id" file_id;
59
Added:
get "/file/:id" file_id;
60
60
get "/refs/" refs;
61
61
get "/commit/:id" commit;
62
62
];
lib/resolvers.ml
@@ -122,10 +122,9 @@
122
122
let of_id repo id =
123
123
let* store = store repo in
124
124
let hash = Store.Hash.of_hex id in
125
Removed:
Store.read store hash
126
Removed:
|> Lwt_result.map @@ function
127
Removed:
| Git.Value.Tree tree -> to_t tree
128
Removed:
| _ -> failwith "no head tree id"
125
Added:
Lwt_result.bind (Store.read store hash) @@ function
126
Added:
| Git.Value.Tree tree -> to_t tree |> Lwt_result.return
127
Added:
| _ -> `Msg "no head tree id" |> Lwt_result.fail
129
128
130
129
let head repo : (t, Store.error) Lwt_result.t =
131
130
let* store = store repo in
lib/views.ml
@@ -79,15 +79,14 @@
79
79
in
80
80
HTML.(div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ])
81
81
in
82
Removed:
let body_data =
83
Removed:
{
84
Removed:
title = "Ogit";
85
Removed:
subtitle = "Repositories for " ^ config.user;
86
Removed:
topnav = HTML.null [];
87
Removed:
content = [ all_repositories ];
88
Removed:
}
89
Removed:
in
90
Removed:
respond @@ Page.render body_data
82
Added:
respond
83
Added:
@@ Page.render
84
Added:
{
85
Added:
title = "Ogit";
86
Added:
subtitle = "Repositories for " ^ config.user;
87
Added:
topnav = HTML.null [];
88
Added:
content = [ all_repositories ];
89
Added:
}
91
90
92
91
module Repo = struct
93
92
let page_title repo =
@@ -100,22 +99,17 @@
100
99
101
100
let li_of_commit repo (commit : Resolvers.Commit.t) =
102
101
let short_hash = Resolvers.short_hash commit.hash in
103
Removed:
let content =
102
Added:
let hash_span =
103
Added:
HTML.(span [ class_ "commit-hash" ] [ txt "%s" short_hash ])
104
Added:
in
105
Added:
let description =
104
106
match commit.message with
105
Removed:
| None -> txt "%s" short_hash
106
Removed:
| Some msg ->
107
Removed:
let route = Routes.Commit (repo, commit.hash) in
108
Removed:
let node =
109
Removed:
HTML.(
110
Removed:
null
111
Removed:
[
112
Removed:
span [ class_ "commit-hash" ] [ txt "%s" short_hash ];
113
Removed:
txt " — %s" msg;
114
Removed:
])
115
Removed:
in
116
Removed:
Routes.link_to route node
107
Added:
| None -> HTML.null []
108
Added:
| Some msg -> txt " %s" msg
117
109
in
118
Removed:
HTML.li [] [ content ]
110
Added:
let route = Routes.Commit (repo, commit.hash) in
111
Added:
let node = HTML.null [ hash_span; description ] in
112
Added:
HTML.li [] [ Routes.link_to route node ]
119
113
120
114
let li_of_entry repo (entry : Resolvers.Entry.t) =
121
115
let display_name =
@@ -128,79 +122,70 @@
128
122
HTML.(li [] [ Routes.link_to route @@ txt "%s" display_name ])
129
123
130
124
let summary repo branches commits authors =
131
Removed:
let content =
132
Removed:
HTML.
133
Removed:
[
134
Removed:
h3 [] [ txt "Branches" ];
135
Removed:
ul [] (List.map (li_of_branch repo) branches);
136
Removed:
h3 [] [ txt "Latest commits" ];
137
Removed:
ul [] (List.map (li_of_commit repo) commits);
138
Removed:
h3 [] [ txt "Authors" ];
139
Removed:
ul [] (List.map li_of_author authors);
140
Removed:
]
141
Removed:
in
142
125
respond
143
126
@@ Page.render ~page_title:(page_title repo)
144
127
{
145
128
title = repo;
146
129
subtitle = Resolvers.repo_description repo;
147
130
topnav = Components.Topnav.(v ~active_path:Summary repo);
148
Removed:
content;
131
Added:
content =
132
Added:
HTML.
133
Added:
[
134
Added:
h3 [] [ txt "Branches" ];
135
Added:
ul [] (List.map (li_of_branch repo) branches);
136
Added:
h3 [] [ txt "Latest commits" ];
137
Added:
ul [] (List.map (li_of_commit repo) commits);
138
Added:
h3 [] [ txt "Authors" ];
139
Added:
ul [] (List.map li_of_author authors);
140
Added:
];
149
141
}
150
142
151
143
let refs repo branches =
152
Removed:
let content =
153
Removed:
HTML.
154
Removed:
[
155
Removed:
h3 [] [ txt "Branches" ];
156
Removed:
ul [] (List.map (li_of_branch repo) branches);
157
Removed:
]
158
Removed:
in
159
144
respond
160
145
@@ Page.render ~page_title:(page_title repo)
161
146
{
162
147
title = repo;
163
148
subtitle = Resolvers.repo_description repo;
164
149
topnav = Components.Topnav.(v ~active_path:Refs repo);
165
Removed:
content;
150
Added:
content =
151
Added:
HTML.
152
Added:
[
153
Added:
h3 [] [ txt "Branches" ];
154
Added:
ul [] (List.map (li_of_branch repo) branches);
155
Added:
];
166
156
}
167
157
168
158
let log repo commits =
169
Removed:
let content =
170
Removed:
HTML.
171
Removed:
[
172
Removed:
h3 [] [ txt "All commits" ];
173
Removed:
ul [] (List.map (li_of_commit repo) commits);
174
Removed:
]
175
Removed:
in
176
159
respond
177
160
@@ Page.render ~page_title:(page_title repo)
178
161
{
179
162
title = repo;
180
163
subtitle = Resolvers.repo_description repo;
181
164
topnav = Components.Topnav.(v ~active_path:Log repo);
182
Removed:
content;
165
Added:
content =
166
Added:
HTML.
167
Added:
[
168
Added:
h3 [] [ txt "All commits" ];
169
Added:
ul [] (List.map (li_of_commit repo) commits);
170
Added:
];
183
171
}
184
172
185
173
let files repo (tree : Resolvers.Tree.t) =
186
Removed:
let content =
187
Removed:
HTML.
188
Removed:
[
189
Removed:
h3 [] [ txt "Files %s" @@ Resolvers.short_hash tree.hash ];
190
Removed:
ul [] (List.map (li_of_entry repo) tree.entries);
191
Removed:
]
192
Removed:
in
193
174
respond
194
175
@@ Page.render ~page_title:(page_title repo)
195
176
{
196
177
title = Printf.sprintf "%s" repo;
197
178
subtitle = Resolvers.repo_description repo;
198
179
topnav = Components.Topnav.(v ~active_path:Files repo);
199
Removed:
content;
180
Added:
content =
181
Added:
HTML.
182
Added:
[
183
Added:
h3 [] [ txt "Files %s" @@ Resolvers.short_hash tree.hash ];
184
Added:
ul [] (List.map (li_of_entry repo) tree.entries);
185
Added:
];
200
186
}
201
187
202
188
let file repo (blob : Resolvers.Blob.t) =
203
Removed:
let title = Printf.sprintf "%s" repo in
204
189
let to_numbered_line number line =
205
190
let n = number + 1 in
206
191
HTML.
@@ -213,31 +198,26 @@
213
198
String.split_on_char '\n' blob.content
214
199
|> List.mapi to_numbered_line |> List.flatten
215
200
in
216
Removed:
let content =
217
Removed:
HTML.[ h3 [] [ txt "File" ]; div [ id "blob" ] formatted_blob ]
218
Removed:
in
219
201
respond
220
202
@@ Page.render ~page_title:(page_title repo)
221
203
{
222
Removed:
title;
204
Added:
title = Printf.sprintf "%s" repo;
223
205
subtitle = Resolvers.repo_description repo;
224
Removed:
topnav = Components.Topnav.(v ~active_path:Files repo);
225
Removed:
content;
206
Added:
topnav = Components.Topnav.v ~active_path:Files repo;
207
Added:
content =
208
Added:
HTML.[ h3 [] [ txt "File" ]; div [ id "blob" ] formatted_blob ];
226
209
}
227
210
228
211
let commit repo (commit : Resolvers.Commit.t) =
229
212
let message = match commit.message with Some msg -> msg | None -> "" in
230
Removed:
let title =
231
Removed:
Printf.sprintf "%s : %s" repo @@ Resolvers.short_hash commit.hash
232
Removed:
in
233
Removed:
let content = HTML.[ h3 [] [ txt "%s" message ] ] in
234
213
respond
235
214
@@ Page.render ~page_title:(page_title repo)
236
215
{
237
Removed:
title;
216
Added:
title =
217
Added:
Printf.sprintf "%s : %s" repo @@ Resolvers.short_hash commit.hash;
238
218
subtitle = Resolvers.repo_description repo;
239
219
topnav = Components.Topnav.v repo;
240
Removed:
content;
220
Added:
content = HTML.[ h3 [] [ txt "%s" message ] ];
241
221
}
242
222
end
243
223