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

Superfast baking with Thymeleaf #220

Merged
merged 1 commit into from
Jun 24, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/main/java/org/jbake/template/ThymeleafTemplateEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,21 @@ public class ThymeleafTemplateEngine extends AbstractTemplateEngine {
private TemplateEngine templateEngine;
private FileTemplateResolver templateResolver;

private String templateMode;

public ThymeleafTemplateEngine(final CompositeConfiguration config, final ContentStore db, final File destination, final File templatesPath) {
super(config, db, destination, templatesPath);
initializeTemplateEngine();
}

private void initializeTemplateEngine() {
private void initializeTemplateEngine(String mode) {
if (mode.equals(templateMode)) {
return;
}
templateMode = mode;
templateResolver = new FileTemplateResolver();
templateResolver.setPrefix(templatesPath.getAbsolutePath() + File.separatorChar);
templateResolver.setCharacterEncoding(config.getString(Keys.TEMPLATE_ENCODING));
templateResolver.setTemplateMode(mode);
templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
try {
Expand All @@ -75,7 +81,6 @@ public void renderDocument(final Map<String, Object> model, final String templat
Context context = new Context(locale, wrap(model));
lock.lock();
try {
initializeTemplateEngine();
@SuppressWarnings("unchecked")
Map<String, Object> config = (Map<String, Object>) model.get("config");
@SuppressWarnings("unchecked")
Expand All @@ -88,7 +93,7 @@ public void renderDocument(final Map<String, Object> model, final String templat
mode = configMode;
}
}
templateResolver.setTemplateMode(mode);
initializeTemplateEngine(mode);
templateEngine.process(templateName, context, writer);
} finally {
lock.unlock();
Expand Down