Closed hellozyemlya closed 1 year ago
Hm. Seems like there is no such feature(and I doubt which template engine has such feature).
And I guess it can be tricky to implement. An easy solution I can see, is to extend render
method to accept indent, and put this indent after each \r\n
(maybe skipping some parts of \r\n like in
\r\n\r\n`, but passing this argument requires calculation distance to the last \r\n symbol in currently written output.
One of the tricky scenarios:
helloworld(@template.someTemplate(...))
Make indent for whole someTemplate
equals to len("helloworld(")
?
Maybe extend @template
and make some kind of @templateKeepIndent
variant, that will remember own indent and render underlying content with same indent?
Hey @hellozyemlya,
thanks for using jte and for reporting this issue.
jte is mainly used to generate HTML pages, where indentation is not as relevant as in this code-generation example. As you already pointed out, this is rather complex to implement. In fact, this would need to be implemented at runtime instead of compile time, since templates can be called from various places.
Maybe another library would be suited better for generating such code files?
@casid I see, thanks for reply. Maybe as an author of jte, you know a good candidates for template library that can support this?
Kotlin Poet might fit your usecase pretty well.
For example, following template:
resulting in generated content like:
but expected output is: