Skip to content

Commit

Permalink
fix init from scratch (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
pietroppeter authored Oct 24, 2021
1 parent 3ac959f commit aadbc09
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 5 additions & 0 deletions src/nimibook/books.nim
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ proc initBookFile(book: Book) =
let srcurls = book.files
for f in srcurls:
if not fileExists(f):
let (dir, _, _) = f.splitFile()
if not dir.dirExists:
echo "[nimibook] creating directory ", dir
createDir(dir)
let file = open(f, fmWrite)
echo "[nimibook] creating file ", f
file.close()

proc init*(book: Book) =
Expand Down
14 changes: 9 additions & 5 deletions src/nimibook/tocs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ import nimibook / [types, defaults, paths]
proc inc(levels: var seq[int]) =
levels[levels.high] = levels[levels.high] + 1

# TODO comment debugEcho before merge
proc add(toc: var Toc, entry: Entry) =
let fullPath = entry.path
# debugEcho "==> toc.add Entry <==\n fullPath>", fullPath
if not fileExists(fullPath):
raise newException(IOError, fmt"Error entry {fullpath} doesn't exist.")
echo fmt"[nimibook.warning] Toc entry {fullpath} doesn't exist."
toc.entries.add entry

template populateAssets*(rootfolder: string, force: bool = false) =
const baseRessources = currentSourcePath().parentDir() / "resources"
# debugEcho "[nimibook] baseResources", baseRessources
let
assetsSrc = baseRessources / "assets"
assetsTarget = getCurrentDir() / "docs" / "assets"
Expand All @@ -25,21 +25,25 @@ template populateAssets*(rootfolder: string, force: bool = false) =
# debugEcho("mustacheSrc >> ", mustacheSrc)
# debugEcho("mustacheTarget >> ", mustacheTarget)

if not dirExists(mustacheTarget):
echo "[nimibook] creating template directory: ", mustacheTarget
createDir(mustacheTarget)

for file in walkDir(mustacheSrc):
let file = file.path
let name = file.splitPath().tail
# Copy default mustache file
if not fileExists(mustacheTarget / name) or force:
# debugEcho "copyFile(", file , ", ", mustacheTarget, ") "
echo fmt"[nimibook] creating/overwriting template file:", mustacheTarget
copyFile(file, mustacheTarget / name)

if not dirExists(assetsTarget):
# debugEcho "==> copyDir(", assetsSrc, ", ", assetsTarget, ")"
echo "[nimibook] creating assets directory: ", assetsTarget
copyDir(assetsSrc, assetsTarget)
else:
if force:
removeDir(assetsTarget)
# debugEcho "==> copyDir(", assetsSrc, ", ", assetsTarget, ")"
echo "[nimibook] removing and creating again assets directory: ", assetsTarget
copyDir(assetsSrc, assetsTarget)

template newBookFromToc*(booklabel: string, rootfolder: string, body: untyped): Book =
Expand Down

0 comments on commit aadbc09

Please sign in to comment.