Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor the velocity with a more scalable api and spi interfaces #25

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

xiaoma20082008
Copy link

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:

  1. compile the template(.vm) to a java class(.java), also provide a interpreter like now.
  2. 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();
}

@xiaoma20082008 xiaoma20082008 changed the title refactor the velocity with more scalable api and spi refactor the velocity with a more scalable api and spi interfaces Sep 14, 2021
Copy link
Member

@michael-o michael-o left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@xiaoma20082008
Copy link
Author

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!

@AnthonyJClink
Copy link

This api looks alot like handlebars. this is pretty slick.

@xiaoma20082008
Copy link
Author

I was fired after i started on this issues, and lost many commits on my old computer as it's belong to the company, I'll restart now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants