add jade engine example (#2365)

* add jade engine example

* formatting
This commit is contained in:
lor6 2017-08-03 19:47:25 +03:00 committed by Grzegorz Piwowarek
parent 8e9c36c98e
commit 71f1a2bc44
5 changed files with 65 additions and 0 deletions

View File

@ -27,6 +27,7 @@
<org.thymeleaf-version>3.0.7.RELEASE</org.thymeleaf-version> <org.thymeleaf-version>3.0.7.RELEASE</org.thymeleaf-version>
<groovy.version>2.4.12</groovy.version> <groovy.version>2.4.12</groovy.version>
<freemarker.version>2.3.23</freemarker.version> <freemarker.version>2.3.23</freemarker.version>
<jade.version>1.2.5</jade.version>
</properties> </properties>
<dependencies> <dependencies>
@ -115,6 +116,13 @@
<version>${groovy.version}</version> <version>${groovy.version}</version>
</dependency> </dependency>
<!-- jade dependency -->
<dependency>
<groupId>de.neuland-bfi</groupId>
<artifactId>spring-jade4j</artifactId>
<version>${jade.version}</version>
</dependency>
</dependencies> </dependencies>
<build> <build>
<pluginManagement> <pluginManagement>

View File

@ -0,0 +1,39 @@
package com.baeldung.spring.configuration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import de.neuland.jade4j.JadeConfiguration;
import de.neuland.jade4j.spring.template.SpringTemplateLoader;
import de.neuland.jade4j.spring.view.JadeViewResolver;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.baeldung.springmvcforms", "com.baeldung.spring.controller", "com.baeldung.spring.validator" })
public class JadeTemplateConfiguration {
@Bean
public SpringTemplateLoader templateLoader() {
SpringTemplateLoader templateLoader = new SpringTemplateLoader();
templateLoader.setBasePath("/WEB-INF/views/");
templateLoader.setSuffix(".jade");
return templateLoader;
}
@Bean
public JadeConfiguration jadeConfiguration() {
JadeConfiguration configuration = new JadeConfiguration();
configuration.setCaching(false);
configuration.setTemplateLoader(templateLoader());
return configuration;
}
@Bean
public ViewResolver viewResolver() {
JadeViewResolver viewResolver = new JadeViewResolver();
viewResolver.setConfiguration(jadeConfiguration());
return viewResolver;
}
}

View File

@ -18,6 +18,7 @@ public class WebInitializer implements WebApplicationInitializer {
//ctx.register(ThymeleafConfiguration.class); //ctx.register(ThymeleafConfiguration.class);
//ctx.register(FreemarkerConfiguration.class); //ctx.register(FreemarkerConfiguration.class);
//ctx.register(GroovyConfiguration.class); //ctx.register(GroovyConfiguration.class);
//ctx.register(JadeTemplateConfiguration.class);
ctx.setServletContext(container); ctx.setServletContext(container);
// Manage the lifecycle of the root application context // Manage the lifecycle of the root application context

View File

@ -35,6 +35,12 @@ public class UserController {
return "registration-groovy"; return "registration-groovy";
} }
@GetMapping("/registration-jade")
public String getRegistrationJade(Model model) {
model.addAttribute("user", new User());
return "registration-jade";
}
@PostMapping("/register") @PostMapping("/register")
@ResponseBody @ResponseBody
public void register(User user){ public void register(User user){

View File

@ -0,0 +1,11 @@
doctype html
html
head
title User Registration
body
form(action="register" method="post" )
label(for="email") Emailaaaaaaaa:
input(type="text" name="email")
label(for="password") Password:
input(type="password" name="password")
input(type="submit" value="Submit")