Skip to content

Commit 71f1a2b

Browse files
lor6pivovarit
authored andcommitted
add jade engine example (eugenp#2365)
* add jade engine example * formatting
1 parent 8e9c36c commit 71f1a2b

5 files changed

Lines changed: 65 additions & 0 deletions

File tree

‎spring-mvc-simple/pom.xml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
<org.thymeleaf-version>3.0.7.RELEASE</org.thymeleaf-version>
2828
<groovy.version>2.4.12</groovy.version>
2929
<freemarker.version>2.3.23</freemarker.version>
30+
<jade.version>1.2.5</jade.version>
3031
</properties>
3132

3233
<dependencies>
@@ -114,6 +115,13 @@
114115
<artifactId>groovy-templates</artifactId>
115116
<version>${groovy.version}</version>
116117
</dependency>
118+
119+
<!-- jade dependency -->
120+
<dependency>
121+
<groupId>de.neuland-bfi</groupId>
122+
<artifactId>spring-jade4j</artifactId>
123+
<version>${jade.version}</version>
124+
</dependency>
117125

118126
</dependencies>
119127
<build>
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.baeldung.spring.configuration;
2+
3+
import org.springframework.context.annotation.Bean;
4+
import org.springframework.context.annotation.ComponentScan;
5+
import org.springframework.context.annotation.Configuration;
6+
import org.springframework.web.servlet.ViewResolver;
7+
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
8+
9+
import de.neuland.jade4j.JadeConfiguration;
10+
import de.neuland.jade4j.spring.template.SpringTemplateLoader;
11+
import de.neuland.jade4j.spring.view.JadeViewResolver;
12+
13+
@Configuration
14+
@EnableWebMvc
15+
@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" })
16+
public class JadeTemplateConfiguration {
17+
@Bean
18+
public SpringTemplateLoader templateLoader() {
19+
SpringTemplateLoader templateLoader = new SpringTemplateLoader();
20+
templateLoader.setBasePath("/WEB-INF/views/");
21+
templateLoader.setSuffix(".jade");
22+
return templateLoader;
23+
}
24+
25+
@Bean
26+
public JadeConfiguration jadeConfiguration() {
27+
JadeConfiguration configuration = new JadeConfiguration();
28+
configuration.setCaching(false);
29+
configuration.setTemplateLoader(templateLoader());
30+
return configuration;
31+
}
32+
33+
@Bean
34+
public ViewResolver viewResolver() {
35+
JadeViewResolver viewResolver = new JadeViewResolver();
36+
viewResolver.setConfiguration(jadeConfiguration());
37+
return viewResolver;
38+
}
39+
}

‎spring-mvc-simple/src/main/java/com/baeldung/spring/configuration/WebInitializer.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public void onStartup(ServletContext container) throws ServletException {
1818
//ctx.register(ThymeleafConfiguration.class);
1919
//ctx.register(FreemarkerConfiguration.class);
2020
//ctx.register(GroovyConfiguration.class);
21+
//ctx.register(JadeTemplateConfiguration.class);
2122
ctx.setServletContext(container);
2223

2324
// Manage the lifecycle of the root application context

‎spring-mvc-simple/src/main/java/com/baeldung/spring/controller/UserController.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ public String getRegistrationGroovy(Model model) {
3535
return "registration-groovy";
3636
}
3737

38+
@GetMapping("/registration-jade")
39+
public String getRegistrationJade(Model model) {
40+
model.addAttribute("user", new User());
41+
return "registration-jade";
42+
}
43+
3844
@PostMapping("/register")
3945
@ResponseBody
4046
public void register(User user){
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
doctype html
2+
html
3+
head
4+
title User Registration
5+
body
6+
form(action="register" method="post" )
7+
label(for="email") Emailaaaaaaaa:
8+
input(type="text" name="email")
9+
label(for="password") Password:
10+
input(type="password" name="password")
11+
input(type="submit" value="Submit")

0 commit comments

Comments
 (0)