diff --git a/README.md b/README.md index 80096960..a2e76a90 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ in this repo: * [mostaccio](https://pietroppeter.github.io/nimib/mostaccio.html): examples of usage of nim-mustache and of dark mode. * [interactivity](https://pietroppeter.github.io/nimib/interactivity.html): shows the basic API of creating interactive elements using `nbJsFromCode`. * [counter](https://pietroppeter.github.io/nimib/counters.html): shows how to create reusable interactive widgets by creating a counter button. -* [caesar](https://pietroppeter.github.io/nimib/caesar.html): a Caesar cipher implemented using `nbJsFromCode` and `karax`. +* [caesar](https://pietroppeter.github.io/nimib/caesar.html): a Caesar cipher implemented using `nbKaraxCode` and `karax`. elsewhere: @@ -153,7 +153,7 @@ Currently most of the documentation on customization is given by the examples. * `nbImage`: image command to show images (see `penguins.nim` example linked above) * `nbFile`: content (string or untyped) is saved to file (see example document [files](https://pietroppeter.github.io/nimib/files.html)) -* `nbRawOutput`: called with string content, it will add the raw content to document (html backend) +* `nbRawHtml`: called with string content, it will add the raw content to document (html backend) * `nbTextWithCode`: a variant of `nbText` that also reads nim source. See example of usage at the end of the source in `numerical.nim` linked above. * `nbPython`: can be used after calling `nbInitPython()` and it runs and capture output of python code; diff --git a/assets/nimib-nimconf-thumbnail.png b/assets/nimib-nimconf-thumbnail.png new file mode 100644 index 00000000..163ea24a Binary files /dev/null and b/assets/nimib-nimconf-thumbnail.png differ diff --git a/changelog.md b/changelog.md index c1e83129..8a02bde8 100644 --- a/changelog.md +++ b/changelog.md @@ -8,9 +8,17 @@ made this development possible. When contributing a fix, feature or example please add a new line to briefly explain the changes. It will be used as release documentation here: https://github.com/pietroppeter/nimib/releases ## 0.3.x - * _add next change here_ +## 0.3.3 + +* Refactored nbJs (#148) + * **Breaking**: All `nbJsFromCode` blocks are now inserted into the same file (Compared to previously when each block was compiled as its own file). + So this will break any reusable components as you will get `redefinition of variable` errors. The solution is to use `nbJsFromCodeInBlock` which puts the code inside a `block`. Imports can't be done in there though so you must do them in a separate `nbJsFromCode` or `nbJsFromCodeGlobal` before. + * See [https://pietroppeter.github.io/nimib/interactivity.html](https://pietroppeter.github.io/nimib/interactivity.html) for a more detailed guide on how to use the new API. +* Added `nimibCode` template. One problem with using `nbCode` is that you can't show *nimib* code using it because it nests blocks and wrecks havoc. +So `nimibCode` allows you to show *nimib* code but at the cost of not capturing output of the code. + ## 0.3.2 * Add `hlHtml` and `hlHtml` to nimiBoost diff --git a/docsrc/counters.nim b/docsrc/counters.nim index 26772cdc..fe7ae4a4 100644 --- a/docsrc/counters.nim +++ b/docsrc/counters.nim @@ -6,25 +6,27 @@ nbInit nbText: hlMd""" # Counters - Creating reusable widgets -This document will show you how to create reusable widgets using `nbJsFromCode`. Specifically we will make a counter: +This document will show you how to create reusable widgets using `nbJsFromCodeInBlock`. Specifically we will make a counter: A button which increases a counter each time you click it. We will do this in two different ways, using `std/dom` and `karax`. ## std/dom The first method is to use Nim like you would have used Javascript using `getElementById` and `addEventListener`: """ -nbCode: +nimibCode: + ## 0: + nbJsFromCodeGlobal: + import std/dom ## 1: template counterButton(id: string) = let labelId = "label-" & id let buttonId = "button-" & id ## 2: - nbRawOutput: """ + nbRawHtml: """ """ % [labelId, buttonId] ## 3: - nbJsFromCode(labelId, buttonId): - import std/dom + nbJsFromCodeInBlock(labelId, buttonId): ## 4: var label = getElementById(labelId.cstring) var button = getElementById(buttonId.cstring) @@ -38,10 +40,13 @@ nbCode: nbText: hlMd""" Let's explain each part of the code: + +0. We import `std/dom` in a `nbJsFromCodeGlobal` block. `std/dom` is where many dom-manipulation functions are located. 1. We define a template called `counterButton` which will create a new counter button. So if you call it somewhere it will place the widget there, that's the reusable part done. But it also takes an input `id: string`. This is to solve the problem of each widget needing unique ids. It can also be done with `nb.newId` as will be used in the Karax example. 2. Here we emit the `