@@ -2,67 +2,53 @@ open Odoc_document
2
2
open Or_error
3
3
open Odoc_model
4
4
5
- let check_empty_asset_path asset_path filename =
6
- if asset_path <> None then
7
- Error. raise_warning
8
- @@ Error. filename_only
9
- " --asset-path only has an effect when generating from an asset"
10
- filename
11
-
12
- let documents_of_unit ~warnings_options ~syntax ~renderer ~extra ~asset_path
13
- ~filename unit =
5
+ let documents_of_unit ~warnings_options ~syntax ~renderer ~extra unit =
14
6
Error. catch_warnings (fun () ->
15
- check_empty_asset_path asset_path filename;
16
7
renderer.Renderer. extra_documents extra (CU unit ))
17
8
|> Error. handle_warnings ~warnings_options
18
9
>> = fun extra_docs ->
19
10
Ok (Renderer. document_of_compilation_unit ~syntax unit :: extra_docs)
20
11
21
- let documents_of_asset ~warnings_options ~asset_path unit =
22
- Error. catch_warnings (fun () ->
23
- match asset_path with None -> failwith " TODO" | Some a -> a)
24
- |> Error. handle_warnings ~warnings_options
25
- >> = fun asset_path -> Ok [ Renderer. document_of_asset asset_path unit ]
26
-
27
- let documents_of_page ~warnings_options ~syntax ~renderer ~extra ~asset_path
28
- ~filename page =
12
+ let documents_of_page ~warnings_options ~syntax ~renderer ~extra page =
29
13
Error. catch_warnings (fun () ->
30
- check_empty_asset_path asset_path filename;
31
14
renderer.Renderer. extra_documents extra (Page page))
32
15
|> Error. handle_warnings ~warnings_options
33
16
>> = fun extra_docs -> Ok (Renderer. document_of_page ~syntax page :: extra_docs)
34
17
35
- let documents_of_odocl ~warnings_options ~filename ~renderer ~extra ~syntax
36
- ~asset_path input =
18
+ let documents_of_odocl ~warnings_options ~renderer ~extra ~syntax input =
37
19
Odoc_file. load input >> = fun unit ->
38
20
match unit .content with
39
21
| Odoc_file. Page_content odoctree ->
40
- documents_of_page ~warnings_options ~syntax ~renderer ~extra ~asset_path
41
- ~filename odoctree
22
+ documents_of_page ~warnings_options ~syntax ~renderer ~extra odoctree
23
+ | Unit_content odoctree ->
24
+ documents_of_unit ~warnings_options ~syntax ~renderer ~extra odoctree
42
25
| Impl_content _ ->
43
26
Error
44
27
(`Msg
45
28
" Wrong kind of unit: Expected a page or module unit, got an \
46
29
implementation. Use the dedicated command for implementation." )
47
- | Unit_content odoctree ->
48
- documents_of_unit ~warnings_options ~syntax ~renderer ~extra ~asset_path
49
- ~filename odoctree
50
- | Asset_content a -> documents_of_asset ~warnings_options ~asset_path a
30
+ | Asset_content _ ->
31
+ Error
32
+ (`Msg
33
+ " Wrong kind of unit: Expected a page or module unit, got an asset \
34
+ unit. Use the dedicated command for assets." )
51
35
52
36
let documents_of_input ~renderer ~extra ~resolver ~warnings_options ~syntax
53
- ~ asset_path input =
37
+ input =
54
38
let output = Fs.File. (set_ext " .odocl" input) in
55
39
Odoc_link. from_odoc ~resolver ~warnings_options input output >> = function
56
40
| `Page page -> Ok [ Renderer. document_of_page ~syntax page ]
57
- | `Impl _impl ->
41
+ | `Module m -> documents_of_unit ~warnings_options ~syntax ~renderer ~extra m
42
+ | `Impl _ ->
58
43
Error
59
44
(`Msg
60
45
" Wrong kind of unit: Expected a page or module unit, got an \
61
46
implementation. Use the dedicated command for implementation." )
62
- | `Module m ->
63
- documents_of_unit ~warnings_options ~filename: " " ~syntax ~asset_path
64
- ~renderer ~extra m
65
- | `Asset a -> documents_of_asset ~warnings_options ~asset_path a
47
+ | `Asset _ ->
48
+ Error
49
+ (`Msg
50
+ " Wrong kind of unit: Expected a page or module unit, got an asset \
51
+ unit. Use the dedicated command for assets." )
66
52
67
53
let render_document renderer ~sidebar ~output :root_dir ~extra_suffix ~extra doc
68
54
=
@@ -96,24 +82,21 @@ let render_odoc ~resolver ~warnings_options ~syntax ~renderer ~output extra file
96
82
=
97
83
let extra_suffix = None in
98
84
documents_of_input ~renderer ~extra ~resolver ~warnings_options ~syntax file
99
- ~asset_path: None
100
85
>> = fun docs ->
101
86
List. iter
102
87
(render_document renderer ~sidebar: None ~output ~extra_suffix ~extra )
103
88
docs;
104
89
Ok ()
105
90
106
91
let generate_odoc ~syntax ~warnings_options ~renderer ~output ~extra_suffix
107
- ~sidebar ~asset_path extra file =
108
- let filename = Fpath. filename file in
92
+ ~sidebar extra file =
109
93
(match sidebar with
110
94
| None -> Ok None
111
95
| Some x ->
112
96
Odoc_file. load_index x >> = fun (sidebar , _ ) ->
113
97
Ok (Some (Odoc_document.Sidebar. of_lang sidebar)))
114
98
>> = fun sidebar ->
115
- documents_of_odocl ~warnings_options ~filename ~renderer ~extra ~syntax
116
- ~asset_path file
99
+ documents_of_odocl ~warnings_options ~renderer ~extra ~syntax file
117
100
>> = fun docs ->
118
101
List. iter
119
102
(render_document renderer ~output ~sidebar ~extra_suffix ~extra )
@@ -152,16 +135,24 @@ let generate_source_odoc ~syntax ~warnings_options ~renderer ~output
152
135
| Page_content _ | Unit_content _ | Asset_content _ ->
153
136
Error (`Msg " Expected an implementation unit" )
154
137
138
+ let generate_asset_odoc ~warnings_options :_ ~renderer ~output ~asset_file
139
+ ~extra_suffix extra file =
140
+ Odoc_file. load file >> = fun unit ->
141
+ match unit .content with
142
+ | Odoc_file. Asset_content unit ->
143
+ let doc = Renderer. document_of_asset asset_file unit in
144
+ render_document renderer ~output ~sidebar: None ~extra_suffix ~extra doc;
145
+ Ok ()
146
+ | Page_content _ | Unit_content _ | Impl_content _ ->
147
+ Error (`Msg " Expected an asset unit" )
148
+
155
149
let targets_odoc ~resolver ~warnings_options ~syntax ~renderer ~output :root_dir
156
150
~extra odoctree =
157
- let filename = Fpath. filename odoctree in
158
151
let docs =
159
152
if Fpath. get_ext odoctree = " .odoc" then
160
153
documents_of_input ~renderer ~extra ~resolver ~warnings_options ~syntax
161
- ~asset_path: None odoctree
162
- else
163
- documents_of_odocl ~warnings_options ~renderer ~extra ~syntax ~filename
164
- ~asset_path: None odoctree
154
+ odoctree
155
+ else documents_of_odocl ~warnings_options ~renderer ~extra ~syntax odoctree
165
156
in
166
157
docs >> = fun docs ->
167
158
List. iter
0 commit comments