-
Notifications
You must be signed in to change notification settings - Fork 10
Refactor NbBlock #235
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
base: main
Are you sure you want to change the base?
Refactor NbBlock #235
Conversation
|
milestone reached, now in sandbox/minib3.nim both a minimal html and json backend work. (your json work was great @HugoGranstrom). Still lots of details to work on, but I am feeling more confident now! A big realization was that in the end we might not need after all nim mustache anymore (we might still provide it for legacy reason and we should be able to provide a somewhat backward compatible NbLegacyDoc object that implements the default theme as before with partials), in a sense nimib itself is some code based (and block based) templating system with superpowers... |
|
(moved this note in sandbox/notes.md) |
Mmh, no to customize an existing block the idea is to replace the function that renders it in the nimib/sandbox/minib3/minib.nim Line 26 in 5e6727e
The part above is still an idea and will need more fleshing out. I would definitely start with bare html and would allow customization only in the sense of: give me the rendered output and I can put things before or after. Any kind of refinement to that idea would need a use case that we think makes it worth it. And I would not probably push this during this refactor, maybe for now we do not even do what is sketched above (just to keep the scope manageable).
Yes, that is an option (serializing also the theme), but I guess it is kind of wasteful and also not "clean". I would like if possible to have a somewhat readable json. Especially if it is a low cost thing and a simple rule such as: everything that is in
Yeah, that is a good observation and it might not be needed after all. In principle you should not remember to set it since it should be in the NbBlock generating sugar, but if we can avoid needing it I could probably remove it. It will get trickier once I introduce real custom container blocks. My idea there at the moment is that Thanks for the feedback on the work-in-progress, it is useful :) nothing here is yet set in stone but I think a cleaner implementation is finally coming out. |
|
note, I just pushed a possible implementation of a NbContainer object (and NbContainer = ref object of NbBlock
blocks: seq[NbBlock]
parent: NbContainerwhile the html backend works fine with it the json backend fails to serialize because of the circular reference. This is an issue with My current plan is to actually skip the |
|
ok the new Next steps:
|
|
Nice work! 🤩 I really like the |
|
notes from another discussion. in this PR we should also:
|
|
So, I've started working on implementing Another thing that I'm wondering about is whether we should do the compilation the same way we are doing it now. Now we do it in |
|
Looks good to me! Couple of things I am noticing:
|
|
Nice! Then I'll go ahead and implement it for the other blocks as well 👍
Exactly,
That is correct. I also didn't know about it until a few weeks ago. It's really nice as it handles var j: JsonNode = nil
j{"hello"}{"world"}.getStr("default string")This will just work, Edit: it can be written even shorter: j{"hello", "world"}.getStr("default string") |
|
HugoGranstrom/nimiSlides#52 |
|
I can't imagine nimibook being more complicated. It doesn't really define that many custom blocks, it's more of the tooling around it and a theme. So I would be okay with saying that this PR doesn't break anything for the other libraries. And that means (by looking at my todo list hidden in the middle of this thread) that I should be fixing a rewriting tests 🥳 |
|
The tests are finally fixed! 🥳 We are so close, now we just need to go through the code and clean it up. One thing I'm thinking about is moving all the block definitions out to other files. Maybe a folder with different blocks in different files? Maybe just a gigantic file with all the blocks? Do you have any preferences? The drawback of putting them in different files would be that we could stumble upon cyclic imports if we want to share stuff between them. |
|
I would probably go with single file with all blocks |
|
Great, then I'll fix that when I get some time over 👌 |
|
That worked out way smoother than I expected. Now I just need to clean up some comments and then we should be ready for a final review. 🥳 |
this is a major change, implements #168 (and also #117). Very WIP in a sandbox folder (see sandbox/notes.md)