com.github.spt-oss:thymeleaf-extras

Thymeleaf extra modules for customizing templates

License

License

Categories

Categories

Leaf Data Databases
GroupId

GroupId

com.github.spt-oss
ArtifactId

ArtifactId

thymeleaf-extras
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

pom
Description

Description

Thymeleaf extra modules for customizing templates
Project URL

Project URL

https://github.com/spt-oss/thymeleaf-extras
Project Organization

Project Organization

SPT
Source Code Management

Source Code Management

https://github.com/spt-oss/thymeleaf-extras/tree/master

Download thymeleaf-extras

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.spt-oss/thymeleaf-extras/ -->
<dependency>
    <groupId>com.github.spt-oss</groupId>
    <artifactId>thymeleaf-extras</artifactId>
    <version>0.1.0</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.spt-oss/thymeleaf-extras/
implementation 'com.github.spt-oss:thymeleaf-extras:0.1.0'
// https://jarcasting.com/artifacts/com.github.spt-oss/thymeleaf-extras/
implementation ("com.github.spt-oss:thymeleaf-extras:0.1.0")
'com.github.spt-oss:thymeleaf-extras:pom:0.1.0'
<dependency org="com.github.spt-oss" name="thymeleaf-extras" rev="0.1.0">
  <artifact name="thymeleaf-extras" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.github.spt-oss', module='thymeleaf-extras', version='0.1.0')
)
libraryDependencies += "com.github.spt-oss" % "thymeleaf-extras" % "0.1.0"
[com.github.spt-oss/thymeleaf-extras "0.1.0"]

Dependencies

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.16.18

Project Modules

  • thymeleaf-extras-minify

Thymeleaf Extras

circleci maven central javadoc

  • Thymeleaf extra modules for customizing templates
  • Note: This project is unofficial and experimental.

TOC

thymeleaf-extras-minify

Example

  • Thymeleaf template
     <!DOCTYPE html>
     <html xmlns:th="http://www.thymeleaf.org">
     
     <!-- head -->
     <head>
         <meta charset="utf-8" />
         <title th:text="bar">foo</title>
         <style>
         body {
           font-size: 1rem;
         }
         </style>
     ......
  • Processed HTML
     <!DOCTYPE html><html><head><meta charset="utf-8" /><title>bar</title><style>body { font-size: 1rem; }</style>......

Usage

  1. Add a dependency in your project.

    <dependency>
        <groupId>com.github.spt-oss</groupId>
        <artifactId>thymeleaf-extras-minify</artifactId>
        <version>3.0.11.0</version>
    </dependency>
  2. Add the MinifierDialect to the TemplateEngine instance.

    import org.thymeleaf.TemplateEngine;
    import org.thymeleaf.extras.minify.dialect.MinifierDialect;
    
    TemplateEngine engine = new TemplateEngine();
    engine.addDialect(new MinifierDialect());
  3. Or setup Spring configurations if your project is based on Spring Boot.

    spring.thymeleaf:
        prefix: classpath:/templates/
    import org.springframework.context.annotation.Bean;
    import org.thymeleaf.extras.minify.dialect.MinifierDialect;
    
    @Bean
    public MinifierDialect minifierDialect() {
        return new MinifierDialect();
    }

Customization

  1. Create a subclass of AbstractMinifierTemplateHandler or SimpleMinifierTemplateHandler.

    package my.project;
    
    import org.thymeleaf.extras.minify.engine.AbstractMinifierTemplateHandler;
    
    public class MyMinifierTemplateHandler extends AbstractMinifierTemplateHandler {
        ......
    }
  2. Set the class to the first argument of the MinifierDialect. Note that only class type is accepted because of Thymeleaf processor's restriction.

    import my.project.MyMinifierTemplateHandler;
    
    TemplateEngine engine = new TemplateEngine();
    engine.addDialect(new MinifierDialect(MyMinifierTemplateHandler.class));
    import my.project.MyMinifierTemplateHandler;
    
    @Bean
    public MinifierDialect minifierDialect() {
        return new MinifierDialect(MyMinifierTemplateHandler.class);
    }

References

License

  • This software is released under the Apache License 2.0.
com.github.spt-oss

SPT

Open Source Libraries for Java

Versions

Version
0.1.0