-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a source-root arg to html-generate #982
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,6 +58,8 @@ module Arg = struct | |
|
||
let file = file | ||
|
||
let dir = dir | ||
|
||
let bool = bool | ||
|
||
let ( & ) = ( & ) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,23 +16,45 @@ | |
|
||
open Odoc_model | ||
|
||
type source = File of Fpath.t | Root of Fpath.t | ||
|
||
let pp fmt = function | ||
| File f -> Format.fprintf fmt "File: %a" Fpath.pp f | ||
| Root f -> Format.fprintf fmt "File: %a" Fpath.pp f | ||
|
||
let to_string f = Format.asprintf "%a" pp f | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe this could be put inside a submodule? The |
||
type args = { | ||
html_config : Odoc_html.Config.t; | ||
source_file : Fpath.t option; | ||
source : source option; | ||
assets : Fpath.t list; | ||
} | ||
|
||
let render { html_config; source_file = _; assets = _ } page = | ||
let render { html_config; source = _; assets = _ } page = | ||
Odoc_html.Generator.render ~config:html_config page | ||
|
||
let source_documents source_info source_file ~syntax = | ||
match (source_info, source_file) with | ||
let source_documents source_info source ~syntax = | ||
match (source_info, source) with | ||
| Some { Lang.Source_info.id; infos }, Some src -> ( | ||
match Fs.File.read src with | ||
let file = | ||
match src with | ||
| File f -> f | ||
| Root f -> | ||
let open Odoc_model.Paths.Identifier in | ||
let rec get_path_dir : SourceDir.t -> Fpath.t = function | ||
| { iv = `SourceDir (d, f); _ } -> Fpath.(get_path_dir d / f) | ||
| { iv = `Page _; _ } -> f | ||
in | ||
let get_path : SourcePage.t -> Fpath.t = function | ||
| { iv = `SourcePage (d, f); _ } -> Fpath.(get_path_dir d / f) | ||
in | ||
get_path id | ||
in | ||
match Fs.File.read file with | ||
| Error (`Msg msg) -> | ||
Error.raise_warning | ||
(Error.filename_only "Couldn't load source file: %s" msg | ||
(Fs.File.to_string src)); | ||
(Fs.File.to_string file)); | ||
[] | ||
| Ok source_code -> | ||
let infos = infos @ Odoc_loader.Source_info.of_source source_code in | ||
|
@@ -54,7 +76,7 @@ let source_documents source_info source_file ~syntax = | |
(Error.filename_only | ||
"--source argument is invalid on compilation unit that were not \ | ||
compiled with --source-parent and --source-name" | ||
(Fs.File.to_string src)); | ||
(to_string src)); | ||
[] | ||
| None, None -> [] | ||
|
||
|
@@ -109,7 +131,7 @@ let asset_documents parent_id children asset_paths = | |
let extra_documents args input ~syntax = | ||
match input with | ||
| Odoc_document.Renderer.CU unit -> | ||
source_documents unit.Lang.Compilation_unit.source_info args.source_file | ||
source_documents unit.Lang.Compilation_unit.source_info args.source | ||
~syntax | ||
| Page page -> asset_documents page.Lang.Page.name page.children args.assets | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let y = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let x = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
let w = 5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{0 Root} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
A page can have source children. | ||
|
||
$ odoc compile -c module-a -c module-b -c src-source root.mld | ||
|
||
$ printf "lib/main.ml\nlib/b/b.ml\nlib/a/a.ml\n" > source.map | ||
$ odoc source-tree -I . --parent page-root source.map | ||
|
||
Compile the modules: | ||
|
||
$ ocamlc -c lib/a/a.ml -bin-annot | ||
$ ocamlc -c lib/b/b.ml -bin-annot | ||
$ ocamlc -c lib/main.ml -bin-annot | ||
|
||
Now, compile the pages with the --source option. The source-name must be included in the source-children of the source-parent: | ||
|
||
$ odoc compile -I . --source-name lib/a/a.ml --source-parent-file src-source.odoc lib/a/a.cmt | ||
$ odoc compile -I . --source-name lib/b/b.ml --source-parent-file src-source.odoc lib/b/b.cmt | ||
$ odoc compile -I . --source-name lib/main.ml --source-parent-file src-source.odoc lib/main.cmt | ||
$ odoc link -I . -I lib/a -I lib/b -I lib page-root.odoc | ||
$ odoc link -I . lib/a/a.odoc | ||
$ odoc link -I . lib/b/b.odoc | ||
$ odoc link -I . lib/main.odoc | ||
$ odoc link -I . src-source.odoc | ||
$ odoc html-generate --indent -o html page-root.odocl | ||
$ odoc html-generate --indent -o html src-source.odocl | ||
$ odoc html-generate --source-root . --indent -o html lib/a/a.odocl | ||
$ odoc html-generate --source-root . --indent -o html lib/b/b.odocl | ||
$ odoc html-generate --source-root . --indent -o html lib/main.odocl | ||
|
||
Source pages and source directory pages are generated: | ||
|
||
$ find html | sort | ||
html | ||
html/A | ||
html/A/index.html | ||
html/B | ||
html/B/index.html | ||
html/Main | ||
html/Main/index.html | ||
html/root | ||
html/root/index.html | ||
html/root/source | ||
html/root/source/index.html | ||
html/root/source/lib | ||
html/root/source/lib/a | ||
html/root/source/lib/a/a.ml.html | ||
html/root/source/lib/a/index.html | ||
html/root/source/lib/b | ||
html/root/source/lib/b/b.ml.html | ||
html/root/source/lib/b/index.html | ||
html/root/source/lib/index.html | ||
html/root/source/lib/main.ml.html | ||
|
||
A directory simply list its children: | ||
|
||
$ cat html/root/source/lib/index.html | ||
<!DOCTYPE html> | ||
<html xmlns="http://www.w3.org/1999/xhtml"> | ||
<head><title>lib (root.source.lib)</title> | ||
<link rel="stylesheet" href="../../../odoc.css"/><meta charset="utf-8"/> | ||
<meta name="generator" content="odoc %%VERSION%%"/> | ||
<meta name="viewport" content="width=device-width,initial-scale=1.0"/> | ||
<script src="../../../highlight.pack.js"></script> | ||
<script>hljs.initHighlightingOnLoad();</script> | ||
</head> | ||
<body class="odoc"> | ||
<nav class="odoc-nav"><a href="../index.html">Up</a> – | ||
<a href="../../index.html">root</a> » | ||
<a href="../index.html">source</a> » lib | ||
</nav><header class="odoc-preamble"></header> | ||
<div class="odoc-content"><h1>./lib/</h1> | ||
<ul class="odoc-folder-list"> | ||
<li><span class="odoc-directory"><a href="a/index.html">a</a></span></li> | ||
<li><span class="odoc-directory"><a href="b/index.html">b</a></span></li> | ||
<li><span class="odoc-file"><a href="main.ml.html">main.ml</a></span> | ||
</li> | ||
</ul> | ||
</div> | ||
</body> | ||
</html> |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel it might help to add some explanation what is a "source code root".
Also, line 718 it should be
--source-parent-file
instead of--source-parent
(or maybe "--source-parent-file
and--source-name
to be more explicit)