Skip to content

Commit

Permalink
Prepare for generating documentation for submodules (e.g. bimatrix_ge…
Browse files Browse the repository at this point in the history
…nerators)
  • Loading branch information
shizejin authored and oyamad committed Dec 8, 2017
1 parent e850c7d commit 2b0fa36
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 15 deletions.
22 changes: 14 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ There are three parts to generate the documentation.
### auto_doc_gen.jl

Main part of documentation generation. It reads `src/Games.jl` to find
out all the source files, and then write markdown files for each with
the structure instructed by `docs/build/Structure`, which will be utilized
by "Documenter.jl" later.
out all the source files (include the ones used in submodules), and then
write markdown files for each by the structure instructed by
`docs/build/Structure`, which will be utilized by "Documenter.jl" later.

Note that the pattern of each page can be modified by changing the
strings in `auto_doc_gen.jl` called `file_page` and `section_page`.
Expand All @@ -34,9 +34,10 @@ You may modify `Structure` to arrange the structure of the website to be generat
For example:

```
Order: Base Types and Methods, Computing Nash Equilibria, Repeated Games
Base Types and Methods: normal_form_game, random
Computing Nash Equilibria: pure_nash
Order: Base Types and Methods, Game Generators, Computing Nash Equilibria, Repeated Games
Base Types and Methods: normal_form_game
Game Generators: random, generators/bimatrix_generators
Computing Nash Equilibria: pure_nash, support_enumeration
Repeated Games: repeated_game_util, repeated_game
```

Expand All @@ -45,8 +46,13 @@ generate a single page, or the name of the section you want to create. In the fo
you need to declare which files are included in each section. Note that you should not
put a comma or dot at the end of each line.

It is not necessary to declare the structure of every file included in the Module.
A separate single page will be generated for each file not mentioned in `Structure` automatically.
It is not necessary to declare the structure of every file included in the main module.
A separate single page will be generated for each file not mentioned in `Structure`
automatically.

However, you must specify the structure for files in each submodule. If you want to let
a submodule to be a seperate section, please state this in `Structure`, with the submodule
name as the section name.

#### Homepage

Expand Down
32 changes: 25 additions & 7 deletions docs/auto_doc_gen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,34 @@ open(joinpath(path, "docs/Structure")) do f
end
end

modules = String["Games"]
# find all files used in Games.jl
re = r"include\(\"(.*)\.jl\"\)"
files = String[]

open(joinpath(path, "src/Games.jl")) do f
for match in eachmatch(re, readstring(f))
push!(files, match.captures[1])
# check if it is a submodule
if contains(match.captures[1], "/")
submodule_path = match.captures[1]
submodule_dir, submodule_name = split(submodule_path, "/")
# add submodule name to modules
push!(modules, "Games.$submodule_name")
# find all files used in submodules
open(joinpath(path, "src/$submodule_path.jl")) do f_submodule
for match_sub in eachmatch(re, readstring(f_submodule))
file = match_sub.captures[1]
push!(files, "$submodule_dir/$file")
end
end
else
push!(files, match.captures[1])
end
end
end

module_names = join(modules, ", ")

files_names = Dict{String, String}(
file => replace(join(map(ucfirst, split(file, "_")), " "),
"Util",
Expand All @@ -53,7 +71,7 @@ if !ispath(joinpath(path, "docs/src/lib"))
mkpath(joinpath(path, "docs/src/lib"))
end

# write .md for files not in section
# write .md for files in main modules not in section
for file in files
if file in vcat(values(sections)...)
continue
Expand All @@ -71,15 +89,15 @@ This is documentation for `$file.jl`.
## Exported
```@autodocs
Modules = [Games]
Modules = [$module_names]
Pages = ["$file.jl"]
Private = false
```
## Internal
```@autodocs
Modules = [Games]
Modules = [$module_names]
Pages = ["$file.jl"]
Public = false
```
Expand Down Expand Up @@ -108,14 +126,14 @@ for section_name in sections_names
## Exported
```@autodocs
Modules = [Games]
Modules = [$module_names]
Pages = [$section_file_list]
Private = false
```
## Internal
```@autodocs
Modules = [Games]
Modules = [$module_names]
Pages = [$section_file_list]
Public = false
```
Expand All @@ -130,7 +148,7 @@ index = """
# Index
```@index
modules = [Games]
Modules = [$module_names]
```
"""

Expand Down

0 comments on commit 2b0fa36

Please sign in to comment.