Search in sources :

Example 6 with PebbleException

use of com.mitchellbosecke.pebble.error.PebbleException in project symja_android_library by axkr.

the class BoxTrace 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 7 with PebbleException

use of com.mitchellbosecke.pebble.error.PebbleException in project symja_android_library by axkr.

the class HistogramTrace 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 8 with PebbleException

use of com.mitchellbosecke.pebble.error.PebbleException in project symja_android_library by axkr.

the class Component method asJavascript.

protected String asJavascript(String filename) {
    Writer writer = new StringWriter();
    PebbleTemplate compiledTemplate;
    try {
        compiledTemplate = getEngine().getTemplate(filename);
        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 9 with PebbleException

use of com.mitchellbosecke.pebble.error.PebbleException in project symja_android_library by axkr.

the class Layout method asJavascript.

public String asJavascript() {
    Writer writer = new StringWriter();
    PebbleTemplate compiledTemplate;
    try {
        compiledTemplate = engine.getTemplate("layout_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 10 with PebbleException

use of com.mitchellbosecke.pebble.error.PebbleException in project Orchid by JavaEden.

the class PebbleCompiler method compile.

@Override
public void compile(OutputStream os, @Nullable OrchidResource resource, String extension, String input, Map<String, Object> data) {
    try {
        PebbleTemplateLoader loader = new PebbleTemplateLoader(contextProvider.get(), contextProvider.get().getTheme());
        PebbleEngine engine = new PebbleEngine.Builder().loader(loader).executorService(executor).extension(extensionArray).methodAccessValidator(new NoOpMethodAccessValidator()).newLineTrimming(false).tagCache(tagCache).templateCache(templateCache).build();
        engine.getExtensionRegistry().getAttributeResolver().add(new GetMethodAttributeResolver());
        LexerImpl lexer = new LexerImpl(engine.getSyntax(), engine.getExtensionRegistry().getUnaryOperators().values(), engine.getExtensionRegistry().getBinaryOperators().values());
        TokenStream tokenStream = lexer.tokenize(new StringReader(input), "");
        Parser parser = new ParserImpl(engine.getExtensionRegistry().getUnaryOperators(), engine.getExtensionRegistry().getBinaryOperators(), engine.getExtensionRegistry().getTokenParsers(), new ParserOptions());
        RootNode root = parser.parse(tokenStream);
        PebbleTemplateImpl compiledTemplate = new PebbleTemplateImpl(engine, root, "");
        for (NodeVisitorFactory visitorFactory : engine.getExtensionRegistry().getNodeVisitors()) {
            visitorFactory.createVisitor(compiledTemplate).visit(root);
        }
        ByteArrayOutputStream os1 = new ByteArrayOutputStream();
        Writer writer = new OutputStreamWriter(os1, StandardCharsets.UTF_8);
        compiledTemplate.evaluate(writer, data);
        writer.close();
        os.write(os1.toByteArray());
    } catch (PebbleException e) {
        OrchidExtensionsKt.logSyntaxError(input, extension, e.getLineNumber(), 0, e.getMessage(), e.getCause());
    } catch (Exception e) {
        Clog.e("Error rendering Pebble template (see template source below)", e);
        Clog.e(input);
        contextProvider.get().diagnosisMessage(() -> ExceptionUtils.getStackTrace(e));
    }
}
Also used : RootNode(com.mitchellbosecke.pebble.node.RootNode) TokenStream(com.mitchellbosecke.pebble.lexer.TokenStream) NodeVisitorFactory(com.mitchellbosecke.pebble.extension.NodeVisitorFactory) ParserOptions(com.mitchellbosecke.pebble.parser.ParserOptions) PebbleTemplateImpl(com.mitchellbosecke.pebble.template.PebbleTemplateImpl) NoOpMethodAccessValidator(com.mitchellbosecke.pebble.attributes.methodaccess.NoOpMethodAccessValidator) ParserImpl(com.mitchellbosecke.pebble.parser.ParserImpl) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PebbleException(com.mitchellbosecke.pebble.error.PebbleException) PebbleEngine(com.mitchellbosecke.pebble.PebbleEngine) Parser(com.mitchellbosecke.pebble.parser.Parser) PebbleException(com.mitchellbosecke.pebble.error.PebbleException) StringReader(java.io.StringReader) LexerImpl(com.mitchellbosecke.pebble.lexer.LexerImpl) OutputStreamWriter(java.io.OutputStreamWriter) OutputStreamWriter(java.io.OutputStreamWriter) StringWriter(java.io.StringWriter) Writer(java.io.Writer)

Aggregations

PebbleException (com.mitchellbosecke.pebble.error.PebbleException)17 StringWriter (java.io.StringWriter)16 Writer (java.io.Writer)16 PebbleTemplate (com.mitchellbosecke.pebble.template.PebbleTemplate)15 IOException (java.io.IOException)15 UncheckedIOException (java.io.UncheckedIOException)15 PebbleEngine (com.mitchellbosecke.pebble.PebbleEngine)2 Utils.dataAsString (tech.tablesaw.plotly.Utils.dataAsString)2 NoOpMethodAccessValidator (com.mitchellbosecke.pebble.attributes.methodaccess.NoOpMethodAccessValidator)1 NodeVisitorFactory (com.mitchellbosecke.pebble.extension.NodeVisitorFactory)1 LexerImpl (com.mitchellbosecke.pebble.lexer.LexerImpl)1 TokenStream (com.mitchellbosecke.pebble.lexer.TokenStream)1 ClasspathLoader (com.mitchellbosecke.pebble.loader.ClasspathLoader)1 DelegatingLoader (com.mitchellbosecke.pebble.loader.DelegatingLoader)1 FileLoader (com.mitchellbosecke.pebble.loader.FileLoader)1 Loader (com.mitchellbosecke.pebble.loader.Loader)1 RootNode (com.mitchellbosecke.pebble.node.RootNode)1 Parser (com.mitchellbosecke.pebble.parser.Parser)1 ParserImpl (com.mitchellbosecke.pebble.parser.ParserImpl)1 ParserOptions (com.mitchellbosecke.pebble.parser.ParserOptions)1