Skip to content

Commit fdd0915

Browse files
committed
Allow sections.
1 parent e1cdc1a commit fdd0915

File tree

3 files changed

+132
-33
lines changed

3 files changed

+132
-33
lines changed

docs/README.md

+12
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@ $julia make.jl
66
```
77

88
The generated docs can be accessed in `build/index.html`.
9+
10+
You may modify `Structure` to arrange the structure of the website to be generated. For example:
11+
12+
```
13+
Order: normal_form_game, Computing Nash equilibria, Repeated Game
14+
Computing Nash equilibria: pure_nash, support_enumeration
15+
Repeated Game: repeated_game_util, repeated_game
16+
```
17+
18+
The first line sets the order of pages. You can add a file name if you want it to generate a single page, or the name of section you want to create. In the following you need to declare which files are included in each section. Note that you shouldn't put a comma or dot at the end of each line.
19+
20+
It is not necessary to declare structure for every file included in the Module. Files not mentioned in `Structure` will simply generate a single page automatically.

docs/Structure

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Order: normal_form_game, Computing Nash Equilibria, Repeated Game
2+
Computing Nash Equilibria: pure_nash, support_enumeration
3+
Repeated Game: repeated_game_util, repeated_game

docs/auto_doc_gen.jl

+117-33
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,65 @@ docs using `Documenter.jl`.
66
77
=#
88

9+
path = Pkg.dir("Games")
10+
11+
# read the basic structures
12+
order = SubString{String}[]
13+
sections_names = SubString{String}[]
14+
sections = Dict{SubString{String}, Vector{SubString{String}}}()
15+
re = r"(.*): (.*)\n"
16+
open(joinpath(path, "docs/Structure")) do f
17+
for match in eachmatch(re, readstring(f))
18+
list = map(i -> strip(i), split(match.captures[2], ","))
19+
if list ==[""]
20+
continue
21+
end
22+
23+
if match.captures[1] == "Order"
24+
order = list
25+
global order
26+
else
27+
section_name = match.captures[1]
28+
push!(sections_names, section_name)
29+
sections[section_name] = list
30+
end
31+
end
32+
end
33+
934
# find all files used in Games.jl
1035
re = r"include\(\"(.*)\.jl\"\)"
1136
files = String[]
12-
path = Pkg.dir("Games")
1337

1438
open(joinpath(path, "src/Games.jl")) do f
1539
for match in eachmatch(re, readstring(f))
1640
push!(files, match.captures[1])
1741
end
1842
end
1943

20-
# create PAGES for makedocs()
21-
PAGES = ["Home" => "index.md",
22-
"Library" => push!(
23-
["lib/$file.md" for file in files],
24-
"lib/index.md"
25-
)
26-
]
44+
files_names = Dict{String, String}(
45+
file => replace(join(map(ucfirst, split(file, "_")), " "),
46+
"Util",
47+
"Utilities")
48+
for file in files
49+
)
2750

2851
# generate paths
2952
if !ispath(joinpath(path, "docs/src/lib"))
3053
mkpath(joinpath(path, "docs/src/lib"))
3154
end
3255

33-
# write index.md as Homepage
34-
home_page = """
35-
# Games.jl
36-
37-
"""
38-
39-
open(joinpath(path, "docs/src/index.md"), "w") do f
40-
write(f, home_page)
41-
for file in files
42-
file_name =
43-
replace(join(map(ucfirst, split(file, "_")), " "),
44-
"Util",
45-
"Utilities"
46-
)
47-
write(f, "* [$file_name](@ref)\n")
48-
end
49-
end
50-
51-
# write .md for each file in Library
56+
# write .md for files not in section
5257
for file in files
53-
file_name =
54-
replace(join(map(ucfirst, split(file, "_")), " "),
55-
"Util",
56-
"Utilities"
57-
)
58+
if file in vcat(values(sections)...)
59+
continue
60+
end
5861

62+
if !(file in order)
63+
push!(order, file)
64+
end
65+
file_name = files_names[file]
5966
file_page = """
60-
# $file_name
67+
# [$file_name](@id $file)
6168
6269
This is documentation for `$file.jl`.
6370
@@ -82,6 +89,48 @@ Public = false
8289
end
8390
end
8491

92+
# write .md for sections
93+
for section_name in sections_names
94+
if !(section_name in order)
95+
push!(order, section_name)
96+
end
97+
98+
section_files = sections[section_name]
99+
section_name_lower = replace(lowercase(section_name), " ", "_")
100+
section_page = """
101+
# $section_name
102+
103+
This is documentation for $section_name.
104+
"""
105+
open(joinpath(path, "docs/src/lib/$section_name_lower.md"), "w") do f
106+
write(f, section_page)
107+
for file in section_files
108+
file_name = files_names[file]
109+
section_file_page = """
110+
111+
## [$file_name](@id $file)
112+
113+
Documentation for `$file.jl`.
114+
115+
### Exported
116+
```@autodocs
117+
Modules = [Games]
118+
Pages = ["$file.jl"]
119+
Private = false
120+
```
121+
122+
### Internal
123+
```@autodocs
124+
Modules = [Games]
125+
Pages = ["$file.jl"]
126+
Public = false
127+
```
128+
"""
129+
write(f, section_file_page)
130+
end
131+
end
132+
end
133+
85134
# write index page for Liabrary
86135
index = """
87136
# Index
@@ -94,3 +143,38 @@ modules = [Games]
94143
open(joinpath(path, "docs/src/lib/index.md"), "w") do f
95144
write(f, index)
96145
end
146+
147+
# write index.md as Homepage
148+
home_page = """
149+
# Games.jl
150+
151+
"""
152+
153+
open(joinpath(path, "docs/src/index.md"), "w") do f
154+
write(f, home_page)
155+
for page in order
156+
if page in keys(sections)
157+
write(f, "$page\n")
158+
for file in sections[page]
159+
file_name = files_names[file]
160+
write(f, "* [$file_name](@ref $file)\n")
161+
end
162+
write(f, "\n")
163+
else
164+
file = page
165+
file_name = files_names[file]
166+
write(f, "[$file_name](@ref $file)\n\n")
167+
end
168+
end
169+
end
170+
171+
pages_names = map(i -> replace(lowercase(i), " ", "_"), order)
172+
173+
PAGES = ["Home" => "index.md",
174+
"Library" => push!(
175+
["lib/$page_name.md"
176+
for page_name in pages_names
177+
],
178+
"lib/index.md"
179+
)
180+
]

0 commit comments

Comments
 (0)