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

#262 Upgrade Thymeleaf to 3.0 #263

Merged
merged 1 commit into from Jul 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 1 addition & 8 deletions pom.xml
Expand Up @@ -79,8 +79,7 @@
<slf4j.version>1.7.6</slf4j.version>
<logback.version>1.1.1</logback.version>
<assertj.version>1.7.0</assertj.version>
<thymeleaf.version>2.1.3.RELEASE</thymeleaf.version>
<thymeleaf.extras.version>2.1.1.RELEASE</thymeleaf.extras.version>
<thymeleaf.version>3.0.0.RELEASE</thymeleaf.version>
<json-simple.version>1.1.1</json-simple.version>
<!-- <pebble.version>1.3.0</pebble.version> -->
<jade.version>0.4.2</jade.version>
Expand Down Expand Up @@ -443,12 +442,6 @@
<version>${thymeleaf.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-conditionalcomments</artifactId>
<version>${thymeleaf.extras.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>de.neuland-bfi</groupId>
<artifactId>jade4j</artifactId>
Expand Down
36 changes: 14 additions & 22 deletions src/main/java/org/jbake/template/ThymeleafTemplateEngine.java
@@ -1,30 +1,28 @@
package org.jbake.template;

import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.lang.LocaleUtils;
import org.jbake.app.ConfigUtil.Keys;
import org.jbake.app.Crawler.Attributes;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.context.VariablesMap;
import org.thymeleaf.dialect.IDialect;
import org.thymeleaf.templateresolver.FileTemplateResolver;

import java.io.File;
import java.io.Writer;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.locks.ReentrantLock;

import org.apache.commons.configuration.CompositeConfiguration;
import org.apache.commons.lang.LocaleUtils;
import org.jbake.app.ConfigUtil.Keys;
import org.jbake.app.ContentStore;
import org.jbake.app.Crawler.Attributes;
import org.thymeleaf.TemplateEngine;
import org.thymeleaf.context.Context;
import org.thymeleaf.templateresolver.FileTemplateResolver;

/**
* <p>A template engine which renders pages using Thymeleaf.</p>
*
* <p>This template engine is not recommended for large sites because the whole model
* is loaded into memory due to Thymeleaf internal limitations.</p>
*
* <p>The default rendering mode is "HTML5", but it is possible to use another mode
* <p>The default rendering mode is "HTML", but it is possible to use another mode
* for each document type, by adding a key in the configuration, for example:</p>
* <p/>
* <code>
Expand All @@ -51,12 +49,6 @@ private void initializeTemplateEngine() {
templateResolver.setCharacterEncoding(config.getString(Keys.TEMPLATE_ENCODING));
templateEngine = new TemplateEngine();
templateEngine.setTemplateResolver(templateResolver);
try {
IDialect condCommentDialect = (IDialect) Class.forName("org.thymeleaf.extras.conditionalcomments.dialect.ConditionalCommentsDialect").newInstance();
templateEngine.addDialect(condCommentDialect);
} catch (Exception e) {
// Sad, but true and not a real problem
}
}

@Override
Expand All @@ -71,7 +63,7 @@ public void renderDocument(final Map<String, Object> model, final String templat
Map<String, Object> config = (Map<String, Object>) model.get("config");
@SuppressWarnings("unchecked")
Map<String, Object> content = (Map<String, Object>) model.get("content");
String mode = "HTML5";
String mode = "HTML";
if (config != null && content != null) {
String key = "template_" + content.get(Attributes.TYPE) + "_thymeleaf_mode";
String configMode = (String) config.get(key);
Expand All @@ -86,12 +78,12 @@ public void renderDocument(final Map<String, Object> model, final String templat
}
}

private VariablesMap<String, Object> wrap(final Map<String, Object> model) {
return new JBakeVariablesMap(model);
private Map<String, Object> wrap(final Map<String, Object> model) {
return new JBakeMap(model);
}

private class JBakeVariablesMap extends VariablesMap<String, Object> {
public JBakeVariablesMap(final Map<String, Object> model) {
private class JBakeMap extends HashMap<String, Object> {
public JBakeMap(final Map<String, Object> model) {
super(model);
for(String key : extractors.keySet()) {
try {
Expand Down
Expand Up @@ -43,15 +43,15 @@ public ThymeleafTemplateEngineRenderingTest() {
"All about stuff!",
"<h5>Published Pages</h5>",
"/projects.html"));
outputStrings.put("index", Arrays.asList("<h4><a href=\"blog/2012/first-post.html\" shape=\"rect\">First Post</a></h4>",
"<h4><a href=\"blog/2013/second-post.html\" shape=\"rect\">Second Post</a></h4>"));
outputStrings.put("index", Arrays.asList("<h4><a href=\"blog/2012/first-post.html\">First Post</a></h4>",
"<h4><a href=\"blog/2013/second-post.html\">Second Post</a></h4>"));
outputStrings.put("feed", Arrays.asList("<description>My corner of the Internet</description>",
"<title>Second Post</title>",
"<title>First Post</title>"));
outputStrings.put("archive", Arrays.asList("<a href=\"blog/2013/second-post.html\" shape=\"rect\">Second Post</a></h4>",
"<a href=\"blog/2012/first-post.html\" shape=\"rect\">First Post</a></h4>"));
outputStrings.put("tags", Arrays.asList("<a href=\"blog/2013/second-post.html\" shape=\"rect\">Second Post</a></h4>",
"<a href=\"blog/2012/first-post.html\" shape=\"rect\">First Post</a></h4>"));
outputStrings.put("archive", Arrays.asList("<a href=\"blog/2013/second-post.html\">Second Post</a></h4>",
"<a href=\"blog/2012/first-post.html\">First Post</a></h4>"));
outputStrings.put("tags", Arrays.asList("<a href=\"blog/2013/second-post.html\">Second Post</a></h4>",
"<a href=\"blog/2012/first-post.html\">First Post</a></h4>"));
outputStrings.put("sitemap", Arrays.asList("blog/2013/second-post.html",
"blog/2012/first-post.html",
"papers/published-paper.html"));
Expand Down