Hum, actually I'm not sure it will work with conte...
# terpal
a
Hum, actually I'm not sure it will work with context functions that I see you're using. I need to check if that's possible. If it's not I could probably fix that.
i
right I am using context functions, but perhaps even more problematic is that my Interpolator is not static in that it pulls an Appendable out of the context and constructs an Interpolator with it 😕
I don't really know the relative complexity of what I'm talking about but could a general solution to this be to support instrumenting (perhaps in a limited but sufficient capacity) inlined functions as wrappers? ala
Copy code
public inline fun TemplateScope.html(@Language("HTML") fragment: String): Unit = HtmlAppender(...).invoke(fragment)
where
HtmlAppender
is a subclass of
Interpolator
for now, I've added language injection by following along with terpal-sql but sticking to calling the Interpolator's invoke, i.e.
html.invoke(...)
instead of the prettier
html(...)
, because it's the lesser evil compared to having loads of
@Language("HTML")
all over the place, at least in my use cases. really hope JetBrains fixes this so I don't have to choose. ref. https://github.com/TwingineerHQ/ktemplar/commit/58e53366e3930c9d3826cfecb408edc7162ae9ab
and of course grateful to discuss alternative workarounds
a
Hi. I just released Terpal 1.0.0 RC4. This release allows you to use InterpolatorFunction with a context-receiver in order to get a function whose argument you can annotate with @Language. Instead of using the Interpolator class you need to use ProtoInterpolator and annotate your interpolation function as @InterpolatorBackend. Have a look at the following code sample for how to do this: https://github.com/deusaquilus/Terpal/blob/main/testing/src/commonTest/kotlin/io/exoquery/terpal/InterpolatorFunctionContextTest.kt
Follow this kind of pattern and add the language annotation like this:
Copy code
fun MyConext.staticContextTerp(@Language("MyLanguage") str: String): Wrapped = Messages.throwPluginNotExecuted()
This way you won't need to use
.invoke
to get the @Language annotation to work.
Does that make sense?
i
working it now, getting the following error
Error transforming expression: Fatal Exception: The interpolator type InterpolatingAppender has no 2nd argument (i.e. the output-type)
where my leaf object is
HtmlAppender -subclasses-> InterpolatingAppender -subclasses-> ProtoInterpolator<Any?, Unit>
. I'm assuming it's not following the inheritance up, so I'm testing the theory by inlining
InterpolatingAppender
worked around it by making HtmlAppender also subclass
ProtoInterpolator<Any?, Unit>
directly. side note that it is order sensitive in that the ProtoInterpolator subclassing has to be the first one, e.g.
ProtoInterpolator<Any?, Unit>, InterpolatingAppender()
but not
InterpolatingAppender(), ProtoInterpolator<Any?, Unit>
but ultimately success! 🎉 using RC4 and ProtoInterpolator, context functions are working allowing for language injection in
html("<div>${data.someValue}</div>")
form! changeset: https://github.com/TwingineerHQ/ktemplar/commit/b1c28ba39fb134881b6548be5f7117c781d0a159
a
Great to hear! I need to look into why it requires extending Interpolator and in a particular order specifically. Feel free to file an issue if you want.
i
created https://github.com/deusaquilus/Terpal/issues/9 to track it. and thanks again for implementing the Proto and context stuff. it's looking really slick. 😄
👍 1
c
really hope JetBrains fixes this so I don't have to choose.
The youtrack ticket was marked as in-progress today, so I'll probably be in the next release 🚀
🙌 1
a
Yeah I saw that. Exciting!