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

nimibook docs + 2 fixes + 1 feature (cfg) + 1 refactor #18

Merged
merged 11 commits into from
Jun 1, 2021
Merged

Conversation

pietroppeter
Copy link
Owner

@pietroppeter pietroppeter commented May 31, 2021

fix #10

  • (fix) removed nimibook / prelude (was broken); replaced with template nbUseNimibook
  • removed all previous content
  • expand README
  • new structure of documentation
  • (refactor) use template in genbook for book tasks (currently they are compile time switches. they should actually be available through a real CLI)
  • (fix) fix bug in draft (if in section it does not get indented)
  • (feature) add a way to configure stuff (book title and such), the idea is to create a Book object that will contain the Toc object and will have the fields needed to configure stuff. toc.json will become book.json and so forth...
  • docs:
    • chapter index: uses README (in principle I could add stuff in index which is not in README and also add stuff in README which is not in index but I have not yet taken advantage of that)
    • chapter content: brief description of the structure of the book page
    • chapter tocdsl: brief explanation of TocDSL
    • chapter configuration: todo, the feature is missing!
    • chapter tasks: automatically generated from nimble

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
Copy link
Contributor

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 ?

Copy link
Owner Author

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

@pietroppeter pietroppeter changed the title new content for book + remove include nimibook docs + 2 fixes + 1 feature (cfg) May 31, 2021
@pietroppeter pietroppeter changed the title nimibook docs + 2 fixes + 1 feature (cfg) nimibook docs + 2 fixes + 1 feature (cfg) + 1 refactor May 31, 2021
@pietroppeter
Copy link
Owner Author

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".

@HugoGranstrom
Copy link
Collaborator

HugoGranstrom commented May 31, 2021

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.

Copy link
Contributor

@Clonkk Clonkk left a 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 using import 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"
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Collaborator

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. 🤦‍♂️

Copy link
Owner Author

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:

  1. nim jsondoc ... and parse json file (will also depend directly on src)
  2. 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.

Copy link
Contributor

@Clonkk Clonkk Jun 1, 2021

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")
Copy link
Contributor

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 ?

Copy link
Owner Author

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.

Copy link
Contributor

@Clonkk Clonkk Jun 1, 2021

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:
Copy link
Contributor

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 :

I didn't analyzed it in details, but it seems like we could simplify it ?

Copy link
Owner Author

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 '\\', '\\'
Copy link
Contributor

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.

@pietroppeter
Copy link
Owner Author

Thanks all for the reviews.

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 using import nimibook as a library instead of relying on relative ../. CI based on relative folder can also be deceiving.

my thoughts on this (as reported below also in a comment):

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 in there should not matter.

I do not see any other option to not depend on src folder other than duplicating documentation in code and book and I would prefer to avoid this unless there are specific issues.

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...) :)

@pietroppeter pietroppeter merged commit 4c8b542 into main Jun 1, 2021
@pietroppeter pietroppeter deleted the add-docs branch June 25, 2021 15:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

example book should be nimibook documentation
3 participants