Skip to content

neuland/spring-pug4j

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Test Status

A Spring Integration for Pug4J

See neuland/pug4j for more information.

Bean Declarations

applicationContext.xml

<bean id="templateLoader" class="de.neuland.pug4j.spring.template.SpringTemplateLoader">
	<property name="templateLoaderPath" value="classpath:/templates" />
</bean>

<bean id="expressionHandler" class="de.neuland.pug4j.expression.GraalJsExpressionHandler">
</bean>

<bean id="pugConfiguration" class="de.neuland.pug4j.PugConfiguration">
	<property name="prettyPrint" value="false" />
	<property name="caching" value="false" />
	<property name="templateLoader" ref="templateLoader" />
	<!--<property name="expressionHandler" ref="expressionHandler" />-->
</bean>

<bean id="viewResolver" class="de.neuland.pug4j.spring.view.PugViewResolver">
	<property name="configuration" ref="pugConfiguration" />
	<!-- rendering nice html formatted error pages for development -->
	<property name="renderExceptions" value="true" />
</bean>

Or, if you are using Spring JavaConfig:

import de.neuland.pug4j.expression.GraalJsExpressionHandler;

@Configuration
public class PugConfig {

    @Bean
    public SpringTemplateLoader templateLoader() {
        SpringTemplateLoader templateLoader = new SpringTemplateLoader();
        templateLoader.setTemplateLoaderPath("classpath:/templates");
        templateLoader.setEncoding("UTF-8");
        templateLoader.setSuffix(".pug");
        return templateLoader;
    }

    @Bean
    public PugConfiguration pugConfiguration() {
        PugConfiguration configuration = new PugConfiguration();
        configuration.setCaching(false);
        configuration.setTemplateLoader(templateLoader());
        //To use the new GraalJsExpressionHandler add this:
        //configuration.setExpressionHandler(new GraalJsExpressionHandler());
        return configuration;
    }

    @Bean
    public ViewResolver viewResolver() {
        PugViewResolver viewResolver = new PugViewResolver();
        viewResolver.setConfiguration(pugConfiguration());
        return viewResolver;
    }
}

TemplateLoaderPath

SpringTemplateLoader uses the ResourceLoader of the Spring Framework. For more information how to configure the templateLoaderPath see ResourceLoader

Most people use something like 'classpath:/templates' which points to a templates folder in your resources.

Versions

3.1.0

  • update dependencies (thanks dbelyaev)
  • update to pug4j 2.1.0

3.0.0

  • switch to jakarta servlet-api
  • support of spring framework 6
  • needs java 17

Usage

via Maven

Just add following dependency definitions to your pom.xml.

<dependency>
  <groupId>de.neuland-bfi</groupId>
  <artifactId>spring-pug4j</artifactId>
  <version>3.1.0</version>
</dependency>

Author

License

The MIT License

Copyright (C) 2012-2023 neuland Büro für Informatik, Bremen, Germany

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.