add Source+Edit links on top of every docgend file (#15642)
This commit is contained in:
parent
b2f51e2950
commit
0979524137
7 changed files with 32 additions and 23 deletions
|
|
@ -12,6 +12,7 @@
|
||||||
|
|
||||||
## Compiler changes
|
## Compiler changes
|
||||||
add `--declaredlocs` to show symbol declaration location in messages
|
add `--declaredlocs` to show symbol declaration location in messages
|
||||||
|
* Source+Edit links now appear on top of every docgen'd page when `nim doc --git.url:url ...` is given
|
||||||
|
|
||||||
|
|
||||||
## Tool changes
|
## Tool changes
|
||||||
|
|
|
||||||
|
|
@ -396,6 +396,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
var
|
var
|
||||||
key, val: string
|
key, val: string
|
||||||
case switch.normalize
|
case switch.normalize
|
||||||
|
of "input", "i": # PRTEMP
|
||||||
|
expectArg(conf, switch, arg, pass, info)
|
||||||
of "path", "p":
|
of "path", "p":
|
||||||
expectArg(conf, switch, arg, pass, info)
|
expectArg(conf, switch, arg, pass, info)
|
||||||
for path in nimbleSubs(conf, arg):
|
for path in nimbleSubs(conf, arg):
|
||||||
|
|
|
||||||
|
|
@ -777,6 +777,26 @@ type DocFlags = enum
|
||||||
kDefault
|
kDefault
|
||||||
kForceExport
|
kForceExport
|
||||||
|
|
||||||
|
proc genSeeSrcRope(d: PDoc, path: string, line: int): Rope =
|
||||||
|
let docItemSeeSrc = getConfigVar(d.conf, "doc.item.seesrc")
|
||||||
|
if docItemSeeSrc.len > 0:
|
||||||
|
let path = relativeTo(AbsoluteFile path, AbsoluteDir getCurrentDir(), '/')
|
||||||
|
when false:
|
||||||
|
let cwd = canonicalizePath(d.conf, getCurrentDir())
|
||||||
|
var path = path
|
||||||
|
if path.startsWith(cwd):
|
||||||
|
path = path[cwd.len+1..^1].replace('\\', '/')
|
||||||
|
let gitUrl = getConfigVar(d.conf, "git.url")
|
||||||
|
if gitUrl.len > 0:
|
||||||
|
let defaultBranch =
|
||||||
|
if NimPatch mod 2 == 1: "devel"
|
||||||
|
else: "version-$1-$2" % [$NimMajor, $NimMinor]
|
||||||
|
let commit = getConfigVar(d.conf, "git.commit", defaultBranch)
|
||||||
|
let develBranch = getConfigVar(d.conf, "git.devel", "devel")
|
||||||
|
dispA(d.conf, result, "$1", "", [ropeFormatNamedVars(d.conf, docItemSeeSrc,
|
||||||
|
["path", "line", "url", "commit", "devel"], [rope path.string,
|
||||||
|
rope($line), rope gitUrl, rope commit, rope develBranch])])
|
||||||
|
|
||||||
proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
|
proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
|
||||||
if (docFlags != kForceExport) and not isVisible(d, nameNode): return
|
if (docFlags != kForceExport) and not isVisible(d, nameNode): return
|
||||||
let
|
let
|
||||||
|
|
@ -822,26 +842,7 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) =
|
||||||
nodeToHighlightedHtml(d, n, result, {renderNoBody, renderNoComments,
|
nodeToHighlightedHtml(d, n, result, {renderNoBody, renderNoComments,
|
||||||
renderDocComments, renderSyms}, symbolOrIdEncRope)
|
renderDocComments, renderSyms}, symbolOrIdEncRope)
|
||||||
|
|
||||||
var seeSrcRope: Rope = nil
|
let seeSrcRope = genSeeSrcRope(d, toFullPath(d.conf, n.info), n.info.line.int)
|
||||||
let docItemSeeSrc = getConfigVar(d.conf, "doc.item.seesrc")
|
|
||||||
if docItemSeeSrc.len > 0:
|
|
||||||
let path = relativeTo(AbsoluteFile toFullPath(d.conf, n.info), AbsoluteDir getCurrentDir(), '/')
|
|
||||||
when false:
|
|
||||||
let cwd = canonicalizePath(d.conf, getCurrentDir())
|
|
||||||
var path = toFullPath(d.conf, n.info)
|
|
||||||
if path.startsWith(cwd):
|
|
||||||
path = path[cwd.len+1..^1].replace('\\', '/')
|
|
||||||
let gitUrl = getConfigVar(d.conf, "git.url")
|
|
||||||
if gitUrl.len > 0:
|
|
||||||
let defaultBranch =
|
|
||||||
if NimPatch mod 2 == 1: "devel"
|
|
||||||
else: "version-$1-$2" % [$NimMajor, $NimMinor]
|
|
||||||
let commit = getConfigVar(d.conf, "git.commit", defaultBranch)
|
|
||||||
let develBranch = getConfigVar(d.conf, "git.devel", "devel")
|
|
||||||
dispA(d.conf, seeSrcRope, "$1", "", [ropeFormatNamedVars(d.conf, docItemSeeSrc,
|
|
||||||
["path", "line", "url", "commit", "devel"], [rope path.string,
|
|
||||||
rope($n.info.line), rope gitUrl, rope commit, rope develBranch])])
|
|
||||||
|
|
||||||
d.section[k].add(ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.item"),
|
d.section[k].add(ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.item"),
|
||||||
["name", "header", "desc", "itemID", "header_plain", "itemSym",
|
["name", "header", "desc", "itemID", "header_plain", "itemSym",
|
||||||
"itemSymOrID", "itemSymEnc", "itemSymOrIDEnc", "seeSrc", "deprecationMsg"],
|
"itemSymOrID", "itemSymEnc", "itemSymOrIDEnc", "seeSrc", "deprecationMsg"],
|
||||||
|
|
@ -1234,10 +1235,11 @@ proc genOutFile(d: PDoc, groupedToc = false): Rope =
|
||||||
"doc.body_toc_group"
|
"doc.body_toc_group"
|
||||||
elif d.hasToc: "doc.body_toc"
|
elif d.hasToc: "doc.body_toc"
|
||||||
else: "doc.body_no_toc"
|
else: "doc.body_no_toc"
|
||||||
|
let seeSrcRope = genSeeSrcRope(d, d.filename, 1)
|
||||||
content = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, bodyname), ["title",
|
content = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, bodyname), ["title",
|
||||||
"tableofcontents", "moduledesc", "date", "time", "content", "deprecationMsg", "theindexhref", "body_toc_groupsection"],
|
"tableofcontents", "moduledesc", "date", "time", "content", "deprecationMsg", "theindexhref", "body_toc_groupsection", "seeSrc"],
|
||||||
[title.rope, toc, d.modDesc, rope(getDateStr()),
|
[title.rope, toc, d.modDesc, rope(getDateStr()),
|
||||||
rope(getClockStr()), code, d.modDeprecationMsg, relLink(d.conf.outDir, d.destFile.AbsoluteFile, theindexFname.RelativeFile), groupsection.rope])
|
rope(getClockStr()), code, d.modDeprecationMsg, relLink(d.conf.outDir, d.destFile.AbsoluteFile, theindexFname.RelativeFile), groupsection.rope, seeSrcRope])
|
||||||
if optCompileOnly notin d.conf.globalOptions:
|
if optCompileOnly notin d.conf.globalOptions:
|
||||||
# XXX what is this hack doing here? 'optCompileOnly' means raw output!?
|
# XXX what is this hack doing here? 'optCompileOnly' means raw output!?
|
||||||
code = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.file"), [
|
code = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.file"), [
|
||||||
|
|
|
||||||
|
|
@ -80,7 +80,7 @@ doc.item.tocTable = """
|
||||||
doc.item.seesrc = """ <a
|
doc.item.seesrc = """ <a
|
||||||
href="${url}/tree/${commit}/${path}#L${line}"
|
href="${url}/tree/${commit}/${path}#L${line}"
|
||||||
class="link-seesrc" target="_blank">Source</a>
|
class="link-seesrc" target="_blank">Source</a>
|
||||||
<a href="${url}/edit/${devel}/${path}#L${line}" class="link-seesrc" target="_blank" >Edit</a>
|
<a href="${url}/edit/${devel}/${path}#L${line}" class="link-seesrc" target="_blank" >Edit</a>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
doc.deprecationmsg = """
|
doc.deprecationmsg = """
|
||||||
|
|
@ -187,6 +187,7 @@ doc.body_toc_group = """
|
||||||
</div>
|
</div>
|
||||||
$tableofcontents
|
$tableofcontents
|
||||||
</div>
|
</div>
|
||||||
|
$seeSrc
|
||||||
<div class="nine columns" id="content">
|
<div class="nine columns" id="content">
|
||||||
<div id="tocRoot"></div>
|
<div id="tocRoot"></div>
|
||||||
$deprecationMsg
|
$deprecationMsg
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ function main() {
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nine columns" id="content">
|
<div class="nine columns" id="content">
|
||||||
<div id="tocRoot"></div>
|
<div id="tocRoot"></div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -132,6 +132,7 @@ function main() {
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nine columns" id="content">
|
<div class="nine columns" id="content">
|
||||||
<div id="tocRoot"></div>
|
<div id="tocRoot"></div>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -358,6 +358,7 @@ function main() {
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="nine columns" id="content">
|
<div class="nine columns" id="content">
|
||||||
<div id="tocRoot"></div>
|
<div id="tocRoot"></div>
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue