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

move css, fonts, js to assets folder; auto install assets folder #19

Merged
merged 41 commits into from
Jun 4, 2021
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f3dcc4e
move css, fonts, js to assets folder; auto install assets folder
Clonkk Jun 1, 2021
a679fad
add -f to publishers to resolve name conflict (index.nim) between pro…
Clonkk Jun 1, 2021
5ce2987
remove reliance on Nimble
Clonkk Jun 1, 2021
0153d31
only remove assets explicitly
Clonkk Jun 1, 2021
9a81634
Moved mustache template to src folder that gets deployes on Book crea…
Clonkk Jun 1, 2021
0730ff2
added comment to not forget debug comment
Clonkk Jun 1, 2021
1684fb3
rm debugEcho
Clonkk Jun 1, 2021
09c4f6e
added examples folder for a out of repo, example
Clonkk Jun 1, 2021
8ea9369
added validation CI
Clonkk Jun 1, 2021
b7b8afb
Added getEnv / putEnv mechanism to avoid findNimbleDir while propagat…
Clonkk Jun 1, 2021
37e8818
camelCase cariable, remove some debugEcho
Clonkk Jun 1, 2021
0fdd3b5
dirExists -> not dirExists for init check
Clonkk Jun 1, 2021
357be94
re-add entries
Clonkk Jun 2, 2021
69e93f0
move assets to ressources folder
Clonkk Jun 2, 2021
1f098b7
add relative path book.json
Clonkk Jun 2, 2021
f004e8d
Use non compile time value to prepare for CLI; this means it depends …
Clonkk Jun 2, 2021
3815211
uncomment book.json deletion
Clonkk Jun 2, 2021
04dfae4
fix missing nimble files with a placeholder until bugs gets fixe in N…
Clonkk Jun 2, 2021
778fc24
CLI prototype
Clonkk Jun 2, 2021
3796311
fixed clean
Clonkk Jun 2, 2021
8301864
add hints:off and verbosity to 0 in publiushers, remove some debug Echo
Clonkk Jun 2, 2021
31b0818
fix nimble tasks
Clonkk Jun 2, 2021
27c16e1
fix init
Clonkk Jun 2, 2021
b3096f2
fix github actions (I think)
Clonkk Jun 2, 2021
ed039b3
this repo uses main instead of master
Clonkk Jun 2, 2021
e70e18a
clean up
Clonkk Jun 3, 2021
ec91fa6
template -> templates; ressources -> resources
Clonkk Jun 3, 2021
2b2ee31
unbreak CI
Clonkk Jun 3, 2021
7dd8428
fix nimble file required and update nimib version to v0.1.3
Clonkk Jun 4, 2021
cf86eaa
nimble srcpretty
Clonkk Jun 4, 2021
549efed
improve readme and printHelp
Clonkk Jun 4, 2021
72a79ff
update readme
Clonkk Jun 4, 2021
3f8bbb4
rename env variable to variable name for clarity
Clonkk Jun 4, 2021
1e2b356
fix links & template missing an 's'
Clonkk Jun 4, 2021
46e685a
update readme
Clonkk Jun 4, 2021
8e1b67d
fix js path
Clonkk Jun 4, 2021
3845ccb
fix force args in populateAssets not overriding mustache files
Clonkk Jun 4, 2021
a34fa4b
nbBookTasks -> nimibookCli; README improvement
Clonkk Jun 4, 2021
9256b48
fix CI failures related to book variable
Clonkk Jun 4, 2021
4a11ff6
add examples in readme
Clonkk Jun 4, 2021
9acda49
md syntax is hard
Clonkk Jun 4, 2021
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
22 changes: 22 additions & 0 deletions .github/workflows/valid.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
on:
pull_request:
branches:
- master
push:
branches:
- master

jobs:
tests:
runs-on: ubuntu-latest
steps:
- name: "install_nim"
id: install_nim
uses: iffy/install-nim@v3
- run: cat nimibook.nimble
- run: nimble install -y
- name: Gen Book
run: nimble genbook
- name: Gen Book outside repo
run: cd examples && nim r examplebook.nim

7 changes: 1 addition & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,2 @@
!docs/.gitignore
!docs/css
!docs/FontAwesome
!docs/fonts
!docs/js
docs/
book/book.json
book/book.json
1 change: 1 addition & 0 deletions book/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.html
*.mustache
Clonkk marked this conversation as resolved.
Show resolved Hide resolved
#toc.mustache
2 changes: 1 addition & 1 deletion book/index.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ proc readFileUntil(filename: string, text: string): string =
result &= line & '\n'

nbText: "../README.md".readFileUntil("<!--SKIP")
nbSave
nbSave
3 changes: 3 additions & 0 deletions examples/book/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
*.mustache
*.html
*.json
11 changes: 11 additions & 0 deletions examples/book/book_1.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import nimib, nimibook

nbInit

nbUseNimibook # overrides nimib defaults with nimibooks and loads book configuration

nbText: """ ## This is a title
This is a sentence in a page
"""

nbSave
12 changes: 12 additions & 0 deletions examples/book/index.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import nimib, nimibook

nbInit

nbUseNimibook # overrides nimib defaults with nimibooks and loads book configuration

nbText: "Hello world"

nbCode:
doAssert 1+2 == 3

nbSave
7 changes: 7 additions & 0 deletions examples/examplebook.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import nimibook, os

var book = newBookFromToc("Dummy Book", "book"):
section("Dummy", "index"):
entry("Simple example", "book_1")

nbBookTasks
2 changes: 1 addition & 1 deletion genbook.nim
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ var book = newBookFromToc("nimibook", "book"):
draft("Draft chapter", "draft.md")

book.git_repository_url = "https://github.com/pietroppeter/nimibook"
nbBookTasks
nbBookTasks
4 changes: 4 additions & 0 deletions nimibook.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ requires "nimib >= 0.1.2"
requires "jsony >= 1.0.1"

import os

task genbook, "build book":
selfExec(" r -d:release genbook.nim")

task dumpbook, "dump book.json":
selfExec(" r -d:release -d:dumpBook genbook.nim")

task cleanbook, "remove all files created during build":
# Since assets now gets populated, I think we can just delete everything in assets
rmDir("docs" / "assets")
# todo: it should remove all files and directories not tracked in git from docs
for file in walkDirRec("docs"):
if file.endsWith(".html"):
Expand All @@ -35,6 +38,7 @@ task cleanbook, "remove all files created during build":
if file.endsWith(".html"):
rmFile(file)
echo "removed ", file
mkDir("docs" / "assets")


task srcpretty, "run nimpretty on nim files in src folder":
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion src/nimibook/books.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import std / os
import nimibook / [types, entries]
import nimibook / [types, entries]
import jsony

# fix for jsony: quote in string. https://github.com/treeform/jsony/issues/14
Expand Down
2 changes: 1 addition & 1 deletion src/nimibook/defaults.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ proc setDefaults*(book: var Book) =
book.preferred_dark_theme = "navy"
book.theme_option = {"light": "Light (default)", "rust": "Rust", "coal": "Coal", "navy": "Navy", "ayu": "Ayu"}.toTable
book.favicon_escaped = """<link rel="icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2280%22>🐳</text></svg>">"""
book.git_repository_icon = "fa-github"
book.git_repository_icon = "fa-github"
24 changes: 14 additions & 10 deletions src/nimibook/docs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@ proc useNimibook*(nbDoc: var NbDoc) =
let
nbThisFile = changeFileExt(nbDoc.filename.AbsoluteFile, ".nim")
thisTuple = nbThisFile.splitFile
nbThisDir: AbsoluteDir = thisTuple.dir
nbHomeDir: AbsoluteDir = findNimbleDir(nbThisDir) / "docs".RelativeDir
nbSrcDir = nbHomeDir / RelativeDir(".." / "book")

# are these two actually needed? well, home_path is needed in path_to_root, but other than that?
pathToRootFolder = getEnv("nimibook_path_to_rootfolder")
nbThisDir: AbsoluteDir = pathToRootFolder.toAbsoluteDir
nbHomeDir: AbsoluteDir = nbThisDir / RelativeDir("..") / "docs".RelativeDir
Clonkk marked this conversation as resolved.
Show resolved Hide resolved
nbSrcDir = nbThisDir

# TODO comment debugEcho before merge
debugecho "-------------------------------"
debugecho nbThisDir
debugecho nbSrcDir
debugecho "-------------------------------"

# Are these two actually needed? well, home_path is needed in path_to_root, but other than that?
nbDoc.context["here_path"] = (nbThisFile.relativeTo nbSrcDir).string
nbDoc.context["home_path"] = (nbSrcDir.relativeTo nbThisDir).string

Expand All @@ -20,16 +27,13 @@ proc useNimibook*(nbDoc: var NbDoc) =
# debugEcho "Current directory: ", getCurrentDir()
# debugEcho "Output file: ", nbDoc.filename


# templates are in nbSrcDir
nbDoc.templateDirs = @[nbSrcDir.string]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

templates are staying in book folder? I thought we were moving them to a templates but maybe that was an assumption I made in my head and never shared... :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we misunderstood each other. My idea was to have a ressources/template folder in src/nimibook to deploy the mustache files automatically in the book folder (per the init mechanism we discussed)

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this comment I describe an alternative folder structure. Do you think it could be done in this PR? if not we can do it/discuss it later. If it stays like this maybe I would just change ressources to resources :)

Copy link
Contributor Author

@Clonkk Clonkk Jun 3, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on general folder structure, I was thinking, maybe we could put in src/nimibook a theme folder which contains a full example structure of a default nimibook (with folders docs\assets, templates, book, ...). If we add to that a clever config.nims (with a path ../../ we probably can also run nbook there and test the default structure during development). The theme folder is then the reference from where we populate assets.

If I understand correctly, you want to have the whole book structure in src/nimibook/theme and copy it in the current folder upon calling the init / update step ?

That is perfectly do-able, I don't think we even need a config.nims to test it (Init should do the trick). We can just copy "*.mustache" from templates into rootfolder (currentlybook comes from user input so we can't use it in theme).

Just one question : why keep docs/assets instead of just æssets copied into docs ?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's do and discuss this in another PR :)

nbDoc.context["title"] = nbDoc.context["here_path"]

# Use nbSrcDir instead another relative path
let bookPath = nbSrcDir.string / "book.json"
# load book object
let bookPath = "../book/book.json"
if not bookPath.fileExists:
withDir("..".AbsoluteDir): # todo: add a withDir for RelativeDir in nimib /paths
discard execShellCmd("nimble dumpbook")
var book = load(bookPath)

# book configuration
Expand Down
6 changes: 3 additions & 3 deletions src/nimibook/entries.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import std / [os, strutils, strformat]
Clonkk marked this conversation as resolved.
Show resolved Hide resolved
import std / [os, strformat]
import nimibook / types

proc url*(e: Entry): string =
Expand All @@ -9,6 +9,6 @@ proc url*(e: Entry): string =
path

proc check*(e: Entry) =
let entryurl = url(e)
if not fileExists("docs" / entryurl):
let entryurl = "docs" / url(e)
if not fileExists(entryurl):
raise newException(IOError, fmt"Error finding {entryurl} : no such file or directory")
28 changes: 14 additions & 14 deletions book/document.mustache → src/nimibook/mustache/document.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,29 @@

{{&favicon_escaped}}
{{#favicon_svg}}
<link rel="icon" href="{{ path_to_root }}favicon.svg">
<link rel="icon" href="{{ path_to_root }}assets/favicon.svg">
{{/favicon_svg}}
{{#favicon_png}}
<link rel="shortcut icon" href="{{ path_to_root }}favicon.png">
<link rel="shortcut icon" href="{{ path_to_root }}assets/favicon.png">
{{/favicon_png}}
<link rel="stylesheet" href="{{ path_to_root }}css/variables.css">
<link rel="stylesheet" href="{{ path_to_root }}css/general.css">
<link rel="stylesheet" href="{{ path_to_root }}css/chrome.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/variables.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/general.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/chrome.css">
{{#print_enable}}
<link rel="stylesheet" href="{{ path_to_root }}css/print.css" media="print">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/print.css" media="print">
{{/print_enable}}

<!-- Fonts -->
<link rel="stylesheet" href="{{ path_to_root }}FontAwesome/css/font-awesome.min.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/FontAwesome/css/font-awesome.min.css">
{{#copy_fonts}}
<link rel="stylesheet" href="{{ path_to_root }}fonts/fonts.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/fonts/fonts.css">
{{/copy_fonts}}

<!-- Highlight.js Stylesheets - I could use nimib native highlight but let's keep it for styling... -->
<link rel="stylesheet" href="{{ path_to_root }}css/highlight.css">
<link rel="stylesheet" href="{{ path_to_root }}css/tomorrow-night.css">
<link rel="stylesheet" href="{{ path_to_root }}css/ayu-highlight.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/highlight.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/tomorrow-night.css">
<link rel="stylesheet" href="{{ path_to_root }}assets/css/ayu-highlight.css">

<!-- Custom theme stylesheets - why the "../"? -->
{{#additional_css}}
<link rel="stylesheet" href="../{{ path_to_root }}{{ . }}">
Expand All @@ -58,7 +58,7 @@
<body>
<!-- Provide site root to javascript -->
<script type="text/javascript">
var path_to_root = "{{ path_to_root }}";
var path_to_root = "{{ path_to_root }}/assets";
var default_theme = window.matchMedia("(prefers-color-scheme: dark)").matches ? "{{ preferred_dark_theme }}" : "{{ default_theme }}";
</script>

Expand Down Expand Up @@ -311,4 +311,4 @@
{{/is_print}}

</body>
</html>
</html>
File renamed without changes.
File renamed without changes.
3 changes: 1 addition & 2 deletions src/nimibook/publishers.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import nimib
proc nimPublish*(entry: Entry) =
let
cmd = "nim"
args = ["r", "-d:release", entry.path]
args = ["r", "-d:release", "-f", entry.path]
debugEcho "[Executing] ", cmd, " ", args.join(" ")
if execShellCmd(cmd & " " & args.join(" ")) != 0:
quit(1)
Expand All @@ -29,7 +29,6 @@ proc publish*(entry: Entry) =
raise newException(IOError, "Error invalid file extension.")

proc publish*(book: Book) =
dump book
for entry in book.toc.entries:
entry.publish()
clean book
Expand Down
45 changes: 32 additions & 13 deletions src/nimibook/tocs.nim
Original file line number Diff line number Diff line change
@@ -1,46 +1,63 @@
import std / [os, strformat]
import std / [os, strformat, macros]
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
debugEcho "==> toc.add Entry <==\n fullPath>", fullPath
if not fileExists(fullPath):
raise newException(IOError, fmt"Error entry {fullpath} doesn't exist.")
toc.entries.add entry

template initBook(rootfolder: string) =
let
assetsSrc = currentSourcePath().parentDir() / "assets"
assetsTarget = getProjectPath() / "docs" / "assets"

mustacheSrc = currentSourcePath().parentDir() / "mustache"
mustacheTarget = getProjectPath() / rootfolder

for file in walkFiles(mustacheSrc / "*.mustache"):
let name = file.splitPath().tail
# Copy default mustache file
if not fileExists(mustacheTarget / name):
# debugEcho "copyFile(", file, ", ", mustacheTarget, ") "
copyFile(file, mustacheTarget / name)

if not dirExists(assetsTarget):
# debugEcho "==> copyDir(", src, ", ", target, ")"
copyDir(assetsSrc, assetsTarget)

template newBookFromToc*(booklabel: string, rootfolder: string, body: untyped): Book =
initBook(rootfolder)
static:
let path_to_rootfolder = getProjectPath() / rootfolder
putEnv("nimibook_path_to_rootfolder", path_to_rootfolder)

var book = Book(book_title: booklabel)
book.setDefaults

var toc = Toc(path: rootfolder)
var levels: seq[int] = @[1]
var folders: seq[string] = @[rootfolder]

template entry(label, rfile: string, numbered=true) =
# debugEcho "==> entry <=="
# debugEcho " file>", rfile
template entry(label, rfile: string, numbered = true) =
let inputs = rfile.splitFile
let file = inputs.dir / formatFileName(inputs)
# debugEcho " inputs>", inputs
# debugEcho " file>", file
toc.add Entry(title: label, path: joinPath(folders, file).normalizedPath(), levels: levels, isNumbered: numbered)
if numbered:
inc levels

template draft(label, rfile: string) = entry(label, rfile, numbered=false)
template draft(label, rfile: string) = entry(label, rfile, numbered = false)

template section(label, rfile: string, sectionBody: untyped) =
let inputs = rfile.splitFile
let curfolder = inputs.dir
let file = formatFileName(inputs)
folders.add curfolder
toc.add Entry(title: label, path: joinPath(folders, file).normalizedPath(), levels: levels, isNumbered: true)
# debugEcho "==> section <=="
# debugEcho " file>", file
# debugEcho " folders>", folders
levels.add 1
sectionBody
discard pop levels
Expand All @@ -49,4 +66,6 @@ template newBookFromToc*(booklabel: string, rootfolder: string, body: untyped):

body
book.toc = toc
book
# Dump json here so we avoid having to use Nimble in use Nimibook
dump(book)
book
6 changes: 3 additions & 3 deletions src/nimibook/types.nim
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import tables
import std / tables
export tables

type
Expand All @@ -22,7 +22,7 @@ type
#
# required fields (in the sense the mustache template will work bad if they are not present):
book_title*: string ## Title of the book as specified in `newBookFromToc`
# chapter_title: not needed?
# chapter_title: not needed?
title*: string # title of the page (what appears in browser tab); default in mdbook is "<chapter_title> - <book_title>" where chapter_title comes from toc
language*: string ## The main language of the book, which is used as a language attribute `<html lang="en">` for example (defaults to en)
description*: string ## A description for the book, which is added as meta information in the html <head> of each page
Expand Down Expand Up @@ -76,4 +76,4 @@ list of assets required as mentioned directly in document.mustache (other assets
- highlight.js
- book.js

]#
]#