Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#225 JS html to j2html code generator via kotlin multiplatform #226

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

PancakeInvaders2
Copy link

No description provided.

@PancakeInvaders2
Copy link
Author

I used kotlin multiplatform to write the converter so that it's in a language that is type-safe, null-safe, and generally nice to work with while able to compile to javascript

The structure of src, with commonMain, commonTest, jsMain, jsTest, jvmMain, and jvmTest is because kotlin multiplatform structures the code to share some of it between platforms (in this case jvm and javascript), and to have some platform specific code for each target

To generate the javascript, launch ./gradlew build, on build success, the compiled JS file will be at ./build/dist/js/productionExecutable/html-to-j2html.js

I used gradle instead of maven because that seems to be the standard for kotlin multiplatform projects, and I could not find any information on how to do the same in maven. It didn't need to be coupled to the rest of the maven structure anyway because while you can be called from and you can call java code from kotlin multiplatform, you can only call it from the jvm target, not from the javascript target

I included a quick and dirty index.html file that calls the converter. To play around with the converter, the easiest way is to open the html-to-j2html folder in VSCode, right click on index.html, Open with live server. The converter should be operational in the opened browser

Launching ./gradlew run will launch jvmMain.kt in the jvm, which will convert the read the content of input.html, convert it, and write it to output.java

@PancakeInvaders2
Copy link
Author

The actual converter logic is in commonMain, in Converter.kt, it uses the library KSoup to read the html. How each attributes is supported in configured in SupportedJ2HtmlAttributes.kt, this file may need to modified in the future if new attributes are supported or change types or something.

I also wrote a bunch of unit tests in ConverterTests in commonTest, using snippets I found online, tweaking the converter until the produced code seemed acceptable. You can have a good look at the expected outputs to see if the generated code is the way you'd want it to be.

Feel free to ask about any unclear parts

@tipsy
Copy link
Owner

tipsy commented Mar 27, 2024

Is this waiting for @sembler or me?

@PancakeInvaders2
Copy link
Author

Is this question directed at me ? I wouldn't know, I suppose that's for you and @sembler to decide

@PancakeInvaders2
Copy link
Author

any news ?

@tipsy
Copy link
Owner

tipsy commented May 26, 2024

any news ?

Sorry @PancakeInvaders2, life is sort of busy at the moment, and this pull request is pretty large.

When I said I could help get this added to the website I was picturing adding a JS library to the website and calling it with some input, not adding a whole new module of a thousand+ lines. I originally handed this project over to @sembler some years ago, but he has become quite busy too.

I'll try to help you get it live, but I don't see any JS library in the PR, could you outline how this can be created and plugged into the website?

@PancakeInvaders2
Copy link
Author

I understand, the purpose of the index.html was to show how this could be used in the website

Maybe it would be easier if I put the generator in a separate project, maintain it myself, and put it on npm or something so you can use it as you please

@tipsy
Copy link
Owner

tipsy commented May 27, 2024

I saw the HTML file, but not the actual html-to-j2html.js file - If you could maintain the generator code and distribute it on jsDelivr (or whatever the default is these day), that would be great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants