pietroppeter / nimib

nimib 🐳 - nim 👑 driven ⛵ publishing ✍
https://pietroppeter.github.io/nimib/
MIT License
176 stars 10 forks source link

nbNewDummy and nbMoveToIndex/nbCopyToIndex for anticipating/previewing code blocks that appear later #75

Open pietroppeter opened 2 years ago

pietroppeter commented 2 years ago

thinking about nim days and Nimib. A classic style of nim days is to start with "what to expect" of final api: https://xmonader.github.io/nimdays/day21_parsec.html

this is doable in Nimib since you can move code around but could be made more ergonomic. a small example showing the api:

nbCodePreview(finalExample):
   hello
# output: "hello"

nbCode:
  proc hello = echo "hello"

finalExample
# output: "hello"

in other cases the same effect could be reached in some way likely with nbFile

pietroppeter commented 2 years ago

this could be based internally of a nbCodeNoEval which is easy to implement but we do not have yet (and really not sure about the name)

pietroppeter commented 2 years ago

something similar to what is described above can be reached with current api, see this example in nblog: https://pietroppeter.github.io/nblog/drafts/mermaid_diagram.html

it is possible we do not need anymore a new command only an explanation on how to do this kind of stuff.

pietroppeter commented 1 year ago

thought of an api for this:


# inserted a dummy block at the place where you will want a later block to appear
idxDummy = nbNewDummy # creates a dummy (e.g. empty) block, places it in nb.blocks and returns index
# could be as simple as nbText ""; return nb.blocks.len - 1

... # stuff you want to do

nbMyGreatBlock # the block I want to show in place of dummy
nbMoveToIndex(idxDummy) # one line implementation: nb.blocks[idxDummy] = nb.blocks.pop()
# (almost one line: I should also replace nb.blk with the now last block)

the above establish an api made with nbNewDummy and nbMoveIndexToDummy and basically we already have the implementation, which is very simple. I think the api still make sense (in case we change implementation details, API should stay the same). We could also have a nbCopyToDummy which does not pop if you want the thing to appear twice.

as example document we might want to try with translating a simple one from nim days...

(rereading the thread not sure what I was referring to about an example in mermaid, maybe a previous commit?)