From dc8ec4296995d81bb6384beab579b6211c452532 Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Thu, 8 Sep 2016 15:06:19 +0200 Subject: [PATCH] documentation now has an 'edit' button --- compiler/docgen.nim | 16 ++++++++++------ config/nimdoc.cfg | 6 ++++-- tools/nimweb.nim | 39 ++++++++++++++++----------------------- 3 files changed, 30 insertions(+), 31 deletions(-) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index bbbec081ac..9c72d5a84a 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -459,13 +459,17 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) = var seeSrcRope: Rope = nil let docItemSeeSrc = getConfigVar("doc.item.seesrc") - if docItemSeeSrc.len > 0 and options.docSeeSrcUrl.len > 0: - let path = n.info.toFilename.extractFilename.rope - let urlRope = ropeFormatNamedVars(options.docSeeSrcUrl, - ["path", "line"], [path, rope($n.info.line)]) + if docItemSeeSrc.len > 0: + let cwd = getCurrentDir() + var path = n.info.toFullPath + if path.startsWith(cwd): + path = path[cwd.len+1 .. ^1].replace('\\', '/') + var commit = getConfigVar("git.commit") + if commit.len == 0: commit = "master" dispA(seeSrcRope, "$1", "", [ropeFormatNamedVars(docItemSeeSrc, - ["path", "line", "url"], [path, - rope($n.info.line), urlRope])]) + ["path", "line", "url", "commit"], [rope path, + rope($n.info.line), rope getConfigVar("git.url"), + rope commit])]) add(d.section[k], ropeFormatNamedVars(getConfigVar("doc.item"), ["name", "header", "desc", "itemID", "header_plain", "itemSym", diff --git a/config/nimdoc.cfg b/config/nimdoc.cfg index 112833e583..195c97a2ee 100644 --- a/config/nimdoc.cfg +++ b/config/nimdoc.cfg @@ -60,8 +60,10 @@ doc.item.toc = """ # * $url: whatever you did pass through the --docSeeSrcUrl switch (which also # gets variables path/line replaced!) doc.item.seesrc = """  Source""" +href="${url}/tree/${commit}/${path}#L${line}" +class="link-seesrc" target="_blank">Source +Edit +""" doc.toc = """