casid / jte

Secure and speedy templates for Java and Kotlin.
https://jte.gg
Apache License 2.0
844 stars 63 forks source link

Provide a way to avoid line-ending #376

Closed albertorobles2000 closed 2 months ago

albertorobles2000 commented 2 months ago

Hi!

I'm starting to investigate JTE to try to migrate a velocity project. I have some complex conditions and I cannot do everything in just one line but I want the output rendered in one line. For example if for this:

l = [@if (A) A @endif @if (B) B @endif ... @if (Z) Z @endif]

I will get l = [A B C E G J ... Z ] I cannot put all those condtions in one line, but the output has to be all in one line. Is it implemented? In velocity I can do:

l = [ #*
#*--*##if (A)
A#*
#*--*##end
#*--*##if (B)
B#*
#*--*##end
#*--*##if (C)
C#*
#*--*##end
...
#*--*#]

And the output will be l = [A B C E G J ... Z ]

edward3h commented 2 months ago

What kind of file are you trying to produce?

albertorobles2000 commented 2 months ago

A raw file. In our case we have velocity integrated in a code generator that process an input file and generates code for the given file for a bunch of APIs C/C++/Java/Python/C#.

Is JTE not expected to be used when you want to generate files different from html?

edward3h commented 2 months ago

JTE can be used for other types of files, but sometimes there are other ways of generating output that are more convenient.

For example, the "jte-models" extension in this project uses JTE to generate Java code, since it avoids needing another dependency. In a different project I am using JavaPoet to generate Java code, because it is better suited for the task.

casid commented 2 months ago

Can only second @edward3h point. jte is heavily focused on generating HTML. For generating code I would (personally) definitely use a different library, like JavaPoet for Java Code.