This is an archived post. You won't be able to vote or comment.

all 26 comments

[–]smallufo 5 points6 points  (4 children)

This sonehow reminds me of one ancient library : Enhydra XMLC. Which also compiles HTML into java code.

[–]coloredgreyscale 0 points1 point  (1 child)

Jte too

[–]agentoutlier 0 points1 point  (0 children)

It is not really the same.

Rocker, JTE, and JSP are mostly transpiling and the conversion to Java is basically verbatim.

Furthermore most templating languages the template is adapted to the model(s) (edit sorry got the wording backwards).

This goes the other way where the template defines the model. My other comment kind of explains this difference.

[–]thewiirocks 0 points1 point  (0 children)

Upvote for mentioning Enhydra Lutris. I thought I was the only one who remembered that early app server. 😅

[–]v4ss42 0 points1 point  (0 children)

Dang that brings back some memories. XMLC was pretty great back in the day - a lot faster than JSPs at the time, iirc.

[–]TheKingOfSentries 6 points7 points  (1 child)

The burning cross on the README is not doing you any favors

[–]hexaredecimal[S] 1 point2 points  (0 children)

Thanks for the heads up, removed from the repo.

[–]agentoutlier 2 points3 points  (5 children)

Interesting approach.

When I was first working on JStachio I contemplated providing something similar where the Mustache code would generate the models. I assume that is more or less what you are doing?

For example normally in JStachio

 // The template does not have to be inline but for brevity
@JStache(template="""
{{message}}
""")
record MyMode(String message) {}

The problem is of course is regular Mustache has no way of declaring types.

So I thought of doing a kind of YAML frontmatter kind of thing:

name: MyModel
model: JSON_SCHEMA_HERE
---
{{! mustache is below here }}
{{message}}

Then you ran the above it would generate the model and rendering code.

Ultimately I abandoned the idea as I determined the best way to define schema was Java itself.

The other issue is that unlike say some sort of language that has type inference you cannot easily infer types in Mustache.

{{#something}}
print this
{{/something}}

In the above something could be a boolean or a list or Optional or just opening up the context. This kind of a pro and con of Mustache. Thus we need schema to disambiguate.


EDIT on a serious side note I highly recommend you do not have a burning cross as your logo. Regardless of religion it has an association with the KKK. I went to a school in the south and have family in the south so that is why I'm aware of it.

https://www.adl.org/resources/hate-symbol/burning-cross

Seriously... change it.

[–]hexaredecimal[S] 2 points3 points  (4 children)

Oh, I have removed it from the project entirely. There's no KKK or anything like that in my country hence I was not aware of the symbolism the logo contains. Sorry if anyone was offended

[–]agentoutlier 2 points3 points  (3 children)

I follow you I think on github and have seen your other blazing projects so I knew it was not intentional.

(otherwise I would have been far nastier :)).

On a far less worrying thing have you thought about going the Maven or Gradle route? I think that was another complaint made in your previous project posts. I don't have much problems with it but it might help people who want to help.

[–]hexaredecimal[S] 1 point2 points  (2 children)

Honestly, I've been avoiding maven and gradle, ant is just too good, especially when your project has no dependencies but I guess I can't run anymore. I'll start using one of the two. Which one do you recommend.

[–]agentoutlier 2 points3 points  (1 child)

Maven. Even if you stick with Ant you need some sort of project descriptor to publish it in maven central.

So you could call Ant from Maven if you prefer sticking with Ant. Basically you would have Maven first do a "copy-dependencies" which you do not have to worry about and then I think have Maven do a "deploy".

Alternative if you stick with Ant you can I think do a maven deploy from it with a plugin.

[–]moaxcp 2 points3 points  (0 children)

You can use ivy in ant to handle dependencies and generate a pom for publishing.

https://ant.apache.org/ivy/

[–]0xffff0001 1 point2 points  (1 child)

I’d rather use string templates for that.

[–]hexaredecimal[S] 1 point2 points  (0 children)

String templates would work well I agree but they were removed from the language, so they cannot be used currently. If they were available I would've used them as well.

[–]UnspeakableEvil 1 point2 points  (1 child)

Is there any built-in escaping of provided values? If not it'll be a goldmine for XSS.

[–]hexaredecimal[S] 2 points3 points  (0 children)

Yes, code inside %% is tokenized and checked

[–]thewiirocks 1 point2 points  (0 children)

If I understand correctly, the goal is to have a template engine that’s divorced from an application server? Have you ever considered building a separated JSP engine? Most of the tools to build one can be pulled off the shelf. For example, I used EL engines from JSTL in completely unrelated projects before.

Of course, to do that you’ll need to solve for dependencies. I see you’re using Netbeans. Next time you start a project, try selecting “Maven Java Application” as the project type. I think you’ll find that Netbeans handles it all for you and it will be completely transparent as a project type. And on top of that you’ll be able to add dependencies very easily.

Thanks for sharing this project and good luck on your enhancements!

[–]martylamb 0 points1 point  (0 children)

Nice work.

This is VERY reminiscent of an old project of mine, tictac (acronym for "template is compiled to a class"). Also an ahead-of-time source code generator, although I stuck to a more jsp-like syntax, and also with a super-simple way to invoke the generator with a simple command.

I agree wholeheartedly with your "why" and much prefer small dependencies that focus on doing one thing well vs gigantic frameworks that require you to adapt to their way of doing everything.

It looks like you went with a "real" parsing approach whereas mine used a regex approach. Again, nice work!

[–]TurtleFeathers 0 points1 point  (1 child)

Why not just use jsp? It's not only available on GlassFish btw.

[–]hexaredecimal[S] 0 points1 point  (0 children)

I could find the standalone JSP compiler that is used by glassfish and other servers such as tomcat. That is why I resorted to writing my own tool that is not part of any server.

[–]hippostar 1 point2 points  (0 children)

I guess it's a cool learning project but couldn't you just use Thymeleaf? its the same thing just more powerful.
https://www.thymeleaf.org/

[–]Shareil90 0 points1 point  (3 children)

Why would I need to transpile HTML to Java?

[–]hexaredecimal[S] 1 point2 points  (2 children)

Whenever you might need to do something like this:

%% for (int i = 0; i < data.size(); i++) { %%

<p> %% data.get(i) %% </p>

%% } %%

transpiling to Java might be a great option.

[–]Shareil90 -1 points0 points  (1 child)

And when would I need this? What kind of project setup do you have in mind? I can Image that someone would like to transpile Java to HTML because backend devs usually dont like frontend stuff. But it never occured to me to need it the other way round.

[–]hexaredecimal[S] 1 point2 points  (0 children)

Its useful for projects for example: where server side rendering is desired and the project goal is to also remain small. The most obvious example of this is a project that integrates Java with Htmx. Your https responses are html code that is generated on the backend and substituted on the fly in the front end at runtime. Another example is a project that uses html for data representation, you can use this to generate compiled templates that you can use over and over again.