Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add docs; add fusion/docutils #24

Merged
merged 1 commit into from
Oct 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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])