Skip to content
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

Refactor examples into subdirectories #2445

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
build/
src/examples/*.md
src/examples/*/*.md
52 changes: 34 additions & 18 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ using Test
const _FAST = findfirst(isequal("--fast"), ARGS) !== nothing

const _EXAMPLE_DIR = joinpath(@__DIR__, "src", "examples")
const _EXAMPLE_SUBDIR = [
"Mixed-integer linear programs",
"Nonlinear programs",
"Quadratic programs",
"Semidefinite programs",
]

function link_example(content)
edit_url = match(r"EditURL = \"(.+?)\"", content)[1]
Expand All @@ -19,20 +25,24 @@ function link_example(content)
return content
end

function literate_examples()
for file in readdir(_EXAMPLE_DIR)
if !endswith(file, ".jl")
continue
end
filename = joinpath(_EXAMPLE_DIR, file)
function _file_list(full_dir, relative_dir, extension)
return map(
file -> joinpath(relative_dir, file),
filter(file -> endswith(file, extension), sort(readdir(full_dir))),
)
end

function literate_examples(dir)
rm.(_file_list(dir, dir, ".md"))
for filename in _file_list(dir, dir, ".jl")
# `include` the file to test it before `#src` lines are removed. It is
# in a testset to isolate local variables between files.
@testset "$(file)" begin
@testset "$(filename)" begin
include(filename)
end
Literate.markdown(
filename,
_EXAMPLE_DIR;
dir;
documenter = true,
postprocess = link_example,
)
Expand All @@ -41,7 +51,8 @@ function literate_examples()
end

if !_FAST
literate_examples()
literate_examples(_EXAMPLE_DIR)
literate_examples.(joinpath.(_EXAMPLE_DIR, _EXAMPLE_SUBDIR))
end

makedocs(
Expand Down Expand Up @@ -88,16 +99,21 @@ makedocs(
"callbacks.md",
"Extensions" => "extensions.md",
],
"API Reference" => map(
file -> joinpath("reference", file),
sort(readdir(joinpath(@__DIR__, "src", "reference"))),
"API Reference" => _file_list(
joinpath(@__DIR__, "src", "reference"),
"reference",
".md",
),
"Examples" => map(
file -> joinpath("examples", file),
filter(
file -> endswith(file, ".md"),
sort(readdir(_EXAMPLE_DIR)),
)
"Examples" => vcat(
_file_list(_EXAMPLE_DIR, "examples", ".md"),
map(
subdir -> subdir => _file_list(
joinpath(_EXAMPLE_DIR, subdir),
joinpath("examples", subdir),
".md",
),
_EXAMPLE_SUBDIR,
),
),
"Style Guide" => "style.md",
"Development Roadmap" => "roadmap.md",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.