Skip to content

Commit

Permalink
Move h1 Title Rendering to the Correct Location (#137)
Browse files Browse the repository at this point in the history
* repair test case for index.mld and extend test cases to look at generated index.html.json

* move title generation to avoid duplicate titles

* rename index.ml -> sourceinfo_index.ml

* improve naming of different index modules
  • Loading branch information
sabine authored Jan 28, 2024
1 parent 2323259 commit f7a7a09
Show file tree
Hide file tree
Showing 11 changed files with 103 additions and 33 deletions.
41 changes: 22 additions & 19 deletions src/voodoo-do/do.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module InputSelect = struct
match ext with ".cmti" -> 0 | ".cmt" -> 1 | ".cmi" -> 2 | _ -> 3

(* Given a list of Sourceinfo.t values, we need to find the 'best'
file for each, and return an Index.t of these *)
file for each, and return an Sourceinfo_index.t of these *)
let select sis =
let h = Hashtbl.create (List.length sis) in
List.iter
Expand All @@ -30,35 +30,37 @@ module InputSelect = struct
best :: acc)
h []
in
Index.of_source_infos result
Sourceinfo_index.of_source_infos result
end

module IncludePaths = struct
let get : Index.t -> Sourceinfo.t -> Fpath.Set.t =
let get : Sourceinfo_index.t -> Sourceinfo.t -> Fpath.Set.t =
fun index si ->
let s = Mld.compile_dir si.parent in
let set = Fpath.Set.of_list [ s ] in
List.fold_left
(fun paths dep ->
match Index.find_opt dep.Odoc.c_digest index with
match Sourceinfo_index.find_opt dep.Odoc.c_digest index with
| Some si -> Fpath.Set.add Sourceinfo.(compile_dir si) paths
| None -> (
match Index.find_extern_opt dep.Odoc.c_digest index with
match Sourceinfo_index.find_extern_opt dep.Odoc.c_digest index with
| Some p -> Fpath.Set.add p paths
| None ->
Format.eprintf "Missing dependency: %s %s\n%!" dep.c_unit_name
dep.c_digest;
paths))
set si.deps

let link : Index.t -> Fpath.Set.t =
let link : Sourceinfo_index.t -> Fpath.Set.t =
fun index ->
let dirs =
Index.M.fold
Sourceinfo_index.M.fold
(fun _ v acc -> Fpath.Set.add (Sourceinfo.compile_dir v) acc)
index.intern Fpath.Set.empty
in
Index.M.fold (fun _ v acc -> Fpath.Set.add v acc) index.extern dirs
Sourceinfo_index.M.fold
(fun _ v acc -> Fpath.Set.add v acc)
index.extern dirs
end

let get_source_info parent path =
Expand Down Expand Up @@ -160,11 +162,12 @@ let run pkg_name ~blessed ~failed =
Bos.OS.Dir.fold_contents ~dotfiles:true
(fun p acc ->
let _, name = Fpath.split_base p in
if name = Fpath.v "index.m" then Index.(combine (read p) acc) else acc)
Index.empty Paths.compile
if name = Fpath.v "index.m" then Sourceinfo_index.(combine (read p) acc)
else acc)
Sourceinfo_index.empty Paths.compile
in
let index =
match index_res with Ok index -> index | Error _ -> Index.empty
match index_res with Ok index -> index | Error _ -> Sourceinfo_index.empty
in

let opam_file = match Opam.find package with Ok f -> Some f | _ -> None in
Expand All @@ -176,8 +179,8 @@ let run pkg_name ~blessed ~failed =
let error_log = Error_log.find package in

let auto_generated_index_mld =
Auto_generated_index_mld.gen package ~blessed ~modules ~libraries
~package_mlds ~error_log ~failed
Index_mld_page.gen package ~blessed ~modules ~libraries ~package_mlds
~error_log ~failed
in

let () =
Expand All @@ -188,15 +191,15 @@ let run pkg_name ~blessed ~failed =
Compat.List.concat_map (get_source_info auto_generated_index_mld) prep
in
let this_index = InputSelect.select sis in
Index.write this_index auto_generated_index_mld;
let index = Index.combine this_index index in
Sourceinfo_index.write this_index auto_generated_index_mld;
let index = Sourceinfo_index.combine this_index index in
let rec compile h si compiled =
if List.mem si.Sourceinfo.path compiled then compiled
else
let compiled =
List.fold_left
(fun (compiled : Fpath.t list) dep ->
match Index.find_opt dep.Odoc.c_digest this_index with
match Sourceinfo_index.find_opt dep.Odoc.c_digest this_index with
| Some si -> compile h si compiled
| None -> compiled)
compiled si.deps
Expand All @@ -207,7 +210,7 @@ let run pkg_name ~blessed ~failed =
~includes ~children:[];
si.path :: compiled
in
let _ = ignore (Index.M.fold compile this_index.intern []) in
let _ = ignore (Sourceinfo_index.M.fold compile this_index.intern []) in
let mldvs =
Package_mlds.compile ~parent:auto_generated_index_mld package_mlds
in
Expand All @@ -219,7 +222,7 @@ let run pkg_name ~blessed ~failed =
in
let output = Fpath.(v "html") in
Util.mkdir_p output;
Index.M.iter
Sourceinfo_index.M.iter
(fun _ si ->
if Sourceinfo.is_hidden si then ()
else
Expand All @@ -229,7 +232,7 @@ let run pkg_name ~blessed ~failed =
~output:(Sourceinfo.output_odocl si))
this_index.intern;
let odocls =
Index.M.fold
Sourceinfo_index.M.fold
(fun _ si acc ->
if Sourceinfo.is_hidden si then acc
else Sourceinfo.output_odocl si :: acc)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,21 @@ let gen_with_error l =
]

let gen :
libraries:Library_names.t -> error_log:Error_log.t -> failed:bool -> string
=
fun ~libraries ~error_log ~failed ->
Package.t ->
libraries:Library_names.t ->
error_log:Error_log.t ->
failed:bool ->
string =
fun package ~libraries ~error_log ~failed ->
Format.eprintf "libraries: [%s]\n%!"
(String.concat ","
(List.map (fun x -> x.Library_names.name) libraries.libraries));
let result =
if failed then gen_with_error error_log
else gen_with_libraries libraries.libraries
in
String.concat "\n" result
Format.sprintf "{0 %s %s}\n %s" package.name package.version
(String.concat "\n" result)

let gen :
Package.t ->
Expand Down Expand Up @@ -119,7 +123,7 @@ let gen :

let content =
match mld_index with
| [] -> gen ~libraries ~error_log ~failed
| [] -> gen package ~libraries ~error_log ~failed
| x :: _ ->
let ic = open_in (Fpath.to_string x) in
let result = really_input_string ic (in_channel_length ic) in
Expand All @@ -133,9 +137,6 @@ let gen :
Format.eprintf "Failed to remove file: doc.mld - %s\n%!" m;
()
in
let doc =
Mld.v cwd "doc" (Some version) children
(Printf.sprintf "{0 %s %s}\n%s\n" package.name package.version content)
in
let doc = Mld.v cwd "doc" (Some version) children content in
Mld.compile doc;
doc
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions src/voodoo/voodoo.ml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Opam = Opam
module Sourceinfo = Sourceinfo
module Index = Index
module Sourceinfo_index = Sourceinfo_index
module Mld = Mld
module Odoc = Odoc
module Paths = Paths
Expand All @@ -9,6 +9,6 @@ module Library_names = Library_names
module Package = Package
module Package_mlds = Package_mlds
module Error_log = Error_log
module Auto_generated_index_mld = Auto_generated_index_mld
module Index_mld_page = Index_mld_page
module Package_info = Package_info
module Otherdocs = Otherdocs
4 changes: 2 additions & 2 deletions src/voodoo/voodoo.mli
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Opam = Opam
module Sourceinfo = Sourceinfo
module Index = Index
module Sourceinfo_index = Sourceinfo_index
module Mld = Mld
module Odoc = Odoc
module Paths = Paths
Expand All @@ -9,6 +9,6 @@ module Library_names = Library_names
module Package = Package
module Package_mlds = Package_mlds
module Error_log = Error_log
module Auto_generated_index_mld = Auto_generated_index_mld
module Index_mld_page = Index_mld_page
module Package_info = Package_info
module Otherdocs = Otherdocs
31 changes: 31 additions & 0 deletions test/can-render-org-files.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,36 @@ Converted the README.org file in HTML
$ cat output/p/$PKG/1.0/README.org.html.json | jq '.content'
"<h3>Title 2</h3>"

Content of automatically generated Index.mld is fine
$ cat output/p/$PKG/1.0/doc/index.html.json | jq .
{
"uses_katex": false,
"breadcrumbs": [
{
"name": "p",
"href": "../../../index.html",
"kind": "page"
},
{
"name": "can-render-org-files",
"href": "../../index.html",
"kind": "page"
},
{
"name": "1.0",
"href": "../index.html",
"kind": "page"
},
{
"name": "doc",
"href": "#",
"kind": "page"
}
],
"toc": [],
"preamble": "<h1 id=\"can-render-org-files-1.0\"><a href=\"#can-render-org-files-1.0\" class=\"anchor\"></a>can-render-org-files 1.0</h1>",
"content": ""
}

Uninstall the package
$ opam remove $PKG --yes > /dev/null
31 changes: 31 additions & 0 deletions test/can-render-tables.t
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,36 @@ Generate a README.md file with the tables formatted in HTML
$ cat output/p/$PKG/1.0/README.md.html.json | jq '.content'
"<table>\n<thead>\n<tr>\n<th>x</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>y</td>\n</tr>\n</tbody>\n</table>\n"

Content of Index.mld is fine
$ cat output/p/$PKG/1.0/doc/index.html.json | jq .
{
"uses_katex": false,
"breadcrumbs": [
{
"name": "p",
"href": "../../../index.html",
"kind": "page"
},
{
"name": "can-render-tables",
"href": "../../index.html",
"kind": "page"
},
{
"name": "1.0",
"href": "../index.html",
"kind": "page"
},
{
"name": "doc",
"href": "#",
"kind": "page"
}
],
"toc": [],
"preamble": "<h1 id=\"title\"><a href=\"#title\" class=\"anchor\"></a>Title</h1><p>Text</p><p>Here is some text that should show up.</p>",
"content": ""
}

Uninstall the package
$ opam remove $PKG --yes > /dev/null
2 changes: 2 additions & 0 deletions test/packages/can-render-tables/doc/dune
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
(documentation
(package can-render-tables))
4 changes: 3 additions & 1 deletion test/packages/can-render-tables/doc/index.mld
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# Title
{0 Title}

Text

Here is some text that should show up.

0 comments on commit f7a7a09

Please sign in to comment.