Spring Boot jade4j Starter
This Starter provides you the minimal and required configuration to use jade templates as views in your Spring Boot application.
Behind the scenes, this starter uses the jade4j and spring-jade4j libraries.
Usage
The usage is pretty straightforward as you can expect for any Starter.
Add Maven dependency
build.gradle
...
dependencies {
compile "com.domingosuarez.boot:spring-boot-starter-jade4j:0.2"
}
...
pom.xml
<project>
...
<dependencies>
<dependency>
<groupId>com.domingosuarez.boot</groupId>
<artifactId>spring-boot-starter-jade4j</artifactId>
<version>0.2</version>
</dependency>
</dependencies>
</project>
Jade templates
Add the jade templates in the following directory
src └── main └── resources └── templates └── index.jade
Then you can add new Spring MVC controllers as usual
Helpers
You can add helpers automatically using the annotation @JadeHelper
package demo;
import com.domingosuarez.boot.autoconfigure.jade4j.JadeHelper;
@JadeHelper
public class Util {
public String format(double number) {
return "some formating";
}
}
template.jade
html head title Hello body h h1 #{util.format(4)} # (1)
-
The helper name’s is the Spring Bean id
Customize the helper’s name
You can customize the helper’s name using the JadeHelper annotation
package demo;
import com.domingosuarez.boot.autoconfigure.jade4j.JadeHelper;
@JadeHelper("myId") // (1)
public class Util {
public String format(double number) {
return "some formating";
}
}
-
The new id
template.jade
html head title Hello body h h1 #{myId.format(4)}
Configuration
The following settings are available:
Setting key | Type | Default value |
---|---|---|
spring.jade4j.checkTemplateLocation |
Boolean |
true |
spring.jade4j.prefix |
String |
'classpath:/templates/' |
spring.jade4j.suffix |
String |
'.jade' |
spring.jade4j.encoding |
String |
'UTF-8' |
spring.jade4j.caching |
Boolean |
true |
spring.jade4j.prettyPrint |
Boolean |
false |
spring.jade4j.mode |
String |
'HTML' |
spring.jade4j.contentType |
String |
'text/html' |
spring.jade4j.resolver.order |
Integer |
Ordered.LOWEST_PRECEDENCE - 50 |
Complete demo application
Please take a look into this application if you want to checkout a fully application.