Skip to content

Instantly share code, notes, and snippets.

@Badbird5907
Last active June 11, 2021 21:21
Show Gist options
  • Save Badbird5907/b6a4ee93788bef4bb063a92698312fc2 to your computer and use it in GitHub Desktop.
Save Badbird5907/b6a4ee93788bef4bb063a92698312fc2 to your computer and use it in GitHub Desktop.
A builder I made for apache's velocity template
import lombok.Getter;
import lombok.Setter;
import spark.ModelAndView;
import spark.template.velocity.VelocityTemplateEngine;
import java.util.HashMap;
@Getter
@Setter
public class VelocityTemplateBuilder {
private HashMap<String,Object> model = new HashMap<>();
private String viewName;
public VelocityTemplateBuilder(String viewName){
this.viewName = viewName;
if (!this.viewName.endsWith(".vm"))
this.viewName = viewName + ".vm";
}
public VelocityTemplateBuilder addEntry(String key,Object value){
model.put(key,value);
return this;
}
public String build(){
return new VelocityTemplateEngine().render(new ModelAndView(model,viewName));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment