001package io.jstach.opt.spring.webflux.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.EncodedTemplate<io.jstach.opt.spring.webflux.example.hello.HelloModel>, 009 io.jstach.jstachio.spi.TemplateProvider, 010 io.jstach.jstachio.spi.JStachioFilter.FilterChain { 011 /** 012 * Template path. 013 * @hidden 014 */ 015 public static final String TEMPLATE_PATH = "views/hello.mustache"; 016 017 /** 018 * Inline template string copied. 019 * @hidden 020 */ 021 022 public static final String TEMPLATE_STRING = ""; 023 024 /** 025 * Template name. Do not rely on this. 026 * @hidden 027 */ 028 public static final String TEMPLATE_NAME = "io.jstach.opt.spring.webflux.example.hello.HelloModelView"; 029 030 /** 031 * Template charset. 032 * @hidden 033 */ 034 public static final java.nio.charset.Charset TEMPLATE_CHARSET = java.nio.charset.StandardCharsets.UTF_8; 035 036 /** 037 * Template mediaType. 038 * @hidden 039 */ 040 public static final String TEMPLATE_MEDIA_TYPE = "text/html"; 041 042 /** 043 * The models class. Use {@link #modelClass()} instead. 044 * @hidden 045 */ 046 public static final Class<?> MODEL_CLASS = io.jstach.opt.spring.webflux.example.hello.HelloModel.class; 047 048 /** 049 * The instance. Use {@link {@link #of()} instead. 050 * @hidden 051 */ 052 private static final HelloModelView INSTANCE = new HelloModelView(); 053 054 /** 055 * Formatter. 056 * @hidden 057 */ 058 private final io.jstach.jstachio.Formatter formatter; 059 060 /** 061 * Escaper. 062 * @hidden 063 */ 064 private final io.jstach.jstachio.Escaper escaper; 065 066 /** 067 * Renderer constructor for manual wiring. 068 * @param formatter formatter if null the static formatter will be used. 069 * @param escaper escaper if null the static escaper will be used 070 */ 071 public HelloModelView( 072 java.util.function./* @Nullable */ Function</* @Nullable */ Object, String> formatter, 073 java.util.function./* @Nullable */ Function<String, String> escaper) { 074 super(); 075 this.formatter = __formatter(formatter); 076 this.escaper = __escaper(escaper); 077 } 078 079 private static io.jstach.jstachio.Formatter __formatter(java.util.function./* @Nullable */ Function</* @Nullable */ Object, String> formatter) { 080 return io.jstach.jstachio.Formatter.of(formatter != null ? formatter : io.jstach.jstachio.formatters.DefaultFormatter.provider()); 081 } 082 083 private static io.jstach.jstachio.Escaper __escaper(java.util.function./* @Nullable */ Function<String, String> escaper) { 084 return io.jstach.jstachio.Escaper.of(escaper != null ? escaper : io.jstach.jstachio.escapers.Html.provider()); 085 } 086 087 /** 088 * Renderer constructor for reflection (use of() instead). 089 * For programmatic consider using {@link #of()} for a shared singleton. 090 */ 091 public HelloModelView() { 092 this(null, null); 093 } 094 095 @Override 096 public StringBuilder execute(io.jstach.opt.spring.webflux.example.hello.HelloModel model, StringBuilder sb) { 097 render(model, io.jstach.jstachio.Output.of(sb), this.formatter, this.escaper, templateAppender()); 098 return sb; 099 } 100 101 @Override 102 public <A extends io.jstach.jstachio.Output<E>, E extends Exception> A execute( 103 io.jstach.opt.spring.webflux.example.hello.HelloModel model, 104 A a) throws E { 105 render(model, a, this.formatter, this.escaper, templateAppender()); 106 return a; 107 } 108 109 /** 110 * Renders the passed in model. 111 * @param <A> appendable type. 112 * @param <E> error type. 113 * @param model a model assumed never to be <code>null</code>. 114 * @param a appendable to write to. 115 * @param formatter formats variables before they are passed to the escaper 116 * @param escaper used to write escaped variables 117 * @throws E if an error occurs while writing to the appendable 118 */ 119 protected <A extends io.jstach.jstachio.Output<E>, E extends Exception> void execute( 120 io.jstach.opt.spring.webflux.example.hello.HelloModel model, 121 A a, 122 io.jstach.jstachio.Formatter formatter, 123 io.jstach.jstachio.Escaper escaper) throws E { 124 render(model, a, formatter, escaper, templateAppender()); 125 } 126 127 @Override 128 public <A extends io.jstach.jstachio.Output.EncodedOutput<E>, E extends Exception> A write( 129 io.jstach.opt.spring.webflux.example.hello.HelloModel model, 130 A outputStream) throws E { 131 encode(model, outputStream, this.formatter, this.escaper, templateAppender()); 132 return outputStream; 133 } 134 135 @Override 136 public boolean supportsType(Class<?> type) { 137 return MODEL_CLASS.isAssignableFrom(type); 138 } 139 140 /** 141 * Needed for jstachio runtime. 142 * @hidden 143 */ 144 @Override 145 public java.util.List<io.jstach.jstachio.Template<?>> provideTemplates(io.jstach.jstachio.TemplateConfig templateConfig ) { 146 return java.util.List.of(io.jstach.jstachio.TemplateConfig.empty() == templateConfig ? INSTANCE : new HelloModelView(templateConfig)); 147 } 148 149 @Override 150 public String templatePath() { 151 return TEMPLATE_PATH; 152 } 153 @Override 154 public String templateName() { 155 return TEMPLATE_NAME; 156 } 157 @Override 158 public java.nio.charset.Charset templateCharset() { 159 return TEMPLATE_CHARSET; 160 } 161 @Override 162 public String templateMediaType() { 163 return TEMPLATE_MEDIA_TYPE; 164 } 165 @Override 166 public String templateString() { 167 return TEMPLATE_STRING; 168 } 169 @Override 170 public Class<?> templateContentType() { 171 return io.jstach.jstachio.escapers.Html.class; 172 } 173 @Override 174 public io.jstach.jstachio.Escaper templateEscaper() { 175 return this.escaper; 176 } 177 178 @Override 179 public io.jstach.jstachio.Formatter templateFormatter() { 180 return this.formatter; 181 } 182 183 /** 184 * Appender. 185 * @return appender for writing unescaped variables. 186 */ 187 public io.jstach.jstachio.Appender templateAppender() { 188 return io.jstach.jstachio.Appender.defaultAppender(); 189 } 190 191 /** 192 * Model class. 193 * @return class used as model (annotated with JStache). 194 */ 195 @Override 196 public Class<?> modelClass() { 197 return MODEL_CLASS; 198 } 199 200 /** 201 * Needed for jstachio runtime. 202 * @hidden 203 */ 204 @Override 205 public void process(Object model, Appendable appendable) throws java.io.IOException { 206 execute( (io.jstach.opt.spring.webflux.example.hello.HelloModel) model, appendable); 207 } 208 209 /** 210 * Needed for jstachio runtime. 211 * @hidden 212 */ 213 @Override 214 public boolean isBroken(Object model) { 215 return !supportsType(model.getClass()); 216 } 217 218 /** 219 * Renderer constructor using config. 220 * @param templateConfig config that has collaborators 221 */ 222 public HelloModelView(io.jstach.jstachio.TemplateConfig templateConfig) { 223 this(templateConfig.formatter(), templateConfig.escaper()); 224 } 225 226 /** 227 * Convience static factory that will reuse the same singleton instance. 228 * @return renderer same as calling no-arg constructor but is cached with singleton instance 229 */ 230 public static HelloModelView of() { 231 return INSTANCE; 232 } 233 234 /** 235 * Renders the passed in model. 236 * @param <A> appendable type. 237 * @param <E> error type. 238 * @param data model 239 * @param unescapedWriter appendable to write to. 240 * @param formatter formats variables before they are passed to the escaper. 241 * @param escaper used to write escaped variables. 242 * @param appender used to write unescaped variables. 243 * @throws E if an error occurs while writing to the appendable 244 */ 245 public static <A extends io.jstach.jstachio.Output<E>, E extends Exception> void render( 246 io.jstach.opt.spring.webflux.example.hello.HelloModel data, 247 A unescapedWriter, 248 io.jstach.jstachio.Formatter formatter, 249 io.jstach.jstachio.Appender escaper, 250 io.jstach.jstachio.Appender appender) throws E { 251 252 unescapedWriter.append( 253 "<!doctype html>\n" + 254 "<html lang=\"en\">\n" + 255 " <head>\n" + 256 " <meta charset=\"utf-8\">\n" + 257 " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" + 258 " <link rel=\"stylesheet\" href=\"https://unpkg.com/@picocss/pico@latest/css/pico.min.css\">\n" + 259 " <title>Hello, "); 260 261 // variable: message 262 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 263 /* TypeMirror: java.lang.String */ 264 formatter.format(escaper, unescapedWriter, "message", data.message()); 265 266 unescapedWriter.append( 267 "!</title>\n" + 268 " </head>\n" + 269 " <body>\n" + 270 " <main class=\"container\">\n" + 271 " <h1>"); 272 273 // variable: message 274 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 275 /* TypeMirror: java.lang.String */ 276 formatter.format(escaper, unescapedWriter, "message", data.message()); 277 278 unescapedWriter.append( 279 "</h1>\n" + 280 " </main>\n" + 281 " </body>\n" + 282 "</html>"); 283 284 285 } 286 287 /** 288 * Renders to an OutputStream use pre-encoded parts of the template. 289 * @param <A> output type. 290 * @param <E> error type. 291 * @param data model 292 * @param unescapedWriter stream to write to. 293 * @param formatter formats variables before they are passed to the escaper. 294 * @param escaper used to write escaped variables. 295 * @param appender used to write unescaped variables. 296 * @throws E if an error occurs while writing to the appendable 297 */ 298 protected static <A extends io.jstach.jstachio.Output.EncodedOutput<E>, E extends Exception> void encode( 299 io.jstach.opt.spring.webflux.example.hello.HelloModel data, 300 A unescapedWriter, 301 io.jstach.jstachio.Formatter formatter, 302 io.jstach.jstachio.Escaper escaper, 303 io.jstach.jstachio.Appender appender) throws E { 304 305 unescapedWriter.write(TEXT_0); 306 307 // variable: message 308 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 309 /* TypeMirror: java.lang.String */ 310 formatter.format(escaper, unescapedWriter, "message", data.message()); 311 312 unescapedWriter.write(TEXT_1); 313 314 // variable: message 315 /* RenderingContext: class io.jstach.apt.internal.context.DeclaredTypeRenderingContext */ 316 /* TypeMirror: java.lang.String */ 317 formatter.format(escaper, unescapedWriter, "message", data.message()); 318 319 unescapedWriter.write(TEXT_2); 320 321 322 } 323 private static final byte[] TEXT_0 = ( 324 "<!doctype html>\n" + 325 "<html lang=\"en\">\n" + 326 " <head>\n" + 327 " <meta charset=\"utf-8\">\n" + 328 " <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">\n" + 329 " <link rel=\"stylesheet\" href=\"https://unpkg.com/@picocss/pico@latest/css/pico.min.css\">\n" + 330 " <title>Hello, ").getBytes(TEMPLATE_CHARSET); 331 private static final byte[] TEXT_1 = ( 332 "!</title>\n" + 333 " </head>\n" + 334 " <body>\n" + 335 " <main class=\"container\">\n" + 336 " <h1>").getBytes(TEMPLATE_CHARSET); 337 private static final byte[] TEXT_2 = ( 338 "</h1>\n" + 339 " </main>\n" + 340 " </body>\n" + 341 "</html>").getBytes(TEMPLATE_CHARSET); 342}