diff options
-rw-r--r-- | changelog.md | 1 | ||||
-rw-r--r-- | compiler/commands.nim | 2 | ||||
-rw-r--r-- | compiler/docgen.nim | 46 | ||||
-rw-r--r-- | config/nimdoc.cfg | 3 | ||||
-rw-r--r-- | nimdoc/test_out_index_dot_html/expected/index.html | 1 | ||||
-rw-r--r-- | nimdoc/testproject/expected/subdir/subdir_b/utils.html | 1 | ||||
-rw-r--r-- | nimdoc/testproject/expected/testproject.html | 1 |
7 files changed, 32 insertions, 23 deletions
diff --git a/changelog.md b/changelog.md index dcaffe23c..66c9131cd 100644 --- a/changelog.md +++ b/changelog.md @@ -12,6 +12,7 @@ ## Compiler changes 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 diff --git a/compiler/commands.nim b/compiler/commands.nim index 325b362a9..93a202639 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -396,6 +396,8 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo; var key, val: string case switch.normalize + of "input", "i": # PRTEMP + expectArg(conf, switch, arg, pass, info) of "path", "p": expectArg(conf, switch, arg, pass, info) for path in nimbleSubs(conf, arg): diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 6c77a44ae..3945a30f8 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -777,6 +777,26 @@ type DocFlags = enum kDefault 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) = if (docFlags != kForceExport) and not isVisible(d, nameNode): return let @@ -822,26 +842,7 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind, docFlags: DocFlags) = nodeToHighlightedHtml(d, n, result, {renderNoBody, renderNoComments, renderDocComments, renderSyms}, symbolOrIdEncRope) - var seeSrcRope: Rope = nil - 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])]) - + let seeSrcRope = genSeeSrcRope(d, toFullPath(d.conf, n.info), n.info.line.int) d.section[k].add(ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.item"), ["name", "header", "desc", "itemID", "header_plain", "itemSym", "itemSymOrID", "itemSymEnc", "itemSymOrIDEnc", "seeSrc", "deprecationMsg"], @@ -1234,10 +1235,11 @@ proc genOutFile(d: PDoc, groupedToc = false): Rope = "doc.body_toc_group" elif d.hasToc: "doc.body_toc" else: "doc.body_no_toc" + let seeSrcRope = genSeeSrcRope(d, d.filename, 1) 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()), - 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: # XXX what is this hack doing here? 'optCompileOnly' means raw output!? code = ropeFormatNamedVars(d.conf, getConfigVar(d.conf, "doc.file"), [ diff --git a/config/nimdoc.cfg b/config/nimdoc.cfg index 13beb5af1..db86af021 100644 --- a/config/nimdoc.cfg +++ b/config/nimdoc.cfg @@ -80,7 +80,7 @@ doc.item.tocTable = """ doc.item.seesrc = """ <a href="${url}/tree/${commit}/${path}#L${line}" 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 = """ @@ -187,6 +187,7 @@ doc.body_toc_group = """ </div> $tableofcontents </div> + $seeSrc <div class="nine columns" id="content"> <div id="tocRoot"></div> $deprecationMsg diff --git a/nimdoc/test_out_index_dot_html/expected/index.html b/nimdoc/test_out_index_dot_html/expected/index.html index d6e318f7d..58ab4fc6d 100644 --- a/nimdoc/test_out_index_dot_html/expected/index.html +++ b/nimdoc/test_out_index_dot_html/expected/index.html @@ -106,6 +106,7 @@ function main() { </ul> </div> + <div class="nine columns" id="content"> <div id="tocRoot"></div> diff --git a/nimdoc/testproject/expected/subdir/subdir_b/utils.html b/nimdoc/testproject/expected/subdir/subdir_b/utils.html index ebbedc648..5acf196b0 100644 --- a/nimdoc/testproject/expected/subdir/subdir_b/utils.html +++ b/nimdoc/testproject/expected/subdir/subdir_b/utils.html @@ -132,6 +132,7 @@ function main() { </ul> </div> + <div class="nine columns" id="content"> <div id="tocRoot"></div> diff --git a/nimdoc/testproject/expected/testproject.html b/nimdoc/testproject/expected/testproject.html index a5522a2e2..922319914 100644 --- a/nimdoc/testproject/expected/testproject.html +++ b/nimdoc/testproject/expected/testproject.html @@ -358,6 +358,7 @@ function main() { </ul> </div> + <div class="nine columns" id="content"> <div id="tocRoot"></div> |