-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi_reference.jl
More file actions
207 lines (196 loc) · 7.4 KB
/
Copy pathapi_reference.jl
File metadata and controls
207 lines (196 loc) · 7.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
# ==============================================================================
# CTModels API Reference Manager
#
# One CTBase.automatic_reference_documentation call per documented page.
# Keep the file lists in sync with src/<Submodule>/ and ext/ when files
# are added, removed, or renamed.
# ==============================================================================
"""
generate_api_reference(src_dir::String, ext_dir::String)
Generate the API reference documentation for CTModels.
Returns the list of pages.
"""
function generate_api_reference(src_dir::String, ext_dir::String)
src(files...) = [abspath(joinpath(src_dir, f)) for f in files]
ext(files...) = [abspath(joinpath(ext_dir, f)) for f in files]
EXCLUDE_SYMBOLS = Symbol[
:include,
:eval,
Symbol("@pack_PreModel"),
Symbol("@pack_PreModel!"),
Symbol("@unpack_PreModel"),
:is_empty,
:time_ns,
]
EXCLUDE_INTERNALS = vcat(
EXCLUDE_SYMBOLS,
Symbol[:DOCTYPE_ABSTRACT_TYPE, :DOCTYPE_CONSTANT, :DOCTYPE_FUNCTION,
:DOCTYPE_MACRO, :DOCTYPE_MODULE, :DOCTYPE_STRUCT],
)
# ── Shared config: one entry per submodule ────────────────────────────────
modules_config = [
(
mod=CTModels.Components,
title="Components",
filename="components",
files=src(
joinpath("Components", "types.jl"),
joinpath("Components", "aliases.jl"),
joinpath("Components", "accessors.jl"),
joinpath("Components", "times_accessors.jl"),
joinpath("Components", "objective_accessors.jl"),
joinpath("Components", "constraints_accessors.jl"),
),
),
(
mod=CTModels.Models,
title="Models",
filename="models",
files=src(
joinpath("Models", "constraint_functors.jl"),
joinpath("Models", "model.jl"),
),
),
(
mod=CTModels.Building,
title="Building",
filename="building",
files=src(
joinpath("Building", "constraint_composers.jl"),
joinpath("Building", "pre_model.jl"),
joinpath("Building", "state.jl"),
joinpath("Building", "control.jl"),
joinpath("Building", "variable.jl"),
joinpath("Building", "times.jl"),
joinpath("Building", "dynamics.jl"),
joinpath("Building", "objective.jl"),
joinpath("Building", "constraints.jl"),
joinpath("Building", "definition.jl"),
joinpath("Building", "time_dependence.jl"),
joinpath("Building", "build.jl"),
joinpath("Building", "defaults.jl"),
joinpath("Building", "name_validation.jl"),
),
),
(
mod=CTModels.Solutions,
title="Solutions",
filename="solutions",
files=src(
joinpath("Solutions", "solution_types.jl"),
joinpath("Solutions", "dual_functors.jl"),
joinpath("Solutions", "build_solution.jl"),
joinpath("Solutions", "dual_model.jl"),
joinpath("Solutions", "interpolation_helpers.jl"),
joinpath("Solutions", "discretization_utils.jl"),
),
),
(
mod=CTModels.Display,
title="Display",
filename="display",
files=src(
joinpath("Display", "Display.jl"),
joinpath("Display", "ansi.jl"),
joinpath("Display", "definition.jl"),
joinpath("Display", "mathematical.jl"),
joinpath("Display", "model.jl"),
joinpath("Display", "pre_model.jl"),
joinpath("Display", "solution.jl"),
),
),
(
mod=CTModels.Serialization,
title="Serialization",
filename="serialization",
files=src(
joinpath("Serialization", "Serialization.jl"),
joinpath("Serialization", "export_import.jl"),
joinpath("Serialization", "types.jl"),
joinpath("Serialization", "reconstruction_helpers.jl"),
),
),
(
mod=CTModels.Init,
title="Init",
filename="init",
files=src(
joinpath("Init", "Init.jl"),
joinpath("Init", "types.jl"),
joinpath("Init", "api.jl"),
joinpath("Init", "init_functors.jl"),
joinpath("Init", "builders.jl"),
joinpath("Init", "state.jl"),
joinpath("Init", "control.jl"),
joinpath("Init", "variable.jl"),
joinpath("Init", "validation.jl"),
joinpath("Init", "utils.jl"),
),
),
]
# ── Public pages: one flat page per submodule ─────────────────────────────
pages = [
CTBase.automatic_reference_documentation(;
subdirectory="api",
primary_modules=[cfg.mod => cfg.files],
external_modules_to_document=[CTModels],
exclude=EXCLUDE_SYMBOLS,
public=true,
private=false,
title=cfg.title,
title_in_menu=cfg.title,
filename=cfg.filename,
) for cfg in modules_config
]
# ── Internals: all private symbols in one page, sections by module ────────
internals_modules = Any[cfg.mod => cfg.files for cfg in modules_config]
# Conditional extensions
for (sym, files) in [
(:CTModelsPlots, ext("CTModelsPlots.jl", "plot.jl", "plot_utils.jl", "plot_default.jl")),
(:CTModelsJSON, ext("CTModelsJSON.jl")),
(:CTModelsJLD, ext("CTModelsJLD.jl")),
]
extmod = Base.get_extension(CTModels, sym)
isnothing(extmod) || push!(internals_modules, extmod => files)
end
push!(
pages,
CTBase.automatic_reference_documentation(;
subdirectory="api",
primary_modules=internals_modules,
external_modules_to_document=[CTModels],
exclude=EXCLUDE_INTERNALS,
public=false,
private=true,
title="Internals",
title_in_menu="Internals",
filename="internals",
),
)
return pages
end
"""
with_api_reference(f::Function, src_dir::String, ext_dir::String)
Generates the API reference, executes `f(pages)`, and cleans up generated files.
"""
function with_api_reference(f::Function, src_dir::String, ext_dir::String)
pages = generate_api_reference(src_dir, ext_dir)
try
f(pages)
finally
docs_src = abspath(joinpath(@__DIR__, "src"))
function cleanup(pages)
for p in pages
content = last(p)
if content isa AbstractString
fname = endswith(content, ".md") ? content : content * ".md"
full_path = joinpath(docs_src, fname)
isfile(full_path) && rm(full_path)
elseif content isa Vector
cleanup(content)
end
end
end
cleanup(pages)
end
end