Skip to content
This repository has been archived by the owner on Oct 15, 2023. It is now read-only.

whilein/te4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Te4j

About the project

Te4j (Template Engine For Java) - Fastest and easy template engine

Pros

  • Extremely fast (132k renders per second on 4790K)
  • Easy and simple syntax
  • No dependencies

Cons (temporary)

  • No community :(
  • Sometimes awful code
  • Poor documentation

Benchmarks

Click me

Example

index.html

<p>Message: {{ message }}</p>

Main.java

public class Main {
    public static void main(String[] args) {
         Pojo pojo = new Pojo();
         Template<Pojo> template = Te4j.load(Pojo.class).from("index.html");
         
         String result = template.renderAsString(pojo);
         System.out.println(result); // <p>Message: Hello world!</p>
    }

    public static class Pojo {
        public String getMessage() {
            return "Hello world!";
        }
    }
}

Also, you are able to create custom template context

TemplateContext ctx = Te4j.custom()
        // deletes repeating spaces, tabs, crlf from output
        .minify(Minify.DEL_CF, Minify.DEL_LF, Minify.DEL_TABS, Minify.DEL_REPEATING_SPACES)
        // .minify(Minify.getValues())
        // .minifyAll()

        // you can choose which output type will be used
        //
        // BYTES - renderAsBytes and renderTo will be optimized
        // STRING - renderAsString will be optimized
        .output(Output.BYTES, Output.STRING)
        // .output(Output.getValues())
        // .outputAll()

        // btw you can enable hot reloading
        //
        // it does not impact performance,
        // but I recommend disabling it in production
        // for max. performance
        .enableAutoReloading()
        .build();

Template<Pojo> template = ctx.load(Pojo.class).from("index.html");

More examples in docs

Full Docs

Click me

Add as dependency

Maven

<dependencies>
    <dependency>
        <groupId>io.github.whilein</groupId>
        <artifactId>te4j</artifactId>
        <version>1.1</version>
    </dependency>
</dependencies>

Gradle

dependencies {
    implementation 'io.github.whilein:te4j:1.1'
}

Build the project

  1. Execute ./gradlew build
  2. Output file located at build/libs/te4j.jar

Contact

Vkontakte, Telegram

Post Scriptum

I will be very glad if someone can help me with development.