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