casid / jte

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

JteModels extension with a 'Plain' (non-HTML engine) #370

Open checketts opened 3 months ago

checketts commented 3 months ago

In following the JteModels documentation I seem to be able to only create Html based templates.

However, I need to create a few text (plain) templates.

Does that support exist? Any hint on how that might be configured?

I'll be happy to provide a PR for the docs once I figure out what is missing...

edward3h commented 3 months ago

Hi @checketts, I'm the author of jte-models. I'm kinda busy but I will try to get back to you at the weekend.

checketts commented 3 months ago

Thanks for the jte-models!

Here is my imagined way of making it work:


    //Generate HTML based templates
    jteExtension("gg.jte.models.generator.ModelExtension") {
        property("language", "Kotlin")
        property("excludePattern", ".*_text.*")
    }

    //Generate Text based templates
    jteExtension("gg.jte.models.generator.ModelExtension") {
        property("language", "Kotlin")
        property("package", "gg.jte.generated.precompiled.text") // Will place the `Templates` classes in this package
        property("contentType", "plain")
        property("includePattern", ".*_text.*")
    }

Note the new package and contentType options.

edward3h commented 2 months ago

jte-models can generate models for plain text templates. It uses the contentType specified on the jte { } block in Gradle.

This does make it difficult to use both HTML and plain templates at the same time. I think you would have to put them in separate submodules.

edward3h commented 2 months ago

Sorry for the delay in responding, by the way.

edward3h commented 2 months ago

It would not be too hard to make your imagined configuration work, but it would require some code changes.

checketts commented 2 months ago

Thanks for the response. My usecase is generating emails, since email has an HTML envelope and a plaintext. So separate modules wouldn't necessarily work for me.

Are you aware of a way to pass separate jteExtension config to a separate Gradle task? Perhaps I could investigate that route.

edward3h commented 2 months ago

The JTE Gradle plugin currently makes some assumptions that will prevent you configuring a separate task with different settings. It would be good to fix, but I don't have time available to work on that at the moment.