mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-07 13:33:22 +00:00
* nim doc now shows correct import name in title
This commit is contained in:
@@ -63,7 +63,22 @@ proc prettyString(a: object): string =
|
||||
for k, v in fieldPairs(a):
|
||||
result.add k & ": " & $v & "\n"
|
||||
|
||||
proc presentationPath*(conf: ConfigRef, file: AbsoluteFile, isTitle = false): RelativeFile =
|
||||
proc canonicalImport*(conf: ConfigRef, file: AbsoluteFile): string =
|
||||
##[
|
||||
Shows the canonical module import, e.g.:
|
||||
system, std/tables, fusion/pointers, system/assertions, std/private/asciitables
|
||||
]##
|
||||
var ret = getRelativePathFromConfigPath(conf, file, isTitle = true)
|
||||
let dir = getNimbleFile(conf, $file).parentDir.AbsoluteDir
|
||||
if not dir.isEmpty:
|
||||
let relPath = relativeTo(file, dir)
|
||||
if not relPath.isEmpty and (ret.isEmpty or relPath.string.len < ret.string.len):
|
||||
ret = relPath
|
||||
if ret.isEmpty:
|
||||
ret = relativeTo(file, conf.projectPath)
|
||||
result = ret.string.nativeToUnixPath.changeFileExt("")
|
||||
|
||||
proc presentationPath*(conf: ConfigRef, file: AbsoluteFile): RelativeFile =
|
||||
## returns a relative file that will be appended to outDir
|
||||
let file2 = $file
|
||||
template bail() =
|
||||
@@ -97,10 +112,7 @@ proc presentationPath*(conf: ConfigRef, file: AbsoluteFile, isTitle = false): Re
|
||||
bail()
|
||||
if isAbsolute(result.string):
|
||||
result = file.string.splitPath()[1].RelativeFile
|
||||
if isTitle:
|
||||
result = result.string.nativeToUnixPath.RelativeFile
|
||||
else:
|
||||
result = result.string.replace("..", dotdotMangle).RelativeFile
|
||||
result = result.string.replace("..", dotdotMangle).RelativeFile
|
||||
doAssert not result.isEmpty
|
||||
doAssert not isAbsolute(result.string)
|
||||
|
||||
@@ -1259,8 +1271,7 @@ proc genOutFile(d: PDoc, groupedToc = false): Rope =
|
||||
setIndexTerm(d[], external, "", title)
|
||||
else:
|
||||
# Modules get an automatic title for the HTML, but no entry in the index.
|
||||
# better than `extractFilename(changeFileExt(d.filename, ""))` as it disambiguates dups
|
||||
title = $presentationPath(d.conf, AbsoluteFile d.filename, isTitle = true).changeFileExt("")
|
||||
title = canonicalImport(d.conf, AbsoluteFile d.filename)
|
||||
var subtitle = "".rope
|
||||
if d.meta[metaSubtitle] != "":
|
||||
dispA(d.conf, subtitle, "<h2 class=\"subtitle\">$1</h2>",
|
||||
|
||||
@@ -761,8 +761,25 @@ when (NimMajor, NimMinor) < (1, 1) or not declared(isRelativeTo):
|
||||
let ret = relativePath(path, base)
|
||||
result = path.len > 0 and not ret.startsWith ".."
|
||||
|
||||
proc getRelativePathFromConfigPath*(conf: ConfigRef; f: AbsoluteFile): RelativeFile =
|
||||
const stdlibDirs = [
|
||||
"pure", "core", "arch",
|
||||
"pure/collections",
|
||||
"pure/concurrency",
|
||||
"pure/unidecode", "impure",
|
||||
"wrappers", "wrappers/linenoise",
|
||||
"windows", "posix", "js"]
|
||||
|
||||
const
|
||||
pkgPrefix = "pkg/"
|
||||
stdPrefix = "std/"
|
||||
|
||||
proc getRelativePathFromConfigPath*(conf: ConfigRef; f: AbsoluteFile, isTitle = false): RelativeFile =
|
||||
let f = $f
|
||||
if isTitle:
|
||||
for dir in stdlibDirs:
|
||||
let path = conf.libpath.string / dir / f.lastPathPart
|
||||
if path.cmpPaths(f) == 0:
|
||||
return RelativeFile(stdPrefix & f.splitFile.name)
|
||||
template search(paths) =
|
||||
for it in paths:
|
||||
let it = $it
|
||||
@@ -784,18 +801,8 @@ proc findFile*(conf: ConfigRef; f: string; suppressStdlib = false): AbsoluteFile
|
||||
result = rawFindFile2(conf, RelativeFile f.toLowerAscii)
|
||||
patchModule(conf)
|
||||
|
||||
const stdlibDirs = [
|
||||
"pure", "core", "arch",
|
||||
"pure/collections",
|
||||
"pure/concurrency",
|
||||
"pure/unidecode", "impure",
|
||||
"wrappers", "wrappers/linenoise",
|
||||
"windows", "posix", "js"]
|
||||
|
||||
proc findModule*(conf: ConfigRef; modulename, currentModule: string): AbsoluteFile =
|
||||
# returns path to module
|
||||
const pkgPrefix = "pkg/"
|
||||
const stdPrefix = "std/"
|
||||
var m = addFileExt(modulename, NimExt)
|
||||
if m.startsWith(pkgPrefix):
|
||||
result = findFile(conf, m.substr(pkgPrefix.len), suppressStdlib = true)
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
<link href='https://fonts.googleapis.com/css?family=Source+Code+Pro:400,500,600' rel='stylesheet' type='text/css'/>
|
||||
|
||||
<!-- CSS -->
|
||||
<title>foo</title>
|
||||
<title>nimdoc/test_out_index_dot_html/foo</title>
|
||||
<link rel="stylesheet" type="text/css" href="nimdoc.out.css">
|
||||
|
||||
<script type="text/javascript" src="dochack.js"></script>
|
||||
@@ -64,7 +64,7 @@ window.addEventListener('DOMContentLoaded', main);
|
||||
<body>
|
||||
<div class="document" id="documentId">
|
||||
<div class="container">
|
||||
<h1 class="title">foo</h1>
|
||||
<h1 class="title">nimdoc/test_out_index_dot_html/foo</h1>
|
||||
<div class="row">
|
||||
<div class="three columns">
|
||||
<div class="theme-switch-wrapper">
|
||||
|
||||
Reference in New Issue
Block a user