Skip to content

domix/jade4j-spring-boot-starter

Repository files navigation

pug4j Spring Boot Starter

Build Status Coverage Status Apache License 2 Gitter


This Starter provides you the minimal and required configuration to use pug/jade templates as views in your Spring Boot application.

Behind the scenes, this starter uses the pug4j and spring-pug4j libraries.

Environment

JDK Spring Framework Spring Boot

Download

Maven Central Download

JCenter Download

GitHub, Factoids and Stats

Forks Release Issues


Usage

The usage is pretty straightforward as you can expect for any Spring Boot Starter

Add Maven dependency

build.gradle

...
dependencies {
  compile "com.domingosuarez.boot:jade4j-spring-boot-starter:2.0.4.RELEASE"
}
...

pom.xml

<project>
  ...
  <dependencies>
    <dependency>
      <groupId>com.domingosuarez.boot</groupId>
      <artifactId>jade4j-spring-boot-starter</artifactId>
      <version>2.0.4.RELEASE</version>
    </dependency>
  </dependencies>
</project>

Pug templates

Add the pug templates in the following directory

src
└── main
    └── resources
        └── templates
            └── index.pug

Then you can add new Spring MVC controllers as usual


Helpers

You can add helpers automatically using the annotation @PugHelper

package demo;

import com.domingosuarez.boot.autoconfigure.pug4j.JadeHelper;

@PugHelper
public class Util {
  public String format(double number) {
    return "some formating";
  }
}

template.pug

html
  head
    title Hello
  body
    h
    h1
      #{util.format(4)} # (1)
  1. The helper name’s is the Spring Bean id

Customize the helper’s name

You can customize the helper’s name using the PugHelper annotation

package demo;

import com.domingosuarez.boot.autoconfigure.pug4j.PugHelper;

@PugHelper("myId") // (1)
public class Util {
  public String format(double number) {
    return "some formating";
  }
}
  1. The new id

template.pug

html
  head
    title Hello
  body
    h
    h1
      #{myId.format(4)}

Configuration

The following settings are available:

Setting key Type Default value

spring.pug4j.checkTemplateLocation

Boolean

true

spring.pug4j.prefix

String

'classpath:/templates/'

spring.pug4j.suffix

String

'.pug'

spring.pug4j.encoding

String

'UTF-8'

spring.pug4j.caching

Boolean

true

spring.pug4j.prettyPrint

Boolean

false

spring.pug4j.mode

String

'HTML'

spring.pug4j.contentType

String

'text/html'

spring.pug4j.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.