@@ -3,6 +3,7 @@ package org.jetbrains.kotlinx.jupyter.api.libraries
3
3
import org.jetbrains.kotlinx.jupyter.api.AfterCellExecutionCallback
4
4
import org.jetbrains.kotlinx.jupyter.api.ClassAnnotationHandler
5
5
import org.jetbrains.kotlinx.jupyter.api.ClassDeclarationsCallback
6
+ import org.jetbrains.kotlinx.jupyter.api.CodeCell
6
7
import org.jetbrains.kotlinx.jupyter.api.ExecutionCallback
7
8
import org.jetbrains.kotlinx.jupyter.api.FieldHandler
8
9
import org.jetbrains.kotlinx.jupyter.api.FieldHandlerByClass
@@ -25,9 +26,9 @@ import kotlin.reflect.KMutableProperty
25
26
*/
26
27
abstract class JupyterIntegration : LibraryDefinitionProducer {
27
28
28
- abstract fun Builder.onLoaded (notebook : Notebook ? )
29
+ abstract fun Builder.onLoaded ()
29
30
30
- class Builder {
31
+ class Builder ( val notebook : Notebook ? ) {
31
32
32
33
private val renderers = mutableListOf<RendererTypeHandler >()
33
34
@@ -69,9 +70,9 @@ abstract class JupyterIntegration : LibraryDefinitionProducer {
69
70
fileAnnotations.add(handler)
70
71
}
71
72
72
- inline fun <reified T : Any > render (noinline renderer : (T ) -> Any ) {
73
+ inline fun <reified T : Any > render (noinline renderer : CodeCell . (T ) -> Any ) {
73
74
val execution = ResultHandlerExecution { _, property ->
74
- FieldValue (renderer(property.value as T ), property.name)
75
+ FieldValue (renderer(notebook !! .currentCell !! , property.value as T ), property.name)
75
76
}
76
77
addRenderer(SubtypeRendererTypeHandler (T ::class , execution))
77
78
}
@@ -163,8 +164,8 @@ abstract class JupyterIntegration : LibraryDefinitionProducer {
163
164
}
164
165
165
166
override fun getDefinitions (notebook : Notebook ? ): List <LibraryDefinition > {
166
- val builder = Builder ()
167
- builder.onLoaded(notebook )
167
+ val builder = Builder (notebook )
168
+ builder.onLoaded()
168
169
return listOf (builder.getDefinition())
169
170
}
170
171
}
0 commit comments