-
Notifications
You must be signed in to change notification settings - Fork 10
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
Refactor nb blocks (fix #24) #78
Conversation
Great work, I'm seeing a lot of things here that I'm liking :D This will make theming much easier! There's one thing I'm wondering what the rationale for it is, and that's the removal of |
sorry, I did it again: edited your comment instead of adding a reply. should be back to normal now.
pretty happy so far, it has really been a long time coming and finally all pieces are falling into place! two main things I am not liking so far:
I think I cannot keep it since |
Haha 😄
Right, had already forgotten about my nbHTML/nbRaw needs 🤭
It isn't performant, but couldn't you make a copy of # old
nb.context["blocks"] = blocks
return "{{> document}}".render(nb.context)
# new
var ctx = nb.context
ctx["blocks"] = blocks
return "{{> document}}".render(ctx)
Yeah, that's not optimal, but it feels like
What's wrong with
I'm not really sure how that fix helps me 😅 As it is now in this PR, when we call One solution would be to keep the field but rename it if it collides. |
I am thinking something a bit radical but along those lines. Replacing
given the above it is possible that even
yeah, probably I should just use that (to be honest I only need to strip the last newline, if there is more than one maybe they should stay, mmh not sure). As mentioned I was in a hurry to finish :)
ah yes, now I do (you actually implemented a new backend) you are right the fix is not easy. But this PR changed fundamentally how render takes place so I think it is supposed to break. What you would need is to create a new backend (basically replace the renderPlan and renderProc). I think I will still change the API there (maybe a backend object by itself). I do have to work at Markdown backend so I will see how that will go. In principle I could keep a renamed field (maybe under a legacy compile time switch) but honestly I do not know how much that is worth. As far as I know only nimislides is using that and it should anyway pass to the new system. Do not worry too much I will help and it will likely not be that much of trouble. |
and that's very useful feedback, thanks! |
yeah I briefly check nimislides code and I think it will be much improved by stuff in this PR. honestly for me in scope of this PR is also a PR to nimislides that makes it work (you see in the todo there are a few checks of multiple stuff) |
That could certainly work, and it is more general as well in what kinds of types it can handle than
That sounds sensible. Don't know about the distinct though, sounds quite complex for little benefit. If
The is a
Ahh, "backend" is what it's called. It is sensible that a lot of things will break, but functionality shouldn't disappear. As I understand it, One solution would be to have some kind of proc htmlAssemble(nbDoc: var NbDoc, renderedBlocks: seq[string]) =
nb.context["blocks"] = blocks
proc render*(nb: var NbDoc): string =
var blocks: seq[string]
for blk in nb.blocks.mitems:
blocks.add nb.render(blk)
nb.assembleProc(nb, blocks) # nb.assembleProc is htmlAssemble
return "{{> document}}".render(nb.context) And in nimiSlides case it would basically do what
That will be very much appreciated, or at least some guidance on how I can do it myself :D |
ok starting to understand better. I think it should be doable with current setup, it would be sort of hack but current implementation is likely a worse hack. for example with a simplified api: nbSlide:
nbText: "some text"
nbCode: echo "and some code" I would implement it as: template nbSlide(body: untyped) =
nbSlideStart
body
nbSlideEnd where I think this kind of thinking can be adapted to your other apis. In the future a better solution will probably be to consider container blocks: blocks that can contain multiple blocks and have their separate rendering. It is something I have being thing since I think it would be useful (e.g. a nbFold section that hides stuff under a |
Yeah you are probably right :/ I really liked the idea of not having to wrap the content in a block, as it allows for a more dynamic creation of slides. And it stopped users from making things slides too nested (they aren't visible if nested more than twice). But I guess it will do. :) The fragments (the only other API I have) already uses this kind of logic, it just has to keep track an index which is a bit annoying. As you say, container blocks is really what would be needed in the future. I'll incorporate these changes in the BlockMaker update of nimiSlides, I don't dare touch it now until FOSDEM 🤣 |
this 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 (innimib / blocks
, exported) where we assign acommand
to the block (e.g."nbText", "nCode", "nbSource"
) and in order for rendering to be correct,partials
and a sequence ofrenderProc
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 insrc/nimib.nim
and thepartial
s andrenderProc
s are defined insrc/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:
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)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)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:
below my dev notes redacted during this PR
minimal stuff needed to merge:
optional renderPlan and partial for NbBlock?no need. Change command name and add specific partial and renderPlan in doc.nb.blk.output
->nb.blk.context["output"]
)<http://www.example.com>
not rendered because not escapedto be done after merging in devel:
milestone for 0.4: better handling of render backends (release name backendMaker). In particular:
other dev notes: