life is too short for a diary




Dear Vishi, daily log on Feb 07, 2023.

Tags: diary letters

Author
Written by: Tushar Sharma
Featured image for Dear Vishi, daily log on Feb 07, 2023.

Dear Vishi, this is my daily log for Feb 07, 2023.

English

Do you know what a horseplay is? As expected in English, it has nothing to do with horses. Horseplay is a rough play or pranks in which people push or hit each other or behave in a silly way.

Mustache

Mustache is a template engine for Java. To add it's dependency

<dependency>
  <groupId>com.github.spullara.mustache.java</groupId>
  <artifactId>compiler</artifactId>
  <version>0.9.6</version>
</dependency>

Define a mustache template..

<h1>Hello {{name}}!</h1>

Create a Java class to hold the data:

public class HelloMessage {
    private String name;
    public HelloMessage(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }
}

Render the template

MustacheFactory mf = new DefaultMustacheFactory();
Mustache mustache = mf.compile("template.mustache");
HelloMessage message = new HelloMessage("John Doe");
StringWriter writer = new StringWriter();
mustache.execute(writer, message).flush();
System.out.println(writer.toString());

This will print

<h1>Hello John Doe!</h1>

comments powered by Disqus