Skip to content

Commit

Permalink
fix nim-lang#12998 nim doc regression
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Jan 15, 2020
1 parent d88b52c commit 39ed80e
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,5 @@ megatest.nim

# ignore debug dirs generated by dsymutil on OSX
*.dSYM

nimdoc.out.css
13 changes: 12 additions & 1 deletion compiler/docgen.nim
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ type
destFile*: AbsoluteFile
thisDir*: AbsoluteDir
examples: string
wroteCss*: bool

PDoc* = ref TDocumentor ## Alias to type less.

Expand Down Expand Up @@ -1060,6 +1061,8 @@ proc generateIndex*(d: PDoc) =
d.conf.projectPath), IndexExt)
writeIndexFile(d[], dest.string)

const nimRepoDir = currentSourcePath / ".." / ".." # this should be exposed somewhere

proc writeOutput*(d: PDoc, useWarning = false) =
runAllExamples(d)
var content = genOutFile(d)
Expand All @@ -1068,10 +1071,18 @@ proc writeOutput*(d: PDoc, useWarning = false) =
else:
template outfile: untyped = d.destFile
#let outfile = getOutFile2(d.conf, shortenDir(d.conf, filename), outExt, "htmldocs")
createDir(outfile.splitFile.dir)
let dir = outfile.`$`.parentDir
createDir(dir)
if not writeRope(content, outfile):
rawMessage(d.conf, if useWarning: warnCannotOpenFile else: errCannotOpenFile,
outfile.string)
else:
if not d.wroteCss:
let cssSource = nimRepoDir / "doc" / "nimdoc.css"
let cssDest = $d.conf.outDir / "nimdoc.out.css"
# renamed to make it easier to use with gitignore in user's repos
copyFile(cssSource, cssDest)
d.wroteCss = true
d.conf.outFile = outfile.extractFilename.RelativeFile

proc writeOutputJson*(d: PDoc, useWarning = false) =
Expand Down
2 changes: 1 addition & 1 deletion config/nimdoc.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ doc.file = """<?xml version="1.0" encoding="utf-8" ?>

<!-- CSS -->
<title>$title</title>
<link rel="stylesheet" type="text/css" href="nimdoc.css">
<link rel="stylesheet" type="text/css" href="/nimdoc.out.css">

<script type="text/javascript" src="dochack.js"></script>

Expand Down
4 changes: 3 additions & 1 deletion koch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ when defined(i386) and defined(windows) and defined(vcc):
{.link: "icons/koch-i386-windows-vcc.res".}

import
os, strutils, parseopt, osproc, streams
os, strutils, parseopt, osproc

import tools / kochdocs

Expand All @@ -45,6 +45,7 @@ Options:
--help, -h shows this help and quits
--latest bundle the installers with a bleeding edge Nimble
--stable bundle the installers with a stable Nimble (default)
--nim:path use specified path for nim binary
Possible Commands:
boot [options] bootstraps with given command line options
distrohelper [bindir] helper for distro packagers
Expand Down Expand Up @@ -605,6 +606,7 @@ when isMainModule:
case normalize(op.key)
of "latest": latest = true
of "stable": latest = false
of "nim": nimExe = op.val.absolutePath # absolute so still works with changeDir
else: showHelp()
of cmdArgument:
case normalize(op.key)
Expand Down
2 changes: 1 addition & 1 deletion nimdoc/test_out_index_dot_html/expected/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- CSS -->
<title>foo</title>
<link rel="stylesheet" type="text/css" href="nimdoc.css">
<link rel="stylesheet" type="text/css" href="/nimdoc.out.css">

<script type="text/javascript" src="dochack.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion nimdoc/test_out_index_dot_html/expected/theindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- CSS -->
<title>Index</title>
<link rel="stylesheet" type="text/css" href="nimdoc.css">
<link rel="stylesheet" type="text/css" href="/nimdoc.out.css">

<script type="text/javascript" src="dochack.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion nimdoc/testproject/expected/subdir/subdir_b/utils.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- CSS -->
<title>utils</title>
<link rel="stylesheet" type="text/css" href="nimdoc.css">
<link rel="stylesheet" type="text/css" href="/nimdoc.out.css">

<script type="text/javascript" src="dochack.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion nimdoc/testproject/expected/testproject.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- CSS -->
<title>testproject</title>
<link rel="stylesheet" type="text/css" href="nimdoc.css">
<link rel="stylesheet" type="text/css" href="/nimdoc.out.css">

<script type="text/javascript" src="dochack.js"></script>

Expand Down
2 changes: 1 addition & 1 deletion nimdoc/testproject/expected/theindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<!-- CSS -->
<title>Index</title>
<link rel="stylesheet" type="text/css" href="nimdoc.css">
<link rel="stylesheet" type="text/css" href="/nimdoc.out.css">

<script type="text/javascript" src="dochack.js"></script>

Expand Down
9 changes: 3 additions & 6 deletions tools/kochdocs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ const
webUploadOutput = "web/upload"
docHackDir = "tools/dochack"

var nimExe*: string

proc exe*(f: string): string =
result = addFileExt(f, ExeExt)
when defined(windows):
result = result.replace('/','\\')

proc findNim*(): string =
if nimExe.len > 0: return nimExe
var nim = "nim".exe
result = "bin" / nim
if existsFile(result): return
Expand Down Expand Up @@ -366,14 +369,11 @@ proc buildJS() =
proc buildDocs*(args: string) =
const
docHackJs = "dochack.js"
css = "nimdoc.css"
let
a = nimArgs & " " & args
docHackJsSource = docHackDir / docHackJs
docHackJsDest = docHtmlOutput / docHackJs

cssSource = "doc" / css
cssDest = docHtmlOutput / css
buildJS() # This call generates docHackJsSource
let docup = webUploadOutput / NimVersion
createDir(docup)
Expand All @@ -387,6 +387,3 @@ proc buildDocs*(args: string) =
buildDoc(nimArgs, docHtmlOutput)
copyFile(docHackJsSource, docHackJsDest)
copyFile(docHackJsSource, docup / docHackJs)

copyFile(cssSource, cssDest)
copyFile(cssSource, docup / css)

0 comments on commit 39ed80e

Please sign in to comment.