jte icon indicating copy to clipboard operation
jte copied to clipboard

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

Open checketts opened this issue 1 year ago • 13 comments

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...

checketts avatar Aug 06 '24 21:08 checketts

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.

edward3h avatar Aug 06 '24 21:08 edward3h

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.

checketts avatar Aug 06 '24 22:08 checketts

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 avatar Sep 12 '24 16:09 edward3h

Sorry for the delay in responding, by the way.

edward3h avatar Sep 12 '24 16:09 edward3h

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

edward3h avatar Sep 12 '24 16:09 edward3h

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.

checketts avatar Sep 12 '24 16:09 checketts

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.

edward3h avatar Sep 12 '24 16:09 edward3h

doc for jte-models https://jte.gg/jte-models/ is un clear, and not working with maven, no StaticTemplates is generated

sysmat avatar Jan 18 '25 08:01 sysmat

  • when switching to generate-sources maven compile error cannot find symbol
  • package gg.jte.models.runtime does not exist even if I add dependency jte-runtime

sysmat avatar Jan 18 '25 09:01 sysmat

@sysmat This test case in JTE, uses jte-models with Maven. Can you look at that as an example?

(I'm a Gradle user: my Maven knowledge is limited.)

edward3h avatar Mar 17 '25 14:03 edward3h

https://github.com/casid/jte/pull/450 is related in a minor way - allows naming the templates interface.

edward3h avatar Apr 19 '25 15:04 edward3h

  • @edward3h the problem is in documentation, where dependency is only in plugin, but it must be also in top level dependencies
  • correct pom.xm
<dependencies>
        <dependency>
            <groupId>gg.jte</groupId>
            <artifactId>jte</artifactId>
            <version>${jte.version}</version>
        </dependency>

       <!-- MUST BE ALSO HERE -->
        <dependency>
            <groupId>gg.jte</groupId>
            <artifactId>jte-models</artifactId>
            <version>${jte.version}</version>
        </dependency>
         .....        
</dependencies>

<build>
        <plugins>
            <plugin>
                <groupId>gg.jte</groupId>
                <artifactId>jte-maven-plugin</artifactId>
                <version>${jte.version}</version>
                <configuration>
                    <sourceDirectory>${project.basedir}/src/main/resources/jte</sourceDirectory>
                    <contentType>Plain</contentType>
                    <extensions>
                        <extension>
                            <className>gg.jte.models.generator.ModelExtension</className>
                        </extension>
                    </extensions>
                </configuration>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                  <!-- NOT enough just here -->
                    <dependency>
                        <groupId>gg.jte</groupId>
                        <artifactId>jte-models</artifactId>
                        <version>${jte.version}</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>

sysmat avatar Apr 20 '25 05:04 sysmat

@sysmat thanks, that makes sense. Can you make a PR to fix the documentation?

edward3h avatar Apr 24 '25 16:04 edward3h