diff options
Diffstat (limited to 'compiler/docgen2.nim')
-rw-r--r-- | compiler/docgen2.nim | 56 |
1 files changed, 34 insertions, 22 deletions
diff --git a/compiler/docgen2.nim b/compiler/docgen2.nim index 068c47bb3..7fb11a3bd 100644 --- a/compiler/docgen2.nim +++ b/compiler/docgen2.nim @@ -11,58 +11,70 @@ # semantic checking. import - os, options, ast, astalgo, msgs, ropes, idents, passes, docgen, lineinfos + options, ast, msgs, docgen, lineinfos, pathutils, packages -from modulegraphs import ModuleGraph +from modulegraphs import ModuleGraph, PPassContext type - TGen = object of TPassContext + TGen = object of PPassContext doc: PDoc module: PSym + config: ConfigRef PGen = ref TGen +proc shouldProcess(g: PGen): bool = + (optWholeProject in g.doc.conf.globalOptions and g.doc.conf.belongsToProjectPackage(g.module)) or + sfMainModule in g.module.flags or g.config.projectMainIdx == g.module.info.fileIndex + template closeImpl(body: untyped) {.dirty.} = var g = PGen(p) let useWarning = sfMainModule notin g.module.flags - #echo g.module.name.s, " ", g.module.owner.id, " ", gMainPackageId - if (g.module.owner.id == g.doc.conf.mainPackageId and optWholeProject in g.doc.conf.globalOptions) or - sfMainModule in g.module.flags: + let groupedToc = true + if shouldProcess(g): + finishGenerateDoc(g.doc) body try: generateIndex(g.doc) except IOError: discard -proc close(graph: ModuleGraph; p: PPassContext, n: PNode): PNode = +proc closeDoc*(graph: ModuleGraph; p: PPassContext, n: PNode): PNode = + result = nil closeImpl: - writeOutput(g.doc, toFilename(graph.config, FileIndex g.module.position), HtmlExt, useWarning) + writeOutput(g.doc, useWarning, groupedToc) -proc closeJson(graph: ModuleGraph; p: PPassContext, n: PNode): PNode = +proc closeJson*(graph: ModuleGraph; p: PPassContext, n: PNode): PNode = + result = nil closeImpl: - writeOutputJson(g.doc, toFilename(graph.config, FileIndex g.module.position), ".json", useWarning) + writeOutputJson(g.doc, useWarning) -proc processNode(c: PPassContext, n: PNode): PNode = +proc processNode*(c: PPassContext, n: PNode): PNode = result = n var g = PGen(c) - generateDoc(g.doc, n) + if shouldProcess(g): + generateDoc(g.doc, n, n, g.config) -proc processNodeJson(c: PPassContext, n: PNode): PNode = +proc processNodeJson*(c: PPassContext, n: PNode): PNode = result = n var g = PGen(c) - generateJson(g.doc, n) + if shouldProcess(g): + generateJson(g.doc, n, g.config, false) -proc myOpen(graph: ModuleGraph; module: PSym): PPassContext = +template myOpenImpl(ext: untyped) {.dirty.} = var g: PGen new(g) g.module = module - var d = newDocumentor(toFilename(graph.config, FileIndex module.position), graph.cache, graph.config) - d.hasToc = true + g.config = graph.config + var d = newDocumentor(AbsoluteFile toFullPath(graph.config, FileIndex module.position), + graph.cache, graph.config, ext, module, hasToc = true) g.doc = d result = g -const docgen2Pass* = makePass(open = myOpen, process = processNode, close = close) -const docgen2JsonPass* = makePass(open = myOpen, process = processNodeJson, - close = closeJson) +proc openHtml*(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext = + myOpenImpl(HtmlExt) + +proc openTex*(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext = + myOpenImpl(TexExt) -proc finishDoc2Pass*(project: string) = - discard +proc openJson*(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext = + myOpenImpl(JsonExt) |