Skip to content

Commit

Permalink
add docs; add fusion/docutils
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheecour committed Oct 13, 2020
1 parent 39ccb3f commit acc7f6c
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
6 changes: 5 additions & 1 deletion fusion.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@ srcDir = "src"


# Dependencies

requires "nim >= 1.0.0"

task docs, "":
# can customize, eg:
# exec "nim r src/fusion/docutils " & srcDir & " --outdir:htmldocs2 -d:foo"
exec "nim r src/fusion/docutils " & srcDir
29 changes: 29 additions & 0 deletions src/fusion/docutils.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import std/[os,strformat,sugar,osproc]
import std/private/globs

iterator findNimSrcFiles*(dir: string): string =
proc follow(a: PathEntry): bool =
a.path.lastPathPart notin ["nimcache", "htmldocs"]
for entry in walkDirRecFilter(dir, follow = follow):
if entry.path.splitFile.ext == ".nim" and entry.kind == pcFile:
yield entry.path

proc genCodeImportAll*(dir: string): string =
result = "{.warning[UnusedImport]: off.}\n"
for a in findNimSrcFiles(dir):
let s = "".dup(addQuoted(a))
result.add &"import {s}\n"

proc genDocs(dir: string, nim = "", args: seq[string]) =
let code = genCodeImportAll(dir)
let extra = quoteShellCommand(args)
let nim = if nim.len == 0: getCurrentCompilerExe() else: nim
let ret = execCmdEx(fmt"{nim} doc -r --project --docroot --outdir:htmldocs {extra} -", input = code)
if ret.exitCode != 0:
doAssert false, ret.output & "\n" & code

when isMainModule:
let args = commandLineParams()
doAssert args.len >= 1
let dir = args[0]
genDocs(dir, nim="", args[1..^1])

0 comments on commit acc7f6c

Please sign in to comment.