I've been working on a Kotlin based HTML template ...
# server
a
I've been working on a Kotlin based HTML template engine for a while. I call it KTML. I wanted one where I could just write HTML and easily create reusable components, and had great production performance. I also wanted it to work with KMP. It's at a decent state now for a beta version (with some framework integrations and a Gradle plugin). Here's the repo: https://github.com/ktool-dev/ktml There's also some small example applications. Let me know what you think.
🔥 7
👍 3
r
Any chance adding web targets?
b
Might I suggest introducing a plugin for the Ktor registry? https://github.com/ktorio/ktor-plugin-registry
a
@Robert Jaros I hand't considered that, but yeah, the runtime library is pretty small, so getting it setup for that shouldn't be too hard.
👍 1
@Bruce Hamilton yeah, that's a good idea!
kodee happy 1
a
Happy to see things like these created!
m
This looks awesome!
a
Thanks! If you get to try it out, be sure and give me any feedback you have, or let me know if you run into any issues!
m
Dependency requires at least JVM runtime version 22. This build uses a Java 21 JVM.
😕 Hopefully we will migrate to 25 soon.
a
There really isn’t any reason it has to use 22. That’s just the version I picked. I kept meaning to go back and change it to maybe 17.
a
stick to 21, it's an LTS version
a
That's true, but there's still a lot of people still on 17
1
m
Sorry for lame question - how do I run ktor example application?
a
Oh, yeah, I should have set that up as an application in the gradle file so there would be a gradle command for that. I've just been running the
main
function in IntelliJ.
m
I tried that, but my IDEA tells me that there is nothing there 🙃
a
Hmm, that's strange. Not sure on that one, I'll have to look into this later and get back with you.
I've made some updates to this now. • I updated the JVM target so now it's targeting 17. • I fixed the example projects so they have an actual run task in gradle now. • I added another example app showing how it works with an actual Kotlin Native app. (example-ktor-native) • @Robert Jaros I added the JS target, and put in another example app demonstrating using KTML with a Kotlin JS app. (example-js)
👍 2
❤️ 2
r
Don't forget
wasmJs
as well 😉
a
I don’t have much experience with that, but I tried wasm and it doesn’t support how I use suspend on my write functions, so I didn’t think it would work.
r
I've just tested adding
wamsJs
target works without problems. All tests are passing and there are no build errors. Could you write a bit more about your issues?
a
Like I said, I don't know much about this, so might have done something wrong. But I added the wasm target, and tried to write some example code that called KTML, but the functions I was calling were
suspend
functions, and it said that wasn't supported on wasm.
r
I'll try to make a PR with some wasm example if you don't mind.
a
Go for it!
a
If it could be merged together with #C04RTD72RQ8 and their server-side handling of things it could be a very powerful project! I would love to see Svelte-like/Vue-like things where you have a
<script>
html tag and inside you can write Kotlin, use the declared variables in HTML, write conditions/loops/etc in HTML, and use file-based routing
That's a lot of work but that's a dream project I would use for all my projects :>
a
I don't know much about Kobweb. I've only looked at it a bit. So, I don't really know what would be involved in that, but it seems like it could work, from what I do know.
a
It's primarily built around Compose HTML for frontend
a
I made a couple more updates to this. I have some code that converts the Kotlin compiler errors in the generated code into a message that tells you what in the ktml template caused the errors, but it only showed when you ran in dev-mode. Now the gradle plugin will show the same information when the Kotlin compile task runs and gets compiler errors in the generated code. That will help native and JS targets, since you can only run in dev-mode on the JVM.
🔥 1
a
Sick !
r
@Aaron Freeman I think your problems with wasm target are caused by this very old coroutines version you are using (1.7.3): https://github.com/ktool-dev/ktml/blob/main/gradle/libs.versions.toml#L3 . I there any reason for this particular version?
a
I didn’t notice I was using an old version, I’ll check it out, thanks!
@Robert Jaros I merged that PR, it works great! Thanks for doing that!
👍 4