-
Notifications
You must be signed in to change notification settings - Fork 7
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
nimibook docs + 2 fixes + 1 feature (cfg) + 1 refactor #18
Conversation
src/nimibook/defaults.nim
Outdated
var toc = load("../book/toc.json") | ||
let tocPath = "../book/toc.json" | ||
if not tocPath.fileExists: | ||
withDir("..".AbsoluteDir): # todo: add a withDir for RelativeDir in nimib /paths |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"..".AbsoluteDir
Isn't ".." a relative dir and not an absolute dir ?
Could that be replaced by getProjectPath.parentDir()
(or maybe currentSourcePath.parentDir()
) or will that pose problem when distributing the binary ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, it is, see the comment. I like to use withDir
which I added in nimib /paths; it came from nimscript and was added in fusion which I copied and pasted into nimib (since I was not sure how to put fusion requirements in nimble file). I want to add also a withDir
with relative directory, but until now it is not there, so now it looks bad (at least it is good that you were able to notice it).
Regarding the other proposals, the rationale is that, nimib will currently use as homeDir docs
and it would by default change currentDir to homeDir so a ..
.RelativeDir should always work with thefolder structure we plan nimibook
to have. For your other suggestions maybe getProjectPath
could work (does it get the dir of nimble file?), currentSourcePath
probably not (since source could be in subfolders of book
).
Anyway I will need to revise how paths are handled in nimib, since nimibook has challenged the choices I made, so the idea is: 1) for now have workarounds in nimibook; 2) understand a better design and implement in nimib; 3) update nimibook with the improved design from nimib
ok PR is ready for review. I will leave it open for a bit if anyone wants to give an additional look, but I plan to merge tomorrow not after the publication of "This Month With Nim". |
I skimmed through the code and didn't find anything obviously wrong but I'm not as familiar as @Clonkk with the codebase. I've checked that it compiles on my machine and produces reasonable outputs. Thought at first that the code formatting was off but I then noticed you inlined some code in the nbText and had noted it in a comment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added my review. It's mostly some small interrogation or minor stuff that could be fixed in later PRs.
In a nutshell :
- Should
book
be dependent upon stuff outside of itself ?
I understand the appeal to auto-document, but I think it would be better to do so by usingimport nimibook
as a library instead of relying on relative../
. CI based on relative folder can also be deceiving.
The changes are overall very good otherwise.
# the following is very dependent on how source is written | ||
proc readBookConfigFields: seq[string] = | ||
# current folder is docs | ||
let src = "../src/nimibook/types.nim" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless I misunderstood something, why does the book rely upon parsing a file in src
?
I think we should keep book
and src
separate as much as possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also relative path based on "../" will break with Nimble; but that may be something to fix later on
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was also confused about the src/book thing until I realized the file wasn't some kind of configuration file butit rather just one of the pages in the book which did some parsing of the doc-comments in src. 🤦♂️
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This book
being the documentation of what happens in src
, I think it is fair to make book
depend on src
to avoid repeating stuff and keep documentation up to date. The moment you add a new field to Book
object implementing another feature you will get the corresponding documentation. For sure we should avoid having src
depend on book
folder. book
folder should be forgotten when installed by nimble so the relative paths there should not matter.
Regarding the implementation, it is indeed a bit hacky (main drawback being that how you add and document fields in Book
object impacts the documentation), but I think it is also rather straightforward. Other options I had in mind for implementation of this autodocumenting configurations were:
nim jsondoc ...
and parse json file (will also depend directly on src)- use
macros.getImpl
and parse AST (this depends only on import nimibook, but since we will not have nimibook as a dependency here, it will still ultimately depend on src)
The only option to not depend on src
folder is to duplicate documentation in code and book
and I would prefer to avoid this unless there are specific issues.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Options 2 was what I had in mind.
Use Nimibook as a library and parse the AST to obtain information but I understand your reasoning.
I think in the long run we need a macros so that we can extract information from the AST for using Nimibook as a API documentation generator (replacement of Nim doc).
Macros based will also allow us to get runnableExamples
But it's a rather complex feature so maybe I think we should merge this first and improve upon it later.
""" | ||
nbCode: | ||
echo "hello mdbook!" | ||
nbText: "../README.md".readFileUntil("<!--SKIP") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a good idea to have book
be dependent on content outside its own folder ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see remarks above, but also reading README I think is rather harmless. I was planning to have distinct contents only for README.md and index.nim but in the end I did not use that feature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, alright; for a static Readme file it's fair game.
when nimvm: | ||
s.add '"' | ||
for c in v: | ||
case c: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be simplified with the use of :
- addEscaped
- addQuoted
- escape / unescape
I didn't analyzed it in details, but it seems like we could simplify it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this and the following I think it should be better addressed in this PR to jsony. I ran into the issue while dumping Book
object, found the fix and directly applied it. When jsony merges the fix we should remove this and update jsony requirement.
ss.add '"' | ||
for c in v: | ||
case c: | ||
of '\\': ss.add '\\', '\\' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a function if it's used more than once. DRY.
Thanks all for the reviews.
my thoughts on this (as reported below also in a comment): This book being the documentation of what happens in I do not see any other option to not depend on I will go ahead and merge, feel free to open an issue and argue more on this if my arguments were not convincing (I might change my mind in the end...) :) |
fix #10
nimibook / prelude
(was broken); replaced with templatenbUseNimibook
genbook
for book tasks (currently they are compile time switches. they should actually be available through a real CLI)draft
(if in section it does not get indented)Book
object that will contain theToc
object and will have the fields needed to configure stuff.toc.json
will becomebook.json
and so forth...