Skip to content

Commit

Permalink
Refactor nb blocks (fix #24, fix #52) (#78)
Browse files Browse the repository at this point in the history
his PR changes completely the `NbBlock` type that is at the basis of Nimib and makes it easier to create custom blocks.

A block will now be created using `newNbBlock` template (in `nimib / blocks`, exported) where we assign a `command` to the block (e.g. `"nbText", "nCode", "nbSource"`) and in order for rendering to be correct, `partials` and a sequence of `renderProc`s need to be defined associated to the above command. "Native" blocks and custom blocks are defined in the same way, the only difference is that for native blocks the block is defined in `src/nimib.nim` and the `partial`s and `renderProc`s are defined in `src/nimib/render` while in custom blocks they will likely be defined next to one other.

along with the above changes there are a few welcome add-ons:

- a better logging of what happens while running blocks
- some tests, sorely needed since ptest was (rightfully) removed
- a new partial `main`

some other accidental or not so welcome changes:

- `sugar` is now exported _(accidental)_
- `nb: NbDoc` is mutated when rendered _(unwelcome, will be changed later)_
- cannot use both Html and Md backend at the same time _(unwelcome, will be changed later)_

this feature will be the main highlight of next release (0.3) but in order to merge this PR some stuff needed for release is left out. Among stuff left out:

- `nbFile` is likely broken, should be fixed and tested inside Nimib (and examples should be added)
- documentation has not improved and it should
- I need to check that (some) projects depending on nimib are not broken (e.g. nimibook, scinim, ...)

after that a release of 0.3 should be in order. Release name will be **Block Maker**.

During work on this release I have also identified next milestone for 0.4: better handling of render backends (release name backendMaker). In particular:

> a big next change would be to use a json data in NbBlock instead of context and generate context during save. In this way you could go back to use multiple render backends at once, document could be made not mutable during save, ... 

----
commits

* new newBlock (with test)

* code is stripped as default

* imporve tests

* add dev notes (to be removed at the end)

* moved templates outside of nbInit

* update dev notes

* preliminaries to change rendering of block

* newNbBlock refactored (and renamed)

* nbNormalize

* add note \c == \r and \l == \n

* change name to tests

* add new nbText, nbCode with tests

* only log output if there is output

* use always check

* new renderBlock working with (minimal) test

* nim r hello works! 🍾

* mostaccio ok

* numerical ok

* nolan ok

* pythno ok

* remove ptest

* general cleanup

* update nbImage to refactored blocks

* minimal plan to just merge

* cheatsheet fixed

* update nimble docs

* markdown backend + index

* update nimble docs and rerun

* more cleanup and remove NbKind

* finalize notes

* remove refactor notes
  • Loading branch information
pietroppeter authored Mar 6, 2022
1 parent 20824e4 commit 07442ee
Show file tree
Hide file tree
Showing 30 changed files with 556 additions and 1,073 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ jobs:
nim-version: '1.6.x'
- run: nimble deps
- run: nimble tdeps
#- run: nimble ptest
- run: nimble test
- run: nimble docs # not to publish but to test it works
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*
!/**/
!*.*
.DS_store

*.exe
*.tmp.html
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# nimib 🐳 - nim πŸ‘‘ driven β›΅ publishing ✍

Nimib provides an API to convert your Nim code and its outputs to html documents.
Expand Down Expand Up @@ -108,7 +109,6 @@ in this repo:
* [numerical](https://pietroppeter.github.io/nimib/numerical.html): example usage of NumericalNim (example of custom style, usage of latex)
* [cheatsheet](https://pietroppeter.github.io/nimib/cheatsheet.html): markdown cheatsheet (example of a custom block, custom highlighting and a simple TOC)
* [mostaccio](https://pietroppeter.github.io/nimib/mostaccio.html): examples of usage of nim-mustache and of dark mode.
* [ptest](https://pietroppeter.github.io/nimib/ptest.html): print testing for nimib

elsewhere:

Expand Down Expand Up @@ -292,4 +292,3 @@ because I made a [package](https://github.com/pietroppeter/nimoji) for that and
because [someone made it into an art form](https://github.com/oakes/vim_cubed#q--a)
and they tell me [imitation is the sincerest form of flattery](https://www.goodreads.com/quotes/558084-imitation-is-the-sincerest-form-of-flattery-that-mediocrity-can)


Loading

0 comments on commit 07442ee

Please sign in to comment.