the documentation generator now supports ':test:' for the testing of test snippets
This commit is contained in:
parent
21ffb3a706
commit
5d2e86ea1a
7 changed files with 60 additions and 34 deletions
|
|
@ -61,6 +61,9 @@ type
|
|||
seenIndexTerms: Table[string, int] ## \
|
||||
## Keeps count of same text index terms to generate different identifiers
|
||||
## for hyperlinks. See renderIndexTerm proc for details.
|
||||
id*: int ## A counter useful for generating IDs.
|
||||
onTestSnippet*: proc (d: var RstGenerator; filename, cmd: string; status: int;
|
||||
content: string)
|
||||
|
||||
PDoc = var RstGenerator ## Alias to type less.
|
||||
|
||||
|
|
@ -69,8 +72,9 @@ type
|
|||
startLine: int ## The starting line of the code block, by default 1.
|
||||
langStr: string ## Input string used to specify the language.
|
||||
lang: SourceLanguage ## Type of highlighting, by default none.
|
||||
{.deprecated: [TRstGenerator: RstGenerator, TTocEntry: TocEntry,
|
||||
TOutputTarget: OutputTarget, TMetaEnum: MetaEnum].}
|
||||
filename: string
|
||||
testCmd: string
|
||||
status: int
|
||||
|
||||
proc init(p: var CodeBlockParams) =
|
||||
## Default initialisation of CodeBlockParams to sane values.
|
||||
|
|
@ -133,6 +137,7 @@ proc initRstGenerator*(g: var RstGenerator, target: OutputTarget,
|
|||
g.options = options
|
||||
g.findFile = findFile
|
||||
g.currentSection = ""
|
||||
g.id = 0
|
||||
let fileParts = filename.splitFile
|
||||
if fileParts.ext == ".nim":
|
||||
g.currentSection = "Module " & fileParts.name
|
||||
|
|
@ -368,7 +373,6 @@ type
|
|||
##
|
||||
## The value indexed by this IndexEntry is a sequence with the real index
|
||||
## entries found in the ``.idx`` file.
|
||||
{.deprecated: [TIndexEntry: IndexEntry, TIndexedDocs: IndexedDocs].}
|
||||
|
||||
proc cmp(a, b: IndexEntry): int =
|
||||
## Sorts two ``IndexEntry`` first by `keyword` field, then by `link`.
|
||||
|
|
@ -823,13 +827,20 @@ proc parseCodeBlockField(d: PDoc, n: PRstNode, params: var CodeBlockParams) =
|
|||
var number: int
|
||||
if parseInt(n.getFieldValue, number) > 0:
|
||||
params.startLine = number
|
||||
of "file":
|
||||
of "file", "filename":
|
||||
# The ``file`` option is a Nim extension to the official spec, it acts
|
||||
# like it would for other directives like ``raw`` or ``cvs-table``. This
|
||||
# field is dealt with in ``rst.nim`` which replaces the existing block with
|
||||
# the referenced file, so we only need to ignore it here to avoid incorrect
|
||||
# warning messages.
|
||||
discard
|
||||
params.filename = n.getFieldValue.strip
|
||||
of "test":
|
||||
params.testCmd = n.getFieldValue.strip
|
||||
if params.testCmd.len == 0: params.testCmd = "nim c -r $1"
|
||||
of "status":
|
||||
var status: int
|
||||
if parseInt(n.getFieldValue, status) > 0:
|
||||
params.status = status
|
||||
of "default-language":
|
||||
params.langStr = n.getFieldValue.strip
|
||||
params.lang = params.langStr.getSourceLanguage
|
||||
|
|
@ -901,6 +912,9 @@ proc renderCodeBlock(d: PDoc, n: PRstNode, result: var string) =
|
|||
var m = n.sons[2].sons[0]
|
||||
assert m.kind == rnLeaf
|
||||
|
||||
if params.testCmd.len > 0 and d.onTestSnippet != nil:
|
||||
d.onTestSnippet(d, params.filename, params.testCmd, params.status, m.text)
|
||||
|
||||
let (blockStart, blockEnd) = buildLinesHTMLTable(d, params, m.text)
|
||||
|
||||
dispA(d.target, result, blockStart, "\\begin{rstpre}\n", [])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue