-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
76 changed files
with
2,492 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
version: '3.2.0' | ||
--- | ||
|
||
- Add support for spring framework 6 and spring-boot 3 (#) | ||
- Bump minimum supported java version to 17 in pebble-spring6 and pebble-spring-boot-starter in order to work with spring |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<artifactId>pebble-spring</artifactId> | ||
<groupId>io.pebbletemplates</groupId> | ||
<version>3.2.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>pebble-legacy-spring-boot-starter</artifactId> | ||
|
||
<name>Pebble Spring Boot 2 Starter</name> | ||
<description>Spring Boot 2 starter for Pebble Template Engine</description> | ||
<url>http://pebbletemplates.io</url> | ||
|
||
<properties> | ||
<boot.version>2.7.5</boot.version> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
<version>${boot.version}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-webflux</artifactId> | ||
<version>${boot.version}</version> | ||
<optional>true</optional> | ||
</dependency> | ||
<dependency> | ||
<groupId>io.pebbletemplates</groupId> | ||
<artifactId>pebble-spring5</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
|
||
<!-- TEST --> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<version>${boot.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<configuration> | ||
<archive> | ||
<manifestEntries> | ||
<Automatic-Module-Name>io.pebbletemplates.spring.boot</Automatic-Module-Name> | ||
</manifestEntries> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
14 changes: 14 additions & 0 deletions
14
.../main/java/com/mitchellbosecke/pebble/boot/autoconfigure/AbstractPebbleConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.mitchellbosecke.pebble.boot.autoconfigure; | ||
|
||
abstract class AbstractPebbleConfiguration { | ||
|
||
protected String stripLeadingSlash(String value) { | ||
if (value == null) { | ||
return null; | ||
} | ||
if (value.startsWith("/")) { | ||
return value.substring(1); | ||
} | ||
return value; | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
.../src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.mitchellbosecke.pebble.boot.autoconfigure; | ||
|
||
import com.mitchellbosecke.pebble.PebbleEngine; | ||
import com.mitchellbosecke.pebble.attributes.methodaccess.MethodAccessValidator; | ||
import com.mitchellbosecke.pebble.extension.Extension; | ||
import com.mitchellbosecke.pebble.loader.ClasspathLoader; | ||
import com.mitchellbosecke.pebble.loader.Loader; | ||
import com.mitchellbosecke.pebble.spring.extension.SpringExtension; | ||
import java.util.List; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
import org.springframework.context.MessageSource; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.lang.Nullable; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnClass(PebbleEngine.class) | ||
@EnableConfigurationProperties(PebbleProperties.class) | ||
@Import({PebbleServletWebConfiguration.class, PebbleReactiveWebConfiguration.class}) | ||
public class PebbleAutoConfiguration extends AbstractPebbleConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(name = "pebbleLoader") | ||
public Loader<?> pebbleLoader(PebbleProperties properties) { | ||
ClasspathLoader loader = new ClasspathLoader(); | ||
loader.setCharset(properties.getCharsetName()); | ||
// classpath loader does not like leading slashes in resource paths | ||
loader.setPrefix(this.stripLeadingSlash(properties.getPrefix())); | ||
loader.setSuffix(properties.getSuffix()); | ||
return loader; | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
public SpringExtension springExtension(MessageSource messageSource) { | ||
return new SpringExtension(messageSource); | ||
} | ||
|
||
@Bean | ||
@ConditionalOnMissingBean(name = "pebbleEngine") | ||
public PebbleEngine pebbleEngine(PebbleProperties properties, | ||
Loader<?> pebbleLoader, | ||
SpringExtension springExtension, | ||
@Nullable List<Extension> extensions, | ||
@Nullable MethodAccessValidator methodAccessValidator) { | ||
PebbleEngine.Builder builder = new PebbleEngine.Builder(); | ||
builder.loader(pebbleLoader); | ||
builder.extension(springExtension); | ||
if (extensions != null && !extensions.isEmpty()) { | ||
builder.extension(extensions.toArray(new Extension[extensions.size()])); | ||
} | ||
if (!properties.isCache()) { | ||
builder.cacheActive(false); | ||
} | ||
if (properties.getDefaultLocale() != null) { | ||
builder.defaultLocale(properties.getDefaultLocale()); | ||
} | ||
builder.strictVariables(properties.isStrictVariables()); | ||
builder.greedyMatchMethod(properties.isGreedyMatchMethod()); | ||
if (methodAccessValidator != null) { | ||
builder.methodAccessValidator(methodAccessValidator); | ||
} | ||
return builder.build(); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.mitchellbosecke.pebble.boot.autoconfigure; | ||
|
||
import java.util.Locale; | ||
import org.springframework.boot.autoconfigure.template.AbstractTemplateViewResolverProperties; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
||
@ConfigurationProperties("pebble") | ||
public class PebbleProperties extends AbstractTemplateViewResolverProperties { | ||
|
||
public static final String DEFAULT_PREFIX = "/templates/"; | ||
public static final String DEFAULT_SUFFIX = ".pebble"; | ||
|
||
private Locale defaultLocale; | ||
private boolean strictVariables; | ||
private boolean greedyMatchMethod; | ||
|
||
public PebbleProperties() { | ||
super(DEFAULT_PREFIX, DEFAULT_SUFFIX); | ||
this.setCache(true); | ||
} | ||
|
||
public Locale getDefaultLocale() { | ||
return this.defaultLocale; | ||
} | ||
|
||
public void setDefaultLocale(Locale defaultLocale) { | ||
this.defaultLocale = defaultLocale; | ||
} | ||
|
||
public boolean isStrictVariables() { | ||
return this.strictVariables; | ||
} | ||
|
||
public void setStrictVariables(boolean strictVariables) { | ||
this.strictVariables = strictVariables; | ||
} | ||
|
||
public boolean isGreedyMatchMethod() { | ||
return this.greedyMatchMethod; | ||
} | ||
|
||
public void setGreedyMatchMethod(boolean greedyMatchMethod) { | ||
this.greedyMatchMethod = greedyMatchMethod; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...in/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleReactiveWebConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.mitchellbosecke.pebble.boot.autoconfigure; | ||
|
||
import com.mitchellbosecke.pebble.PebbleEngine; | ||
import com.mitchellbosecke.pebble.loader.ClasspathLoader; | ||
import com.mitchellbosecke.pebble.spring.reactive.PebbleReactiveViewResolver; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnWebApplication(type = Type.REACTIVE) | ||
class PebbleReactiveWebConfiguration extends AbstractPebbleConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
PebbleReactiveViewResolver pebbleReactiveViewResolver(PebbleProperties properties, | ||
PebbleEngine pebbleEngine) { | ||
String prefix = properties.getPrefix(); | ||
if (pebbleEngine.getLoader() instanceof ClasspathLoader) { | ||
// classpathloader doesn't like leading slashes in paths | ||
prefix = this.stripLeadingSlash(properties.getPrefix()); | ||
} | ||
PebbleReactiveViewResolver resolver = new PebbleReactiveViewResolver(pebbleEngine); | ||
resolver.setPrefix(prefix); | ||
resolver.setSuffix(properties.getSuffix()); | ||
resolver.setViewNames(properties.getViewNames()); | ||
resolver.setRequestContextAttribute(properties.getRequestContextAttribute()); | ||
return resolver; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ain/java/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleServletWebConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.mitchellbosecke.pebble.boot.autoconfigure; | ||
|
||
import com.mitchellbosecke.pebble.PebbleEngine; | ||
import com.mitchellbosecke.pebble.loader.ClasspathLoader; | ||
import com.mitchellbosecke.pebble.spring.servlet.PebbleViewResolver; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication.Type; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration(proxyBeanMethods = false) | ||
@ConditionalOnWebApplication(type = Type.SERVLET) | ||
class PebbleServletWebConfiguration extends AbstractPebbleConfiguration { | ||
|
||
@Bean | ||
@ConditionalOnMissingBean | ||
PebbleViewResolver pebbleViewResolver(PebbleProperties properties, | ||
PebbleEngine pebbleEngine) { | ||
PebbleViewResolver pvr = new PebbleViewResolver(pebbleEngine); | ||
properties.applyToMvcViewResolver(pvr); | ||
if (pebbleEngine.getLoader() instanceof ClasspathLoader) { | ||
// classpathloader doesn't like leading slashes in paths | ||
pvr.setPrefix(this.stripLeadingSlash(properties.getPrefix())); | ||
} | ||
|
||
return pvr; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...ava/com/mitchellbosecke/pebble/boot/autoconfigure/PebbleTemplateAvailabilityProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.mitchellbosecke.pebble.boot.autoconfigure; | ||
|
||
import org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider; | ||
import org.springframework.core.env.Environment; | ||
import org.springframework.core.io.ResourceLoader; | ||
import org.springframework.util.ClassUtils; | ||
|
||
import static org.springframework.core.io.ResourceLoader.CLASSPATH_URL_PREFIX; | ||
|
||
public class PebbleTemplateAvailabilityProvider implements TemplateAvailabilityProvider { | ||
|
||
@Override | ||
public boolean isTemplateAvailable(String view, Environment environment, ClassLoader classLoader, | ||
ResourceLoader resourceLoader) { | ||
if (ClassUtils.isPresent("com.mitchellbosecke.pebble.PebbleEngine", classLoader)) { | ||
String prefix = environment.getProperty("pebble.prefix", PebbleProperties.DEFAULT_PREFIX); | ||
String suffix = environment.getProperty("pebble.suffix", PebbleProperties.DEFAULT_SUFFIX); | ||
return resourceLoader.getResource(CLASSPATH_URL_PREFIX + prefix + view + suffix).exists(); | ||
} | ||
return false; | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
...oot-starter/src/main/java/com/mitchellbosecke/pebble/boot/autoconfigure/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Auto-configuration for Pebble Template Engine. | ||
*/ | ||
package com.mitchellbosecke.pebble.boot.autoconfigure; |
6 changes: 6 additions & 0 deletions
6
pebble-spring/pebble-legacy-spring-boot-starter/src/main/resources/META-INF/spring.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Auto Configure | ||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ | ||
com.mitchellbosecke.pebble.boot.autoconfigure.PebbleAutoConfiguration | ||
# Template availability providers | ||
org.springframework.boot.autoconfigure.template.TemplateAvailabilityProvider=\ | ||
com.mitchellbosecke.pebble.boot.autoconfigure.PebbleTemplateAvailabilityProvider |
1 change: 1 addition & 0 deletions
1
pebble-spring/pebble-legacy-spring-boot-starter/src/main/resources/META-INF/spring.provides
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
provides: pebble,pebble-spring5 |
Oops, something went wrong.