@@ -17,11 +17,10 @@ import
17
17
packages/ docutils/ rst, packages/ docutils/ rstgen,
18
18
json, xmltree, cgi, trees, types,
19
19
typesrenderer, astalgo, lineinfos, intsets,
20
- pathutils, trees, tables
20
+ pathutils, trees, tables, nimpaths
21
21
22
22
const
23
23
exportSection = skField
24
- htmldocsDir = RelativeDir " htmldocs"
25
24
docCmdSkip = " skip"
26
25
27
26
type
51
50
destFile* : AbsoluteFile
52
51
thisDir* : AbsoluteDir
53
52
exampleGroups: OrderedTable [string , ExampleGroup ]
54
- wroteCss * : bool
53
+ wroteSupportFiles * : bool
55
54
56
55
PDoc * = ref TDocumentor # # Alias to type less.
57
56
@@ -72,7 +71,7 @@ proc presentationPath*(conf: ConfigRef, file: AbsoluteFile, isTitle = false): Re
72
71
proc nimbleDir (): AbsoluteDir =
73
72
getNimbleFile (conf, file2).parentDir.AbsoluteDir
74
73
case conf.docRoot:
75
- of " @default " : # using `@` instead of `$` to avoid shell quoting complications
74
+ of docRootDefault:
76
75
result = getRelativePathFromConfigPath (conf, file)
77
76
let dir = nimbleDir ()
78
77
if not dir.isEmpty:
@@ -88,9 +87,12 @@ proc presentationPath*(conf: ConfigRef, file: AbsoluteFile, isTitle = false): Re
88
87
result = getRelativePathFromConfigPath (conf, file)
89
88
if result .isEmpty: bail ()
90
89
elif conf.docRoot.len > 0 :
91
- doAssert conf.docRoot.isAbsolute, conf.docRoot # or globalError
92
- doAssert conf.docRoot.existsDir, conf.docRoot
93
- result = relativeTo (file, conf.docRoot.AbsoluteDir )
90
+ # we're (currently) requiring `isAbsolute` to avoid confusion when passing
91
+ # a relative path (would it be relative wrt $PWD or to projectfile)
92
+ conf.globalAssert conf.docRoot.isAbsolute, arg= conf.docRoot
93
+ conf.globalAssert conf.docRoot.existsDir, arg= conf.docRoot
94
+ # needed because `canonicalizePath` called on `file`
95
+ result = file.relativeTo conf.docRoot.expandFilename.AbsoluteDir
94
96
else :
95
97
bail ()
96
98
if isAbsolute (result .string ):
@@ -1125,11 +1127,8 @@ proc genSection(d: PDoc, kind: TSymKind) =
1125
1127
" sectionid" , " sectionTitle" , " sectionTitleID" , " content" ], [
1126
1128
ord (kind).rope, title, rope (ord (kind) + 50 ), d.toc[kind]])
1127
1129
1128
- const nimdocOutCss = " nimdoc.out.css"
1129
- # `out` to make it easier to use with gitignore in user's repos
1130
-
1131
- proc cssHref (outDir: AbsoluteDir , destFile: AbsoluteFile ): Rope =
1132
- rope ($ relativeTo (outDir / nimdocOutCss.RelativeFile , destFile.splitFile ().dir, '/' ))
1130
+ proc relLink (outDir: AbsoluteDir , destFile: AbsoluteFile , linkto: RelativeFile ): Rope =
1131
+ rope ($ relativeTo (outDir / linkto, destFile.splitFile ().dir, '/' ))
1133
1132
1134
1133
proc genOutFile (d: PDoc ): Rope =
1135
1134
var
@@ -1160,15 +1159,17 @@ proc genOutFile(d: PDoc): Rope =
1160
1159
elif d.hasToc: " doc.body_toc"
1161
1160
else : " doc.body_no_toc"
1162
1161
content = ropeFormatNamedVars (d.conf, getConfigVar (d.conf, bodyname), [" title" ,
1163
- " tableofcontents" , " moduledesc" , " date" , " time" , " content" , " deprecationMsg" ],
1162
+ " tableofcontents" , " moduledesc" , " date" , " time" , " content" , " deprecationMsg" , " theindexhref " ],
1164
1163
[title.rope, toc, d.modDesc, rope (getDateStr ()),
1165
- rope (getClockStr ()), code, d.modDeprecationMsg])
1164
+ rope (getClockStr ()), code, d.modDeprecationMsg, relLink (d.conf.outDir, d.destFile, theindexFname. RelativeFile ) ])
1166
1165
if optCompileOnly notin d.conf.globalOptions:
1167
1166
# XXX what is this hack doing here? 'optCompileOnly' means raw output!?
1168
1167
code = ropeFormatNamedVars (d.conf, getConfigVar (d.conf, " doc.file" ), [
1169
- " nimdoccss" , " title" , " tableofcontents" , " moduledesc" , " date" , " time" ,
1168
+ " nimdoccss" , " dochackjs " , " title" , " tableofcontents" , " moduledesc" , " date" , " time" ,
1170
1169
" content" , " author" , " version" , " analytics" , " deprecationMsg" ],
1171
- [cssHref (d.conf.outDir, d.destFile), title.rope, toc, d.modDesc, rope (getDateStr ()), rope (getClockStr ()),
1170
+ [relLink (d.conf.outDir, d.destFile, nimdocOutCss.RelativeFile ),
1171
+ relLink (d.conf.outDir, d.destFile, docHackJsFname.RelativeFile ),
1172
+ title.rope, toc, d.modDesc, rope (getDateStr ()), rope (getClockStr ()),
1172
1173
content, d.meta[metaAuthor].rope, d.meta[metaVersion].rope, d.analytics.rope, d.modDeprecationMsg])
1173
1174
else :
1174
1175
code = content
@@ -1203,11 +1204,13 @@ proc writeOutput*(d: PDoc, useWarning = false) =
1203
1204
if not writeRope (content, outfile):
1204
1205
rawMessage (d.conf, if useWarning: warnCannotOpenFile else : errCannotOpenFile,
1205
1206
outfile.string )
1206
- elif not d.wroteCss:
1207
- let cssSource = $ d.conf.getPrefixDir () / " doc" / " nimdoc.css"
1208
- let cssDest = $ dir / nimdocOutCss
1209
- copyFile (cssSource, cssDest)
1210
- d.wroteCss = true
1207
+ elif not d.wroteSupportFiles: # nimdoc.css + dochack.js
1208
+ let nimr = $ d.conf.getPrefixDir ()
1209
+ copyFile (docCss.interp (nimr = nimr), $ d.conf.outDir / nimdocOutCss)
1210
+ if optGenIndex in d.conf.globalOptions:
1211
+ let docHackJs2 = getDocHacksJs (nimr, nim = getAppFilename ())
1212
+ copyFile (docHackJs2, $ d.conf.outDir / docHackJs2.lastPathPart)
1213
+ d.wroteSupportFiles = true
1211
1214
1212
1215
proc writeOutputJson * (d: PDoc , useWarning = false ) =
1213
1216
runAllExamples (d)
@@ -1234,6 +1237,8 @@ proc writeOutputJson*(d: PDoc, useWarning = false) =
1234
1237
proc handleDocOutputOptions * (conf: ConfigRef ) =
1235
1238
if optWholeProject in conf.globalOptions:
1236
1239
# Backward compatibility with previous versions
1240
+ # xxx this is buggy when user provides `nim doc --project -o:sub/bar.html main`,
1241
+ # it'd write to `sub/bar.html/main.html`
1237
1242
conf.outDir = AbsoluteDir (conf.outDir / conf.outFile)
1238
1243
1239
1244
proc commandDoc * (cache: IdentCache , conf: ConfigRef ) =
@@ -1308,20 +1313,23 @@ proc commandTags*(cache: IdentCache, conf: ConfigRef) =
1308
1313
if not writeRope (content, filename):
1309
1314
rawMessage (conf, errCannotOpenFile, filename.string )
1310
1315
1311
- proc commandBuildIndex * (cache: IdentCache , conf: ConfigRef ) =
1312
- var content = mergeIndexes (conf.projectFull. string ).rope
1316
+ proc commandBuildIndex * (conf: ConfigRef , dir: string , outFile = RelativeFile " " ) =
1317
+ var content = mergeIndexes (dir ).rope
1313
1318
1314
- var outFile = RelativeFile " theindex"
1315
- if conf.outFile != RelativeFile " " :
1316
- outFile = conf.outFile
1319
+ var outFile = outFile
1320
+ if outFile.isEmpty: outFile = theindexFname.RelativeFile .changeFileExt (" " )
1317
1321
let filename = getOutFile (conf, outFile, HtmlExt )
1318
1322
1319
1323
let code = ropeFormatNamedVars (conf, getConfigVar (conf, " doc.file" ), [
1320
- " nimdoccss" , " title" , " tableofcontents" , " moduledesc" , " date" , " time" ,
1324
+ " nimdoccss" , " dochackjs" ,
1325
+ " title" , " tableofcontents" , " moduledesc" , " date" , " time" ,
1321
1326
" content" , " author" , " version" , " analytics" ],
1322
- [cssHref (conf.outDir, filename), rope " Index" , nil , nil , rope (getDateStr ()),
1327
+ [relLink (conf.outDir, filename, nimdocOutCss.RelativeFile ),
1328
+ relLink (conf.outDir, filename, docHackJsFname.RelativeFile ),
1329
+ rope " Index" , nil , nil , rope (getDateStr ()),
1323
1330
rope (getClockStr ()), content, nil , nil , nil ])
1324
1331
# no analytics because context is not available
1325
1332
1326
1333
if not writeRope (code, filename):
1327
1334
rawMessage (conf, errCannotOpenFile, filename.string )
1335
+
0 commit comments