spring boot starter for rocker template
I'm apply for release to maven centory repository now, before that, you can follow the following steps to use.
- You can run
mvn install
to install this artifact to your local repository.
<dependencies>
<dependency>
<groupId>com.pointcx</groupId>
<artifactId>rocker-spring-boot-starter</artifactId>
<version>1.2.1</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>rocker-runtime</artifactId>
<version>1.2.1</version>
</dependency>
<!-- for hot-reloading support only during development -->
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>rocker-compiler</artifactId>
<version>1.2.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
- rocker-spring-boot-starter will enable dynamic reloading by default.
- this configuration is optional. for convince, you can add to your pom.xml and run 'mvn generate-sources' to generate java code manually.
<build>
<plugins>
<!-- ...-->
<plugin>
<groupId>com.fizzed</groupId>
<artifactId>rocker-maven-plugin</artifactId>
<version>1.2.1</version>
<executions>
<execution>
<id>generate-rocker-templates</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<javaVersion>${java.version}</javaVersion>
<templateDirectory>src/main/resources</templateDirectory>
<outputDirectory>target/generated-sources/rocker</outputDirectory>
<discardLogicWhitespace>true</discardLogicWhitespace>
<targetCharset>UTF-8</targetCharset>
<postProcessing>
<param>com.fizzed.rocker.processor.LoggingProcessor</param>
<param>com.fizzed.rocker.processor.WhitespaceRemovalProcessor</param>
</postProcessing>
</configuration>
</execution>
</executions>
</plugin>
<!--... -->
</plugins>
</build>
for example:
spring.rocker.enabled=true
spring.rocker.reloading=true
spring.rocker.expose-request-attributes=true
spring.rocker.allow-request-override=true
spring.rocker.expose-session-attributes=false
spring.rocker.expose-spring-macro-helpers=true
spring.rocker.suffix=.html
spring.rocker.prefix=classpath:/rocker/
spring.rocker.enabled=true
spring.rocker.reloading=true
spring.rocker.templateResolverOrder=214748213637
spring.rocker.prefix=classpath:/templates/
spring.rocker.suffix=.rocker.html
spring.rocker.contentType="text/html;charset=utf-8"
spring.rocker.expose-request-attribute=false
spring.rocker.allow-request-override=false
spring.rocker.expose-session-attributes=false
spring.rocker.allow-session-override=false
spring.rocker.expose-spring-macro-helpers=true
- path:
<maven_project>/src/main/resources/templates/layout/layout.rocker.html
@import java.util.*
@import rocker.*
@args(RockerContent header, RockerContent script, RockerBody body)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href='@$r.path("/static/deps/bootstrap-4.1.3-dist/css/bootstrap.min.css")'/>
<link rel="stylesheet" href='@$r.path("/static/deps/font-awesome/css/font-awesome.css")'>
<link rel="stylesheet" href='@$r.path("/static/css/style.css")'>
@header
</head>
<body class="white-bg">
@body
<script src='@$r.path("/static/deps/jquery/jquery-3.4.1.min.js")'></script>
<script src='@$r.path("/static/deps/popper.js/popper-1.14.3.min.js")'></script>
<script src='@$r.path("/static/deps/bootstrap-4.1.3-dist/js/bootstrap.min.js")'></script>
<script src='@$r.path("/static/js/app.js")'></script>
@script
</body>
</html>
- path:
<maven_project>/src/main/resources/templates/login.rocker.html
@import java.util.*
@import rocker.*
@args()
@header => {
<title>Login</title>
}
@script => {
<script>
alert("I'm login page!");
</script>
}
@$r.template("layout/layout", header, script)->{
body!
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href='/static/deps/bootstrap-4.1.3-dist/css/bootstrap.min.css'/>
<link rel="stylesheet" href='/static/deps/font-awesome/css/font-awesome.css'>
<link rel="stylesheet" href='/static/css/style.css'>
<title>Login</title>
</head>
<body class="white-bg">
body!
<script src='/static/deps/jquery/jquery-3.4.1.min.js'></script>
<script src='/static/deps/popper.js/popper-1.14.3.min.js'></script>
<script src='/static/deps/bootstrap-4.1.3-dist/js/bootstrap.min.js'></script>
<script src='/static/js/app.js'></script>
<script>
alert("I'm login page!");
</script>
</body>
</html>
$r.getApplicationContext();
$r.bean("beanName");
$r.bean(/*bean class*/);
$r.prop("name");
$r.prop("name", "defaultValue");
$r.msg("code");
$r.msg("code", param1, param2, ...);
$r.request();
$r.paramString("name", "defaultValue");
$r.paramString("name");
$r.paramInt("name", 0);
$r.paramInt("name"); /* return null Integer if not exist*/
$r.paramFloat("name", 0.0f);
$r.paramFloat("name"); /*return null Float if not exist*/
$r.paramLong("name", 0);
$r.paramLong("name");/*return null Long if not exist*/
$r.paramDouble("name", 0.0d);
$r.paramDouble("name"); /*return null Double if not exist*/
$r.paramDate("name", "yyyy-MM-dd HH:mm:ss");
$r.paramDate("name", "MM/dd/yyyy");
$r.paramDate("name", "yyyy-MM-dd", new Date());
$r.attr("name");
$r.attr("name", defaultValue);
$r.field("user.username"); /*user stored in request.attribute, this will invoke user.getUsername()*/
$r.field("user", "username"); /*user stored in request.attribute, this will invoke user.getUsername()*/
<img src='@$r.path("/static/images/logo.png")'/>
<head>
<meta name="_csrf" content="@$r.csrf()"/>
<meta name="_csrf_header" content="@$r.csrfTokenHeaderName()"/>
</head>
<body>
<form method="post">
<input type="hidden" name="@$r.csrfTokenParameterName()" value="@$r.csrf()">
</form>
<script>
$(function () {
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");
$(document).ajaxSend(function(e, xhr, options) {
xhr.setRequestHeader(header, token);
});
});
</script>
</body>
@import java.util.*
@import rocker.*
@args()
@header => {
}
@script => {
}
// dynamic invoke rocker template
@$r.template("layout/layout", header, script)->{
body!
}