Skip to content

Commit

Permalink
opt-in nbOutDir and nbBaseDir (#53)
Browse files Browse the repository at this point in the history
* nimibOutDir (and nimibSrcDir) compile time switches allowing to override nbHomeDir
  • Loading branch information
HugoGranstrom authored Jun 3, 2021
1 parent dda83a5 commit 3436282
Showing 1 changed file with 15 additions and 5 deletions.
20 changes: 15 additions & 5 deletions src/nimib.nim
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,18 @@ template nbInit*() =
nbThisName {.inject, used.}: string = thisTuple.name
nbThisExt {.inject, used.}: string = thisTuple.ext
nbInitDir {.inject, used.} = getCurrentDir().AbsoluteDir # current directory at initialization
var
nbUser {.inject.}: string = getUser()
nbHomeDir {.inject.}: AbsoluteDir = findNimbleDir(nbThisDir)
if dirExists(nbHomeDir / "docs".RelativeDir):
nbHomeDir = nbHomeDir / "docs".RelativeDir
var nbUser {.inject.}: string = getUser()

const nimibOutDir {.strdefine, inject.} = "" # must inject otherwise it is always its default ""
const nimibSrcDir {.strdefine, inject} = ""
when defined(nimibSrcDir):
let nimibSrcDirAbs = nimibSrcDir.toAbsoluteDir
when defined(nimibOutDir):
var nbHomeDir {.inject.}: AbsoluteDir = nimibOutDir.toAbsoluteDir
else:
var nbHomeDir {.inject.}: AbsoluteDir = findNimbleDir(nbThisDir)
if dirExists(nbHomeDir / "docs".RelativeDir):
nbHomeDir = nbHomeDir / "docs".RelativeDir
setCurrentDir nbHomeDir

# could change to nb.rel with nb global object
Expand Down Expand Up @@ -74,6 +81,9 @@ template nbInit*() =
# - in case you need to manage additional exceptions for a specific document add a new set of partials before calling nbSave
nbDoc.context.searchDirs(nbDoc.templateDirs)
nbDoc.context.searchTable(nbDoc.partials)
when defined(nimibSrcDir):
if isAbsolute(nbDoc.filename):
nbDoc.filename = (AbsoluteFile(nbDoc.filename).relativeTo nimibSrcDirAbs).string
withDir(nbHomeDir):
write nbDoc

Expand Down

0 comments on commit 3436282

Please sign in to comment.