3737 modDesc: Rope # module description
3838 module: PSym
3939 modDeprecationMsg: Rope
40- toc, section: TSections
40+ toc, toc2, section: TSections
41+ tocTable: array [TSymKind , Table [string , Rope ]]
4142 indexValFilename: string
4243 analytics: string # Google Analytics javascript, "" if doesn't exist
4344 seenSymbols: StringTableRef # avoids duplicate symbol generation for HTML.
@@ -871,6 +872,14 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
871872 itemIDRope, plainNameRope, plainSymbolRope, symbolOrIdRope,
872873 plainSymbolEncRope, symbolOrIdEncRope, attype]))
873874
875+ d.tocTable[k].mgetOrPut (cleanPlainSymbol, nil ).add (ropeFormatNamedVars (
876+ d.conf, getConfigVar (d.conf, " doc.item.tocTable" ),
877+ [" name" , " header" , " desc" , " itemID" , " header_plain" , " itemSym" ,
878+ " itemSymOrID" , " itemSymEnc" , " itemSymOrIDEnc" , " attype" ],
879+ [rope (getName (d, nameNode, d.splitAfter)), result , comm,
880+ itemIDRope, plainNameRope, plainSymbolRope,
881+ symbolOrIdRope, plainSymbolEncRope, symbolOrIdEncRope, attype]))
882+
874883 # Ironically for types the complexSymbol is *cleaner* than the plainName
875884 # because it doesn't include object fields or documentation comments. So we
876885 # use the plain one for callable elements, and the complex for the rest.
@@ -1167,7 +1176,7 @@ proc generateTags*(d: PDoc, n: PNode, r: var Rope) =
11671176 generateTags (d, lastSon (n[0 ]), r)
11681177 else : discard
11691178
1170- proc genSection (d: PDoc , kind: TSymKind ) =
1179+ proc genSection (d: PDoc , kind: TSymKind , groupedToc = false ) =
11711180 const sectionNames: array [skModule.. skField, string ] = [
11721181 " Imports" , " Types" , " Vars" , " Lets" , " Consts" , " Vars" , " Procs" , " Funcs" ,
11731182 " Methods" , " Iterators" , " Converters" , " Macros" , " Templates" , " Exports"
@@ -1177,14 +1186,23 @@ proc genSection(d: PDoc, kind: TSymKind) =
11771186 d.section[kind] = ropeFormatNamedVars (d.conf, getConfigVar (d.conf, " doc.section" ), [
11781187 " sectionid" , " sectionTitle" , " sectionTitleID" , " content" ], [
11791188 ord (kind).rope, title, rope (ord (kind) + 50 ), d.section[kind]])
1189+
1190+ var tocSource = d.toc
1191+ if groupedToc:
1192+ for p in d.tocTable[kind].keys:
1193+ d.toc2[kind].add ropeFormatNamedVars (d.conf, getConfigVar (d.conf, " doc.section.toc2" ), [
1194+ " sectionid" , " sectionTitle" , " sectionTitleID" , " content" , " plainName" ], [
1195+ ord (kind).rope, title, rope (ord (kind) + 50 ), d.tocTable[kind][p], p.rope])
1196+ tocSource = d.toc2
1197+
11801198 d.toc[kind] = ropeFormatNamedVars (d.conf, getConfigVar (d.conf, " doc.section.toc" ), [
11811199 " sectionid" , " sectionTitle" , " sectionTitleID" , " content" ], [
1182- ord (kind).rope, title, rope (ord (kind) + 50 ), d.toc [kind]])
1200+ ord (kind).rope, title, rope (ord (kind) + 50 ), tocSource [kind]])
11831201
11841202proc relLink (outDir: AbsoluteDir , destFile: AbsoluteFile , linkto: RelativeFile ): Rope =
11851203 rope ($ relativeTo (outDir / linkto, destFile.splitFile ().dir, '/' ))
11861204
1187- proc genOutFile (d: PDoc ): Rope =
1205+ proc genOutFile (d: PDoc , groupedToc = false ): Rope =
11881206 var
11891207 code, content: Rope
11901208 title = " "
@@ -1193,7 +1211,8 @@ proc genOutFile(d: PDoc): Rope =
11931211 renderTocEntries (d[], j, 1 , tmp)
11941212 var toc = tmp.rope
11951213 for i in TSymKind :
1196- genSection (d, i)
1214+ var shouldSort = i in {skProc, skFunc} and groupedToc
1215+ genSection (d, i, shouldSort)
11971216 toc.add (d.toc[i])
11981217 if toc != nil :
11991218 toc = ropeFormatNamedVars (d.conf, getConfigVar (d.conf, " doc.toc" ), [" content" ], [toc])
@@ -1246,9 +1265,9 @@ proc updateOutfile(d: PDoc, outfile: AbsoluteFile) =
12461265 if isAbsolute (d.conf.outFile.string ):
12471266 d.conf.outFile = splitPath (d.conf.outFile.string )[1 ].RelativeFile
12481267
1249- proc writeOutput * (d: PDoc , useWarning = false ) =
1268+ proc writeOutput * (d: PDoc , useWarning = false , groupedToc = false ) =
12501269 runAllExamples (d)
1251- var content = genOutFile (d)
1270+ var content = genOutFile (d, groupedToc )
12521271 if optStdout in d.conf.globalOptions:
12531272 writeRope (stdout, content)
12541273 else :
0 commit comments