Skip to content

Commit 0f32a5b

Browse files
committed
Add source pages to docs
1 parent 3cf5cfb commit 0f32a5b

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

asset/css/doc.css

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,15 @@ div.odoc .comment-delim {
325325
border-color: rgb(32, 68, 165);
326326
}
327327

328+
.navmap-tag.source-tag::after {
329+
content: "S";
330+
}
331+
.source-tag{
332+
color: rgb(97, 8, 138);
333+
background-color: rgb(97, 8, 138);
334+
border-color: rgb(97, 8, 138);
335+
}
336+
328337
span.icon-expand > .navmap-tag,
329338
span.no-expand > .navmap-tag {
330339
color: white;
@@ -372,3 +381,34 @@ span.sign-expand.open::before {
372381
/* Lists of modules */
373382

374383
.modules { list-style-type: none; padding-left:0; }
384+
385+
/* Source links float inside preformated text or headings. */
386+
a.source_link {
387+
float: right;
388+
color: var(--source-link-color);
389+
font-family: "Fira Sans", sans-serif;
390+
font-size: initial;
391+
}
392+
393+
394+
.source_container {
395+
display: flex;
396+
}
397+
398+
.source_line_column {
399+
padding-right: 0.5em;
400+
text-align: right;
401+
color: var(--source-line-column);
402+
background: var(--source-line-column-bg);
403+
}
404+
405+
.source_line {
406+
padding: 0 1em;
407+
}
408+
409+
.source_code {
410+
flex-grow: 1;
411+
background: var(--code-background);
412+
padding: 0 0.3em;
413+
color: var(--code-color);
414+
}

src/ocamlorg_frontend/components/navmap.eml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ type kind =
88
| Class
99
| Class_type
1010
| File
11+
| Source
1112

1213
type toc = {
1314
title : string;
@@ -26,6 +27,7 @@ let kind_title = function
2627
| Parameter -> "Parameter"
2728
| Class -> "Class"
2829
| Class_type -> "Class type"
30+
| Source -> "Source"
2931
| _ -> "?"
3032

3133
let title_style = "flex-1 flex-nowrap py-1 md:py-0.5 pr-1 text-title dark:text-dark-title truncate"
@@ -40,6 +42,7 @@ let icon_style = function
4042
| Parameter -> "navmap-tag parameter-tag"
4143
| Class -> "navmap-tag class-tag"
4244
| Class_type -> "navmap-tag class-type-tag"
45+
| Source -> "navmap-tag source-tag"
4346
| _ -> "navmap-tag"
4447

4548
let rec nested_render ~path (item : toc) =
@@ -135,6 +138,7 @@ let render
135138
<span class="<%s icon_style Module_type %>" style="display:inline-block;color:white"></span>Module type<br>
136139
<span class="<%s icon_style Parameter %>" style="display:inline-block;color:white"></span>Parameter<br>
137140
<span class="<%s icon_style Class %>" style="display:inline-block;color:white"></span>Class<br>
138-
<span class="<%s icon_style Class_type %>" style="display:inline-block;color:white"></span>Class type
141+
<span class="<%s icon_style Class_type %>" style="display:inline-block;color:white"></span>Class type<br>
142+
<span class="<%s icon_style Source %>" style="display:inline-block;color:white"></span>Source
139143
</div>
140144
<% ); %>

src/ocamlorg_package/lib/ocamlorg_package.ml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ module Documentation = struct
241241
| Class
242242
| ClassType
243243
| File
244+
| Source
244245

245246
let breadcrumb_kind_from_string s =
246247
match s with
@@ -251,6 +252,7 @@ module Documentation = struct
251252
| "class" -> Class
252253
| "class-type" -> ClassType
253254
| "file" -> File
255+
| "source" -> Source
254256
| _ ->
255257
if String.starts_with ~prefix:"argument-" s then
256258
let i = List.hd (List.tl (String.split_on_char '-' s)) in
@@ -311,6 +313,17 @@ module Documentation = struct
311313
toc = List.map toc_of_json json_toc;
312314
content = header ^ preamble ^ content;
313315
}
316+
| `Assoc
317+
[
318+
("type", `String "source");
319+
("breadcrumbs", `List json_breadcrumbs);
320+
("global_toc", _);
321+
("header", `String header);
322+
("content", `String content);
323+
] ->
324+
let breadcrumbs = List.map breadcrumb_from_json json_breadcrumbs in
325+
let content = header ^ content in
326+
{ uses_katex = false; breadcrumbs; toc = []; content }
314327
| _ -> raise (Invalid_argument "malformed .html.json file")
315328
end
316329

src/ocamlorg_package/lib/ocamlorg_package.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ module Documentation : sig
8080
| Class
8181
| ClassType
8282
| File
83+
| Source
8384

8485
type breadcrumb = {
8586
name : string;

src/ocamlorg_web/lib/handler.ml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1271,6 +1271,7 @@ let package_documentation t kind req =
12711271
| Some "class" -> Class
12721272
| Some "class-type" -> Class_type
12731273
| Some "file" -> File
1274+
| Some "source" -> Source
12741275
| None -> Page
12751276
| _ -> File);
12761277
href = map_url sidebar.node.url;
@@ -1301,7 +1302,7 @@ let package_documentation t kind req =
13011302
| Parameter i -> Parameter (b, i)
13021303
| Class -> Class b
13031304
| ClassType -> ClassType b
1304-
| Page | LeafPage | File -> Page b
1305+
| Page | LeafPage | File | Source -> Page b
13051306
in
13061307

13071308
Ocamlorg_frontend.Package_breadcrumbs.Documentation

0 commit comments

Comments
 (0)