001package io.jstach.jstachio; 002 003import java.util.function.Function; 004 005import org.eclipse.jdt.annotation.Nullable; 006 007/** 008 * A Container for optional template collaborators for ease of wiring generated 009 * {@link Template}s. 010 * 011 * @apiNote the default methods return <code>null</code> to indicate to the template 012 * constructor to use the static default collaborator and is the reason why 013 * {@link TemplateInfo} does not extend this interface. 014 * @author agentgt 015 * 016 */ 017public interface TemplateConfig { 018 019 /** 020 * A config with no provided collaborators. 021 * @return empty config 022 */ 023 public static TemplateConfig empty() { 024 return EmptyTemplateConfig.INSTANCE; 025 } 026 027 /** 028 * The escaper to be used on the template. See {@link Escaper#of(Function)}. 029 * @apiNote While the return signature is {@link Function} the function is often an 030 * {@link Escaper} but does not have to be. 031 * @return the escaper or <code>null</code> 032 * @see Escaper 033 */ 034 default @Nullable Function<String, String> escaper() { 035 return null; 036 } 037 038 /** 039 * The base formatter to be used on the template. See {@link Formatter#of(Function)}. 040 * @apiNote While the return signature is {@link Function} the function is often a 041 * {@link Formatter} but does not have to be. 042 * @return the formatter or <code>null</code> 043 * @see Formatter 044 */ 045 @SuppressWarnings("exports") 046 default @Nullable Function<@Nullable Object, String> formatter() { 047 return null; 048 } 049 050} 051 052enum EmptyTemplateConfig implements TemplateConfig { 053 054 INSTANCE; 055 056}