Skip to content

LionelWoody/spring-boot-starter-pebble

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Starter Pebble

Maven Central Build Status Coverage Status

Spring Boot Starter support for Pebble (A lightweight but rock solid Java templating engine.).

Usage

Getting started

Add spring-boot-starter-pebble as dependency.

With Gradle:

repositories {
    mavenCentral()
}

dependencies {
    compile 'org.woodylab.boot:spring-boot-starter-pebble:0.2.3'
}

With Maven:

<dependency>
    <groupId>org.woodylab.boot</groupId>
    <artifactId>spring-boot-starter-pebble</artifactId>
    <version>0.2.3</version>
</dependency>

How to extend the library

CustomExtension is supported since version 0.2.0. You can define your extension, simply annotation it and then you can use it in your template.

@EnableAutoConfiguration
@PebbleExtension
public class CustomPebbleExtension extends AbstractExtension {
    @Override
    public Map<String, Filter> getFilters() {
        Map<String, Filter> filters = new HashMap<>();
        filters.put("noArgumentsButCanAccessContext", new Filter() {
            @Override
            public List<String> getArgumentNames() {
                return null;
            }
            @Override
            public String apply(Object input, Map<String, Object> args) {
                EvaluationContext context = (EvaluationContext) args.get("_context");
                PebbleTemplateImpl pebbleTemplate = (PebbleTemplateImpl) args.get("_self");
                if (context != null && pebbleTemplate != null) {
                    return "success";
                } else {
                    return "failure";
                }
            }
        });
        return filters;
    }
}

License

spring-boot-starter-pebble is published under Apache License 2.0.