documentation now has an 'edit' button
This commit is contained in:
parent
6699387c9b
commit
dc8ec42969
3 changed files with 30 additions and 31 deletions
|
|
@ -459,13 +459,17 @@ proc genItem(d: PDoc, n, nameNode: PNode, k: TSymKind) =
|
||||||
|
|
||||||
var seeSrcRope: Rope = nil
|
var seeSrcRope: Rope = nil
|
||||||
let docItemSeeSrc = getConfigVar("doc.item.seesrc")
|
let docItemSeeSrc = getConfigVar("doc.item.seesrc")
|
||||||
if docItemSeeSrc.len > 0 and options.docSeeSrcUrl.len > 0:
|
if docItemSeeSrc.len > 0:
|
||||||
let path = n.info.toFilename.extractFilename.rope
|
let cwd = getCurrentDir()
|
||||||
let urlRope = ropeFormatNamedVars(options.docSeeSrcUrl,
|
var path = n.info.toFullPath
|
||||||
["path", "line"], [path, rope($n.info.line)])
|
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,
|
dispA(seeSrcRope, "$1", "", [ropeFormatNamedVars(docItemSeeSrc,
|
||||||
["path", "line", "url"], [path,
|
["path", "line", "url", "commit"], [rope path,
|
||||||
rope($n.info.line), urlRope])])
|
rope($n.info.line), rope getConfigVar("git.url"),
|
||||||
|
rope commit])])
|
||||||
|
|
||||||
add(d.section[k], ropeFormatNamedVars(getConfigVar("doc.item"),
|
add(d.section[k], ropeFormatNamedVars(getConfigVar("doc.item"),
|
||||||
["name", "header", "desc", "itemID", "header_plain", "itemSym",
|
["name", "header", "desc", "itemID", "header_plain", "itemSym",
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,10 @@ doc.item.toc = """
|
||||||
# * $url: whatever you did pass through the --docSeeSrcUrl switch (which also
|
# * $url: whatever you did pass through the --docSeeSrcUrl switch (which also
|
||||||
# gets variables path/line replaced!)
|
# gets variables path/line replaced!)
|
||||||
doc.item.seesrc = """ <a
|
doc.item.seesrc = """ <a
|
||||||
href="${url}/${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>
|
||||||
|
"""
|
||||||
|
|
||||||
doc.toc = """
|
doc.toc = """
|
||||||
<ul class="simple simple-toc" id="toc-list">
|
<ul class="simple simple-toc" id="toc-list">
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import
|
||||||
|
|
||||||
from xmltree import escape
|
from xmltree import escape
|
||||||
|
|
||||||
|
const gitRepo = "https://github.com/nim-lang/Nim"
|
||||||
|
|
||||||
type
|
type
|
||||||
TKeyValPair = tuple[key, id, val: string]
|
TKeyValPair = tuple[key, id, val: string]
|
||||||
TConfigData = object of RootObj
|
TConfigData = object of RootObj
|
||||||
|
|
@ -21,8 +23,6 @@ type
|
||||||
authors, projectName, projectTitle, logo, infile, outdir, ticker: string
|
authors, projectName, projectTitle, logo, infile, outdir, ticker: string
|
||||||
vars: StringTableRef
|
vars: StringTableRef
|
||||||
nimArgs: string
|
nimArgs: string
|
||||||
gitRepo: string
|
|
||||||
gitCommit: string
|
|
||||||
quotations: Table[string, tuple[quote, author: string]]
|
quotations: Table[string, tuple[quote, author: string]]
|
||||||
numProcessors: int # Set by parallelBuild:n, only works for values > 0.
|
numProcessors: int # Set by parallelBuild:n, only works for values > 0.
|
||||||
gaId: string # google analytics ID, nil means analytics are disabled
|
gaId: string # google analytics ID, nil means analytics are disabled
|
||||||
|
|
@ -59,8 +59,6 @@ proc initConfigData(c: var TConfigData) =
|
||||||
c.logo = ""
|
c.logo = ""
|
||||||
c.ticker = ""
|
c.ticker = ""
|
||||||
c.vars = newStringTable(modeStyleInsensitive)
|
c.vars = newStringTable(modeStyleInsensitive)
|
||||||
c.gitRepo = "https://github.com/nim-lang/Nim/tree"
|
|
||||||
c.gitCommit = "master"
|
|
||||||
c.numProcessors = countProcessors()
|
c.numProcessors = countProcessors()
|
||||||
# Attempts to obtain the git current commit.
|
# Attempts to obtain the git current commit.
|
||||||
when false:
|
when false:
|
||||||
|
|
@ -99,12 +97,12 @@ Compile_options:
|
||||||
validAnchorCharacters = Letters + Digits
|
validAnchorCharacters = Letters + Digits
|
||||||
|
|
||||||
|
|
||||||
macro id(e: expr): expr {.immediate.} =
|
macro id(e: untyped): untyped =
|
||||||
## generates the rss xml ``id`` element.
|
## generates the rss xml ``id`` element.
|
||||||
let e = callsite()
|
let e = callsite()
|
||||||
result = xmlCheckedTag(e, "id")
|
result = xmlCheckedTag(e, "id")
|
||||||
|
|
||||||
macro updated(e: expr): expr {.immediate.} =
|
macro updated(e: varargs[untyped]): untyped =
|
||||||
## generates the rss xml ``updated`` element.
|
## generates the rss xml ``updated`` element.
|
||||||
let e = callsite()
|
let e = callsite()
|
||||||
result = xmlCheckedTag(e, "updated")
|
result = xmlCheckedTag(e, "updated")
|
||||||
|
|
@ -115,12 +113,12 @@ proc updatedDate(year, month, day: string): string =
|
||||||
repeat("0", 2 - len(month)) & month,
|
repeat("0", 2 - len(month)) & month,
|
||||||
repeat("0", 2 - len(day)) & day])
|
repeat("0", 2 - len(day)) & day])
|
||||||
|
|
||||||
macro entry(e: expr): expr {.immediate.} =
|
macro entry(e: varargs[untyped]): untyped =
|
||||||
## generates the rss xml ``entry`` element.
|
## generates the rss xml ``entry`` element.
|
||||||
let e = callsite()
|
let e = callsite()
|
||||||
result = xmlCheckedTag(e, "entry")
|
result = xmlCheckedTag(e, "entry")
|
||||||
|
|
||||||
macro content(e: expr): expr {.immediate.} =
|
macro content(e: varargs[untyped]): untyped =
|
||||||
## generates the rss xml ``content`` element.
|
## generates the rss xml ``content`` element.
|
||||||
let e = callsite()
|
let e = callsite()
|
||||||
result = xmlCheckedTag(e, "content", reqAttr = "type")
|
result = xmlCheckedTag(e, "content", reqAttr = "type")
|
||||||
|
|
@ -245,11 +243,6 @@ proc parseIniFile(c: var TConfigData) =
|
||||||
c.projectName = changeFileExt(extractFilename(c.infile), "")
|
c.projectName = changeFileExt(extractFilename(c.infile), "")
|
||||||
if c.outdir.len == 0:
|
if c.outdir.len == 0:
|
||||||
c.outdir = splitFile(c.infile).dir
|
c.outdir = splitFile(c.infile).dir
|
||||||
# Ugly hack to override git command output when building private repo.
|
|
||||||
if c.vars.hasKey("githash"):
|
|
||||||
let githash = c.vars["githash"].strip
|
|
||||||
if githash.len > 0:
|
|
||||||
c.gitCommit = githash
|
|
||||||
|
|
||||||
# ------------------- main ----------------------------------------------------
|
# ------------------- main ----------------------------------------------------
|
||||||
|
|
||||||
|
|
@ -303,18 +296,18 @@ proc buildDoc(c: var TConfigData, destPath: string) =
|
||||||
commands = newSeq[string](len(c.doc) + len(c.srcdoc) + len(c.srcdoc2))
|
commands = newSeq[string](len(c.doc) + len(c.srcdoc) + len(c.srcdoc2))
|
||||||
i = 0
|
i = 0
|
||||||
for d in items(c.doc):
|
for d in items(c.doc):
|
||||||
commands[i] = findNim() & " rst2html $# --docSeeSrcUrl:$#/$#/$# -o:$# --index:on $#" %
|
commands[i] = findNim() & " rst2html $# --git.url:$# -o:$# --index:on $#" %
|
||||||
[c.nimArgs, c.gitRepo, c.gitCommit, d.pathPart,
|
[c.nimArgs, gitRepo,
|
||||||
destPath / changeFileExt(splitFile(d).name, "html"), d]
|
destPath / changeFileExt(splitFile(d).name, "html"), d]
|
||||||
i.inc
|
i.inc
|
||||||
for d in items(c.srcdoc):
|
for d in items(c.srcdoc):
|
||||||
commands[i] = findNim() & " doc $# --docSeeSrcUrl:$#/$#/$# -o:$# --index:on $#" %
|
commands[i] = findNim() & " doc $# --git.url:$# -o:$# --index:on $#" %
|
||||||
[c.nimArgs, c.gitRepo, c.gitCommit, d.pathPart,
|
[c.nimArgs, gitRepo,
|
||||||
destPath / changeFileExt(splitFile(d).name, "html"), d]
|
destPath / changeFileExt(splitFile(d).name, "html"), d]
|
||||||
i.inc
|
i.inc
|
||||||
for d in items(c.srcdoc2):
|
for d in items(c.srcdoc2):
|
||||||
commands[i] = findNim() & " doc2 $# --docSeeSrcUrl:$#/$#/$# -o:$# --index:on $#" %
|
commands[i] = findNim() & " doc2 $# --git.url:$# -o:$# --index:on $#" %
|
||||||
[c.nimArgs, c.gitRepo, c.gitCommit, d.pathPart,
|
[c.nimArgs, gitRepo,
|
||||||
destPath / changeFileExt(splitFile(d).name, "html"), d]
|
destPath / changeFileExt(splitFile(d).name, "html"), d]
|
||||||
i.inc
|
i.inc
|
||||||
|
|
||||||
|
|
@ -346,8 +339,8 @@ proc buildAddDoc(c: var TConfigData, destPath: string) =
|
||||||
# build additional documentation (without the index):
|
# build additional documentation (without the index):
|
||||||
var commands = newSeq[string](c.webdoc.len)
|
var commands = newSeq[string](c.webdoc.len)
|
||||||
for i, doc in pairs(c.webdoc):
|
for i, doc in pairs(c.webdoc):
|
||||||
commands[i] = findNim() & " doc2 $# --docSeeSrcUrl:$#/$# -o:$# $#" %
|
commands[i] = findNim() & " doc2 $# --git.url:$# -o:$# $#" %
|
||||||
[c.nimArgs, c.gitRepo, c.gitCommit,
|
[c.nimArgs, gitRepo,
|
||||||
destPath / changeFileExt(splitFile(doc).name, "html"), doc]
|
destPath / changeFileExt(splitFile(doc).name, "html"), doc]
|
||||||
mexec(commands, c.numProcessors)
|
mexec(commands, c.numProcessors)
|
||||||
|
|
||||||
|
|
@ -520,8 +513,8 @@ proc json2(c: var TConfigData) =
|
||||||
var i = 0
|
var i = 0
|
||||||
for d in items(c.srcdoc2):
|
for d in items(c.srcdoc2):
|
||||||
createDir(destPath / splitFile(d).dir)
|
createDir(destPath / splitFile(d).dir)
|
||||||
commands[i] = findNim() & " jsondoc2 $# --docSeeSrcUrl:$#/$#/$# -o:$# --index:on $#" %
|
commands[i] = findNim() & " jsondoc2 $# --git.url:$# -o:$# --index:on $#" %
|
||||||
[c.nimArgs, c.gitRepo, c.gitCommit, d.pathPart,
|
[c.nimArgs, gitRepo,
|
||||||
destPath / changeFileExt(d, "json"), d]
|
destPath / changeFileExt(d, "json"), d]
|
||||||
i.inc
|
i.inc
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue