velocity-engine
velocity-engine copied to clipboard
refactor the velocity with a more scalable api and spi interfaces
I want to refactor the velocity with a more scalable API (for Users) and SPI (for Developers), but I don't know whether it's needed, So I created this pr for ensure it (Please tell me if you need otherwise please close this pr, Thank you! ).
The target is:
- compile the template(.vm) to a java class(.java), also provide a interpreter like now.
- the template#render will compile the generated java code to a java class and execute it.
The sample usage For User:
Template template = VelocityEngine.getTemplate(name, locale, encoding);
template.render(context, writer);
Sample Implementation is:
Template getTemplate(String name, Locale locale, String encoding) {
// 0. cache
Resource r = cache.get(name);
// 1. load (the loader maybe is ClasspathLoader, FileLoader, JarLoader... )
r = loader.load(name, locale, encoding);
// 2. read a .vm file to string with encoding
String source = r.getSource();
// 3. convert xxs characters
source = converter.convert(name, source);
// 4. compile
Class<?> templateClass = compiler.compile(source); // maybe a CompiledTemplate or a InterpretedTemplate
// 5. create template instance
return templateClass.getConstructor().newInstance();
}
Nice idea, but we won't introduce another logging abstraction. We have replaced log chutes with SLF4J for very good reasons. Drop that part please.
Got it, Thank you!
This api looks alot like handlebars. this is pretty slick.