From an existing Kotlin desktop application, I wan...
# general-advice
s
From an existing Kotlin desktop application, I want to write out a single-file HTML report with rather complex dynamic elements, like collapsible text sections inside table rows, filtering / sort columns in a table etc. Similar to like in the following screenshot. Any suggestions what Kotlin framework / library to use to write out such an HTML report (without touching any JavaScript / TypeScript code)?
a
Have you considered any libraries or frameworks already? Does it have to be Kotlin Multiplatform? I suspect you’re looking for a templating engine. There’s a handy list in the Ktor docs https://ktor.io/docs/templating.html, but only kotlinx.html is multiplatform, and it’s quite low-level so it could be a lot of work to create an HTML page from scratch. Using Bootstrap can be really handy to build HTML elements. For example, making an element collapse is just a case of adding some attributes and css classes https://getbootstrap.com/docs/5.3/components/collapse/.
s
It doesn't have to multi-platform, for now targeting JVM would be sufficient. I don't think a simple templating engine would be of any help here, where would the code for the dynamic HTML components from from? I've taken a brief look at projects like kvision and kobweb, but they all seem to be focused on creating website that run on a server, not a self-contained "local" HTML report with just some dynamic components.
a
ah yeah, KVision and Kobweb are good ideas. Bundling anything they produce into a single HTML file should be possible by using Webpack.
this post is old, but it should give some idea of how to bundle the Webpack result into a single file https://stackoverflow.com/questions/46866228/how-to-bundle-html-js-and-css-in-one-html-file-with-webpack
s
Ok. I was hoping to be able to not get in direct touch with any JS-rated technology like WebPack etc., but seem like I have to...
a
ah yeah, that’s what I was implying. Kotlin/JS uses Webpack, so you shouldn’t need to do a lot of custom set up - hopefully just add a few Webpack plugins 🤞
I definitely relate though, I’ve been struggling with Webpack today. Apparently it can’t load css files by default 🤷‍♀️