001package io.jstach.opt.spring.example.hello; 002 003/** 004 * Generated Renderer. 005 */ 006// @javax.annotation.Generated("io.jstach.apt.GenerateRendererProcessor") 007@org.springframework.stereotype.Component 008public class HelloModelView implements io.jstach.jstachio.Template<io.jstach.opt.spring.example.hello.HelloModel>, 009 io.jstach.jstachio.TemplateInfo, 010 io.jstach.jstachio.spi.TemplateProvider, 011 io.jstach.jstachio.spi.JStachioFilter.FilterChain { 012 /** 013 * Template path. 014 * @hidden 015 */ 016 public static final String TEMPLATE_PATH = "views/hello.mustache"; 017 018 /** 019 * Inline template string copied. 020 * @hidden 021 */ 022 023 public static final String TEMPLATE_STRING = ""; 024 025 /** 026 * Template name. Do not rely on this. 027 * @hidden 028 */ 029 public static final String TEMPLATE_NAME = "io.jstach.opt.spring.example.hello.HelloModelView"; 030 031 /** 032 * The models class. Use {@link #modelClass()} instead. 033 * @hidden 034 */ 035 public static final Class<?> MODEL_CLASS = io.jstach.opt.spring.example.hello.HelloModel.class; 036 037 /** 038 * The instance. Use {@link {@link #of()} instead. 039 * @hidden 040 */ 041 private static final HelloModelView INSTANCE = new HelloModelView(); 042 043 /** 044 * Formatter. 045 * @hidden 046 */ 047 private final io.jstach.jstachio.Formatter formatter; 048 049 /** 050 * Escaper. 051 * @hidden 052 */ 053 private final io.jstach.jstachio.Escaper escaper; 054 055 /** 056 * Renderer constructor for manual wiring. 057 * @param formatter formatter if null the static formatter will be used. 058 * @param escaper escaper if null the static escaper will be used 059 */ 060 public HelloModelView( 061 /* @Nullable */ java.util.function.Function< /* @Nullable */ Object, String> formatter, 062 /* @Nullable */ java.util.function.Function<String, String> escaper) { 063 super(); 064 this.formatter = __formatter(formatter); 065 this.escaper = __escaper(escaper); 066 } 067 068 private static io.jstach.jstachio.Formatter __formatter(/* @Nullable */ java.util.function.Function< /* @Nullable */ Object, String> formatter) { 069 return io.jstach.jstachio.Formatter.of(formatter != null ? formatter : io.jstach.jstachio.formatters.DefaultFormatter.provider()); 070 } 071 072 private static io.jstach.jstachio.Escaper __escaper(/* @Nullable */ java.util.function.Function<String, String> escaper) { 073 return io.jstach.jstachio.Escaper.of(escaper != null ? escaper : io.jstach.jstachio.escapers.Html.provider()); 074 } 075 076 /** 077 * Renderer constructor for reflection (use of() instead). 078 * For programmatic consider using {@link #of()} for a shared singleton. 079 */ 080 public HelloModelView() { 081 this(null, null); 082 } 083 084 @Override 085 public void execute(io.jstach.opt.spring.example.hello.HelloModel model, Appendable a) throws java.io.IOException { 086 execute(model, a, templateFormatter(), templateEscaper()); 087 } 088 089 @Override 090 public void execute( 091 io.jstach.opt.spring.example.hello.HelloModel model, 092 java.lang.Appendable a, 093 io.jstach.jstachio.Formatter formatter, 094 io.jstach.jstachio.Escaper escaper) throws java.io.IOException { 095 render(model, a, formatter, escaper, templateAppender()); 096 } 097 098 @Override 099 public boolean supportsType(Class<?> type) { 100 return MODEL_CLASS.isAssignableFrom(type); 101 } 102 103 /** 104 * Needed for jstachio runtime. 105 * @hidden 106 */ 107 @Override 108 public java.util.List<io.jstach.jstachio.Template<?>> provideTemplates(io.jstach.jstachio.TemplateConfig templateConfig ) { 109 return java.util.List.of(io.jstach.jstachio.TemplateConfig.empty() == templateConfig ? INSTANCE : new HelloModelView(templateConfig)); 110 } 111 112 @Override 113 public String templatePath() { 114 return TEMPLATE_PATH; 115 } 116 @Override 117 public String templateName() { 118 return TEMPLATE_NAME; 119 } 120 @Override 121 public String templateString() { 122 return TEMPLATE_STRING; 123 } 124 @Override 125 public Class<?> templateContentType() { 126 return io.jstach.jstachio.escapers.Html.class; 127 } 128 @Override 129 public io.jstach.jstachio.Escaper templateEscaper() { 130 return this.escaper; 131 } 132 133 @Override 134 public io.jstach.jstachio.Formatter templateFormatter() { 135 return this.formatter; 136 } 137 138 /** 139 * Appender. 140 * @return appender for writing unescaped variables. 141 */ 142 public io.jstach.jstachio.Appender<java.lang.Appendable> templateAppender() { 143 return io.jstach.jstachio.Appender.defaultAppender(); 144 } 145 146 /** 147 * Model class. 148 * @return class used as model (annotated with JStache). 149 */ 150 @Override 151 public Class<?> modelClass() { 152 return MODEL_CLASS; 153 } 154 155 /** 156 * Needed for jstachio runtime. 157 * @hidden 158 */ 159 @SuppressWarnings("unchecked") 160 @Override 161 public void process(Object model, Appendable appendable) throws java.io.IOException { 162 execute( (io.jstach.opt.spring.example.hello.HelloModel) model, appendable); 163 } 164 165 /** 166 * Needed for jstachio runtime. 167 * @hidden 168 */ 169 @Override 170 public boolean isBroken(Object model) { 171 return !supportsType(model.getClass()); 172 } 173 174 /** 175 * Renderer constructor using config. 176 * @param templateConfig config that has collaborators 177 */ 178 public HelloModelView(io.jstach.jstachio.TemplateConfig templateConfig) { 179 this(templateConfig.formatter(), templateConfig.escaper()); 180 } 181 182 /** 183 * Convience static factory that will reuse the same singleton instance. 184 * @return renderer same as calling no-arg constructor but is cached with singleton instance 185 */ 186 public static HelloModelView of() { 187 return INSTANCE; 188 } 189 190 /** 191 * Renders the passed in model. 192 * @param <A> appendable type. 193 * @param data model 194 * @param unescapedWriter appendable to write to. 195 * @param formatter formats variables before they are passed to the escaper. 196 * @param escaper used to write escaped variables. 197 * @param appender used to write unescaped variables. 198 * @throws java.io.IOException if an error occurs while writing to the appendable 199 */ 200 public static <A extends java.lang.Appendable> void render( 201 io.jstach.opt.spring.example.hello.HelloModel data, 202 A unescapedWriter, 203 io.jstach.jstachio.Formatter formatter, 204 io.jstach.jstachio.Appender<? super A> escaper, 205 io.jstach.jstachio.Appender<A> appender) throws java.io.IOException { 206 207 unescapedWriter.append( 208 "<!doctype html>\n" + 209 "<html lang=\"en\">\n" + 210 " <head>\n" + 211 " <meta charset=\"utf-8\">\n" + 212 " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" + 213 " <link rel=\"stylesheet\" href=\"https://unpkg.com/@picocss/pico@latest/css/pico.min.css\">\n" + 214 " <title>Hello, "); 215 216 // variable: message 217 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 218 /* TypeMirror: java.lang.String */ 219 formatter.format(escaper, unescapedWriter, "message", data.message()); 220 221 unescapedWriter.append( 222 "!</title>\n" + 223 " </head>\n" + 224 " <body>\n" + 225 " <main class=\"container\">\n" + 226 " <h1>"); 227 228 // variable: message 229 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 230 /* TypeMirror: java.lang.String */ 231 formatter.format(escaper, unescapedWriter, "message", data.message()); 232 233 unescapedWriter.append( 234 "</h1>\n" + 235 " </main>\n" + 236 " </body>\n" + 237 "</html>"); 238 239 240 } 241}