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@SuppressWarnings("exports") 019@Configuration 020public class SpringTemplateConfig { 021 022 /** 023 * Do nothing constructor to placate jdk 18 javadoc 024 */ 025 public SpringTemplateConfig() { 026 } 027 028 /** 029 * Creates a services based on spring objects. 030 * @param environment used for config 031 * @param templates found templates via component scanning 032 * @return the services 033 */ 034 @Bean 035 public SpringJStachioExtension jstachioService(Environment environment, List<Template<?>> templates) { 036 return new SpringJStachioExtension(environment, templates); 037 } 038 039 /** 040 * Creates jstachio from found plugins 041 * @param services plugins 042 * @return spring version fo jstachio 043 */ 044 @Bean 045 public SpringJStachio jstachio(List<JStachioExtension> services) { 046 var js = new SpringJStachio(services); 047 // We need this for the view mixins. 048 JStachio.setStatic(() -> js); 049 return js; 050 } 051 052}