001package io.jstach.opt.spring.webflux.example; 002 003import java.util.List; 004 005import org.springframework.context.annotation.Bean; 006import org.springframework.context.annotation.Configuration; 007import org.springframework.core.env.Environment; 008 009import io.jstach.jstachio.JStachio; 010import io.jstach.jstachio.Template; 011import io.jstach.jstachio.spi.JStachioExtension; 012import io.jstach.opt.spring.SpringJStachio; 013import io.jstach.opt.spring.SpringJStachioExtension; 014 015/** 016 * Configures JStachio Spring style. 017 */ 018@Configuration 019public class SpringTemplateConfig { 020 021 /** 022 * Do nothing constructor to placate jdk 18 javadoc 023 */ 024 public SpringTemplateConfig() { 025 } 026 027 /** 028 * Creates a services based on spring objects. 029 * @param environment used for config 030 * @param templates found templates via component scanning 031 * @return the services 032 */ 033 @Bean 034 public SpringJStachioExtension jstachioService(Environment environment, List<Template<?>> templates) { 035 return new SpringJStachioExtension(environment, templates); 036 } 037 038 /** 039 * Creates jstachio from found plugins 040 * @param services plugins 041 * @return spring version fo jstachio 042 */ 043 @Bean 044 public SpringJStachio jstachio(List<JStachioExtension> services) { 045 var js = new SpringJStachio(services); 046 // We need this for the view mixins. 047 JStachio.setStaticJStachio(() -> js); 048 return js; 049 } 050 051}