jte icon indicating copy to clipboard operation
jte copied to clipboard

Template autoformatting at buildtime

Open nedtwigg opened this issue 2 years ago • 5 comments

I hoped to add a jte section to Spotless.

But it looks like the formatter is tied pretty intimately to IntelliJ

  • https://github.com/casid/jte-intellij/tree/master/src/main/java/org/jusecase/jte/intellij/language/format

It seems like it would be possible to make a pretty-printer by implementing a TemplateParserVisitor which implements all the callbacks by appending to a big String.

Any thoughts?

nedtwigg avatar Apr 06 '23 03:04 nedtwigg

@nedtwigg in theorie yes, you could give it a try. For jte parts it should work, but I'm unsure how to format the underlying language (for instance HTML/JS/CSS). The TemplateParser does omit some stuff if configured, so I think the gg.jte.TemplateConfig would need to be set to htmlCommentsPreserved = true and trimControlStructures = false.

casid avatar Apr 06 '23 04:04 casid

Fine to close this if you don't want it implemented, but I've had good luck on some of my projects leaving a seemingly-hopeless feature request open, and eventually somebody comes along and implements it. Canonical formatting has become mainstream (gofmt, rustfmt, prettier, etc), it would be really great if somebody built a jtefmt someday.

nedtwigg avatar May 22 '23 18:05 nedtwigg

If the template is being used in plain text mode it could be rendering anything. You can't generalise format in that case.

edward3h avatar May 22 '23 19:05 edward3h

True, but HTML is common enough that TemplateConfig has fields like htmlCommentsPreserved. Something can be useful without being universal.

nedtwigg avatar May 22 '23 20:05 nedtwigg

I don't have time to work on it, but will leave it open as @nedtwigg suggested.

casid avatar May 23 '23 04:05 casid