Search in sources :

Example 16 with PebbleTemplate

use of com.mitchellbosecke.pebble.template.PebbleTemplate in project symja_android_library by axkr.

the class Histogram2DTrace method asJavascript.

@Override
public String asJavascript(int i) {
    Writer writer = new StringWriter();
    PebbleTemplate compiledTemplate;
    try {
        compiledTemplate = engine.getTemplate("trace_template.html");
        compiledTemplate.evaluate(writer, getContext(i));
    } catch (PebbleException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return writer.toString();
}
Also used : PebbleException(com.mitchellbosecke.pebble.error.PebbleException) StringWriter(java.io.StringWriter) PebbleTemplate(com.mitchellbosecke.pebble.template.PebbleTemplate) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 17 with PebbleTemplate

use of com.mitchellbosecke.pebble.template.PebbleTemplate in project symja_android_library by axkr.

the class PieTrace method asJavascript.

@Override
public String asJavascript(int i) {
    Writer writer = new StringWriter();
    PebbleTemplate compiledTemplate;
    try {
        compiledTemplate = engine.getTemplate("pie_trace_template.html");
        compiledTemplate.evaluate(writer, getContext(i));
    } catch (PebbleException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return writer.toString();
}
Also used : PebbleException(com.mitchellbosecke.pebble.error.PebbleException) StringWriter(java.io.StringWriter) PebbleTemplate(com.mitchellbosecke.pebble.template.PebbleTemplate) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 18 with PebbleTemplate

use of com.mitchellbosecke.pebble.template.PebbleTemplate in project symja_android_library by axkr.

the class Figure method asJavascript.

public String asJavascript(String divName) {
    Writer writer = new StringWriter();
    PebbleTemplate compiledTemplate;
    buildContext(divName);
    try {
        compiledTemplate = engine.getTemplate("figure_template.html");
        compiledTemplate.evaluate(writer, getContext());
    } catch (PebbleException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return writer.toString();
}
Also used : PebbleException(com.mitchellbosecke.pebble.error.PebbleException) StringWriter(java.io.StringWriter) PebbleTemplate(com.mitchellbosecke.pebble.template.PebbleTemplate) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 19 with PebbleTemplate

use of com.mitchellbosecke.pebble.template.PebbleTemplate in project symja_android_library by axkr.

the class HeatmapTrace method asJavascript.

@Override
public String asJavascript(int i) {
    Writer writer = new StringWriter();
    PebbleTemplate compiledTemplate;
    try {
        compiledTemplate = engine.getTemplate("trace_template.html");
        compiledTemplate.evaluate(writer, getContext());
    } catch (PebbleException e) {
        throw new IllegalStateException(e);
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return writer.toString();
}
Also used : PebbleException(com.mitchellbosecke.pebble.error.PebbleException) StringWriter(java.io.StringWriter) PebbleTemplate(com.mitchellbosecke.pebble.template.PebbleTemplate) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Example 20 with PebbleTemplate

use of com.mitchellbosecke.pebble.template.PebbleTemplate in project symja_android_library by axkr.

the class IOFunctions method templateApply.

/**
 * Render the template with the assigned context variable strings.
 *
 * @param templateString the template which should be rendered
 * @param outputWriter use {@link Writer#toString()} to get the rendered result
 * @param context the assigned variables which should be rendered in the template
 * @throws IOException
 */
private static void templateApply(String templateString, Writer outputWriter, Map<String, Object> context) throws IOException {
    PebbleCache<Object, PebbleTemplate> cache = PEBBLE_ENGINE.getTemplateCache();
    PebbleTemplate template = cache.computeIfAbsent(templateString, x -> templateCompile(templateString));
    template.evaluate(outputWriter, context);
}
Also used : PebbleTemplate(com.mitchellbosecke.pebble.template.PebbleTemplate)

Aggregations

PebbleTemplate (com.mitchellbosecke.pebble.template.PebbleTemplate)20 StringWriter (java.io.StringWriter)19 Writer (java.io.Writer)17 PebbleException (com.mitchellbosecke.pebble.error.PebbleException)15 IOException (java.io.IOException)15 UncheckedIOException (java.io.UncheckedIOException)15 HashMap (java.util.HashMap)2 Utils.dataAsString (tech.tablesaw.plotly.Utils.dataAsString)2 PebbleEngine (com.mitchellbosecke.pebble.PebbleEngine)1 LanguageHeader (io.vertx.ext.web.LanguageHeader)1 Locale (java.util.Locale)1 Map (java.util.Map)1