1+ # ==============================================================================
2+ # OptimalControl API Reference Generator
3+ # ==============================================================================
4+ #
5+ # This file generates the API reference documentation for OptimalControl.
6+ # It uses CTBase.automatic_reference_documentation to scan source files
7+ # and generate documentation pages.
8+ #
9+ # ==============================================================================
10+
11+ """
12+ generate_api_reference(src_dir::String, ext_dir::String)
13+
14+ Generate the API reference documentation for OptimalControl.
15+ Returns the list of pages.
16+ """
17+ function generate_api_reference (src_dir:: String , ext_dir:: String )
18+ # Helper to build absolute paths
19+ src (files... ) = [abspath (joinpath (src_dir, f)) for f in files]
20+ ext (files... ) = [abspath (joinpath (ext_dir, f)) for f in files]
21+
22+ # Symbols to exclude from documentation
23+ EXCLUDE_SYMBOLS = Symbol[:include , :eval ]
24+
25+ pages = [
26+
27+ CTBase. automatic_reference_documentation (;
28+ subdirectory= " api" ,
29+ primary_modules= [
30+ OptimalControl => src (
31+ joinpath (" helpers" , " component_checks.jl" ),
32+ joinpath (" helpers" , " component_completion.jl" ),
33+ joinpath (" helpers" , " descriptive_routing.jl" ),
34+ joinpath (" helpers" , " kwarg_extraction.jl" ),
35+ joinpath (" helpers" , " methods.jl" ),
36+ joinpath (" helpers" , " print.jl" ),
37+ joinpath (" helpers" , " registry.jl" ),
38+ joinpath (" helpers" , " strategy_builders.jl" ),
39+ joinpath (" solve" , " canonical.jl" ),
40+ joinpath (" solve" , " descriptive.jl" ),
41+ joinpath (" solve" , " dispatch.jl" ),
42+ joinpath (" solve" , " explicit.jl" ),
43+ joinpath (" solve" , " mode.jl" ),
44+ joinpath (" solve" , " mode_detection.jl" ),
45+ ),
46+ ],
47+ external_modules_to_document= [CTBase, CTModels, CTSolvers],
48+ exclude= EXCLUDE_SYMBOLS,
49+ public= false ,
50+ private= true ,
51+ title= " Private" ,
52+ title_in_menu= " Private" ,
53+ filename= " private" ,
54+ ),
55+
56+ ]
57+
58+ return pages
59+ end
60+
61+ """
62+ with_api_reference(f::Function, src_dir::String, ext_dir::String)
63+
64+ Generates the API reference, executes `f(pages)`, and cleans up generated files.
65+ """
66+ function with_api_reference (f:: Function , src_dir:: String , ext_dir:: String )
67+ pages = generate_api_reference (src_dir, ext_dir)
68+ try
69+ f (pages)
70+ finally
71+ # Clean up generated files
72+ docs_src = abspath (joinpath (@__DIR__ , " src" ))
73+ _cleanup_pages (docs_src, pages)
74+ end
75+ end
76+
77+ function _cleanup_pages (docs_src:: String , pages)
78+ for p in pages
79+ val = last (p)
80+ if val isa AbstractString
81+ fname = endswith (val, " .md" ) ? val : val * " .md"
82+ full_path = joinpath (docs_src, fname)
83+ if isfile (full_path)
84+ rm (full_path)
85+ println (" Removed temporary API doc: $full_path " )
86+ end
87+ elseif val isa AbstractVector
88+ _cleanup_pages (docs_src, val)
89+ end
90+ end
91+ end
0 commit comments