aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGanesh Viswanathan <dev@genotrance.com>2019-10-03 13:45:56 -0500
committerGanesh Viswanathan <dev@genotrance.com>2019-10-03 13:45:56 -0500
commitdee898dc51c4fddebd16f27af88443edaa46a95a (patch)
treebf991634dac5fc5779871867fb13b98c0537ad8d
parent23d2b869553f41b4676607cfd32178b24288259c (diff)
downloadnimterop-dee898dc51c4fddebd16f27af88443edaa46a95a.tar.gz
nimterop-dee898dc51c4fddebd16f27af88443edaa46a95a.zip
Move docs generation to module
-rw-r--r--nimterop.nimble56
-rw-r--r--nimterop/docs.nim42
2 files changed, 53 insertions, 45 deletions
diff --git a/nimterop.nimble b/nimterop.nimble
index 565c3e4..5825f5a 100644
--- a/nimterop.nimble
+++ b/nimterop.nimble
@@ -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()
diff --git a/nimterop/docs.nim b/nimterop/docs.nim
new file mode 100644
index 0000000..d7cb1a7
--- /dev/null
+++ b/nimterop/docs.nim
@@ -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