[OCaml] Mobile-friendly clone of cgit.
Avoid opening HTML at the highest level in functions.
lib/views.ml
@@ -14,7 +14,7 @@
14
14
let header title subtitle =
15
15
null [ h1 [] [ txt "%s" title ]; h2 [] [ txt "%s" subtitle ] ]
16
16
17
Removed:
let footer =
17
Added:
let footer () =
18
18
let today = Unix.localtime (Unix.time ()) in
19
19
let year = string_of_int (today.Unix.tm_year + 1900) in
20
20
let footer_text = Printf.sprintf "Copyright %s %s" year Config.author in
@@ -37,16 +37,16 @@
37
37
header body_data.title body_data.subtitle;
38
38
body_data.topnav;
39
39
div [ id "main" ] body_data.content;
40
Removed:
footer;
40
Added:
footer ();
41
41
];
42
42
]
43
43
end
44
44
45
45
module Components = struct
46
46
open Dream_html
47
Removed:
open HTML
48
47
49
48
let topnav repo_path current_path =
49
Added:
let open HTML in
50
50
let li_of_a (path, text) =
51
51
let is_active = path = current_path in
52
52
let attrs = if is_active then [ id "active" ] else [] in
@@ -74,23 +74,20 @@
74
74
75
75
let ogit_root () =
76
76
let open Dream_html in
77
Removed:
let open HTML in
78
77
let repositories_in directory =
79
Removed:
try
80
Removed:
let repos =
81
Removed:
Sys.readdir directory |> Array.to_list |> List.sort String.compare
82
Removed:
in
83
Removed:
let li_of_repo repo = li [] [ a [ href "%s/" repo ] [ txt "%s" repo ] ] in
84
Removed:
div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ]
85
Removed:
with Sys_error _ ->
86
Removed:
div [] [ txt "Error: Unable to read repository list." ]
78
Added:
let repos =
79
Added:
Sys.readdir directory |> Array.to_list |> List.sort String.compare
80
Added:
in
81
Added:
let li_of_repo repo =
82
Added:
HTML.(li [] [ a [ href "%s/" repo ] [ txt "%s" repo ] ])
83
Added:
in
84
Added:
HTML.(div [ id "repositories" ] [ ul [] @@ List.map li_of_repo repos ])
87
85
in
88
Removed:
89
86
let body_data =
90
87
{
91
88
title = "Ogit";
92
89
subtitle = "Repositories for " ^ Config.author;
93
Removed:
topnav = null [];
90
Added:
topnav = HTML.(null []);
94
91
content = [ repositories_in Config.git_directory ];
95
92
}
96
93
in
@@ -98,50 +95,49 @@
98
95
99
96
let repo_summary repo_path ~branches ~commits =
100
97
let open Dream_html in
101
Removed:
let open HTML in
102
98
let li_of_branch branch =
103
Removed:
li [] [ a [ href "%s" branch ] [ txt "%s" branch ] ]
99
Added:
HTML.(li [] [ a [ href "%s" branch ] [ txt "%s" branch ] ])
104
100
in
105
101
let li_of_commit commit =
106
Removed:
li [] [ a [ href "%s" commit ] [ txt "%s" commit ] ]
102
Added:
HTML.(li [] [ a [ href "%s" commit ] [ txt "%s" commit ] ])
107
103
in
108
104
let content =
109
Removed:
[
110
Removed:
h3 [] [ txt "Branches" ];
111
Removed:
ul [] (List.map li_of_branch branches);
112
Removed:
h3 [] [ txt "Recent commits" ];
113
Removed:
ul [] (List.map li_of_commit commits);
114
Removed:
]
105
Added:
HTML.
106
Added:
[
107
Added:
h3 [] [ txt "Branches" ];
108
Added:
ul [] (List.map li_of_branch branches);
109
Added:
h3 [] [ txt "Recent commits" ];
110
Added:
ul [] (List.map li_of_commit commits);
111
Added:
]
115
112
in
116
Removed:
let body_data =
113
Added:
Layout.application
117
114
{
118
115
title = repo_path;
119
116
subtitle = "Macaroniii";
120
117
topnav = Components.topnav repo_path "";
121
118
content;
122
119
}
123
Removed:
in
124
Removed:
Layout.application body_data
125
120
126
121
let error_page message =
127
122
let open Dream_html in
128
Removed:
let open HTML in
129
Removed:
html []
130
Removed:
[
131
Removed:
head []
132
Removed:
[
133
Removed:
title [] "Big error";
134
Removed:
link [ rel "stylesheet"; href "/static/styles.css" ];
135
Removed:
link [ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ];
136
Removed:
];
137
Removed:
body []
138
Removed:
[
139
Removed:
h1 [] [ txt "Major error alert" ];
140
Removed:
h2 [] [ txt "Major alert subtitle" ];
141
Removed:
(* Components.topnav; *)
142
Removed:
div [ id "main" ] [ txt "%s" message ];
143
Removed:
];
144
Removed:
]
123
Added:
HTML.(
124
Added:
html []
125
Added:
[
126
Added:
head []
127
Added:
[
128
Added:
title [] "Big error";
129
Added:
link [ rel "stylesheet"; href "/static/styles.css" ];
130
Added:
link
131
Added:
[ rel "icon"; type_ "image/x-icon"; href "/static/git_icon.svg" ];
132
Added:
];
133
Added:
body []
134
Added:
[
135
Added:
h1 [] [ txt "Major error alert" ];
136
Added:
h2 [] [ txt "Major alert subtitle" ];
137
Added:
(* Components.topnav; *)
138
Added:
div [ id "main" ] [ txt "%s" message ];
139
Added:
];
140
Added:
])
145
141
146
142
let repo_tree repo_path = repo_summary repo_path
147
143
let repo_blob repo_path = repo_summary repo_path