@@ -6,58 +6,65 @@ docs using `Documenter.jl`.
6
6
7
7
=#
8
8
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
+
9
34
# find all files used in Games.jl
10
35
re = r" include\(\" (.*)\. jl\"\) "
11
36
files = String[]
12
- path = Pkg. dir (" Games" )
13
37
14
38
open (joinpath (path, " src/Games.jl" )) do f
15
39
for match in eachmatch (re, readstring (f))
16
40
push! (files, match. captures[1 ])
17
41
end
18
42
end
19
43
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
+ )
27
50
28
51
# generate paths
29
52
if ! ispath (joinpath (path, " docs/src/lib" ))
30
53
mkpath (joinpath (path, " docs/src/lib" ))
31
54
end
32
55
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
52
57
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
58
61
62
+ if ! (file in order)
63
+ push! (order, file)
64
+ end
65
+ file_name = files_names[file]
59
66
file_page = """
60
- # $file_name
67
+ # [ $file_name ](@id $file )
61
68
62
69
This is documentation for `$file .jl`.
63
70
@@ -82,6 +89,48 @@ Public = false
82
89
end
83
90
end
84
91
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
+
85
134
# write index page for Liabrary
86
135
index = """
87
136
# Index
@@ -94,3 +143,38 @@ modules = [Games]
94
143
open (joinpath (path, " docs/src/lib/index.md" ), " w" ) do f
95
144
write (f, index)
96
145
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