Move docs generation to module

This commit is contained in:
Ganesh Viswanathan 2019-10-03 13:45:56 -05:00
commit dee898dc51
2 changed files with 53 additions and 45 deletions

View file

@ -14,7 +14,7 @@ installFiles = @["config.nims"]
# Dependencies
requires "nim >= 0.19.2", "regex >= 0.10.0", "cligen >= 0.9.17"
import strformat
import nimterop/docs
proc execCmd(cmd: string) =
echo "execCmd:" & cmd
@ -24,61 +24,27 @@ proc execTest(test: string) =
execCmd "nim c -r " & test
execCmd "nim cpp -r " & test
proc tsoloud() =
execTest "tests/tsoloud.nim"
task buildToast, "build toast":
# If need to manually rebuild (automatically built on 1st need)
execCmd(&"nim c -d:release nimterop/toast.nim")
execCmd("nim c -d:danger nimterop/toast.nim")
task docs, "Generate docs":
buildDocs(@["nimterop/all.nim"], "build/htmldocs")
task test, "Test":
buildToastTask()
proc testAll() =
execTest "tests/tnimterop_c.nim"
execCmd "nim cpp -r tests/tnimterop_cpp.nim"
execTest "tests/tpcre.nim"
# platform specific tests
# Platform specific tests
when defined(Windows):
execTest "tests/tmath.nim"
if defined(OSX) or defined(Windows) or not existsEnv("TRAVIS"):
tsoloud() # requires some libraries on linux, need them installed in TRAVIS
execTest "tests/tsoloud.nim"
# getHeader tests
withDir("tests"):
execCmd("nim e getheader.nims")
const htmldocsDir = "build/htmldocs"
when (NimMajor, NimMinor, NimPatch) >= (0, 19, 9):
import os
proc getNimRootDir(): string =
#[
hack, but works
alternatively (but more complex), use (from a nim file, not nims otherwise
you get Error: ambiguous call; both system.fileExists):
import "$nim/testament/lib/stdtest/specialpaths.nim"
nimRootDir
]#
fmt"{currentSourcePath}".parentDir.parentDir.parentDir
proc runNimDoc() =
execCmd &"nim doc -o:{htmldocsDir} --project --index:on nimterop/all.nim"
execCmd &"nim buildIndex -o:{htmldocsDir}/theindex.html {htmldocsDir}"
when declared(getNimRootDir):
#[
this enables doc search, works at least locally with:
cd {htmldocsDir} && python -m SimpleHTTPServer 9009
]#
execCmd &"nim js -o:{htmldocsDir}/dochack.js {getNimRootDir()}/tools/dochack/dochack.nim"
task test, "Test":
buildToastTask()
testAll()
runNimDoc()
task docs, "Generate docs":
runNimDoc()
task docsPublish, "Generate and publish docs":
# Uses: pip install ghp-import
runNimDoc()
execCmd &"ghp-import --no-jekyll -fp {htmldocsDir}"
docsTask()

42
nimterop/docs.nim Normal file
View file

@ -0,0 +1,42 @@
import macros, strformat
when (NimMajor, NimMinor, NimPatch) >= (0, 19, 9):
from os import parentDir
proc getNimRootDir(): string =
#[
hack, but works
alternatively (but more complex), use (from a nim file, not nims otherwise
you get Error: ambiguous call; both system.fileExists):
import "$nim/testament/lib/stdtest/specialpaths.nim"
nimRootDir
]#
fmt"{currentSourcePath}".parentDir.parentDir.parentDir
proc buildDocs*(files: seq[string], path: string, baseDir = getProjectPath() & "/") =
## Generate docs for all specified nim `files` to the specified `path`
##
## `baseDir` is the project path by default and `files` and `path` are relative
## to that directory. Set to "" if using absolute paths.
##
## Use the `--publish` flag with nimble to publish docs contained in
## `path` to Github in the `gh-pages` branch. This requires the ghp-import
## package for Python: `pip install ghp-import`
##
## WARNING: `--publish` will destroy any existing content in this branch.
let
path = baseDir & path
for file in files:
echo gorge(&"nim doc -o:{path} --project --index:on {baseDir & file}")
echo gorge(&"nim buildIndex -o:{path}/theindex.html {path}")
when declared(getNimRootDir):
#[
this enables doc search, works at least locally with:
cd {path} && python -m SimpleHTTPServer 9009
]#
echo gorge(&"nim js -o:{path}/dochack.js {getNimRootDir()}/tools/dochack/dochack.nim")
for i in 0 .. paramCount():
if paramStr(i) == "--publish":
echo gorge(&"ghp-import --no-jekyll -fp {path}")
break