Search in sources :

Example 1 with ReflectionValueResolver

use of io.quarkus.qute.ReflectionValueResolver in project quarkus by quarkusio.

the class QuteErrorPageSetup method generatePage.

String generatePage(Throwable exception) {
    Escaper escaper = Escaper.builder().add('"', "&quot;").add('\'', "&#39;").add('&', "&amp;").add('<', "&lt;").add('>', "&gt;").build();
    Template problemTemplate = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()).addValueResolver(new ValueResolver() {

        public boolean appliesTo(EvalContext context) {
            return context.getName().equals("pad");
        }

        @Override
        public CompletionStage<Object> resolve(EvalContext context) {
            return CompletableFuture.completedFuture(htmlPadRight(context.getBase().toString(), 5));
        }
    }).build().parse(PROBLEM_TEMPLATE);
    TemplateHtmlBuilder builder;
    List<Throwable> problems;
    Throwable[] suppressed = exception.getSuppressed();
    if (suppressed.length == 0) {
        problems = Collections.singletonList(exception);
    } else {
        problems = Arrays.asList(suppressed);
    }
    String problemsFound = "Found " + problems.size() + " Qute problems";
    builder = new TemplateHtmlBuilder("Error restarting Quarkus", problemsFound, problemsFound);
    // Attempt to sort problems by line
    problems.sort(new Comparator<Throwable>() {

        @Override
        public int compare(Throwable t1, Throwable t2) {
            Object o1 = getOrigin(t1);
            Object o2 = getOrigin(t2);
            if (o1 == o2) {
                return 0;
            } else if (o1 == null && o2 != null) {
                return -1;
            } else if (o1 != null && o2 == null) {
                return 1;
            }
            return Integer.compare(getLine(o1), getLine(o2));
        }
    });
    for (ListIterator<Throwable> it = problems.listIterator(); it.hasNext(); ) {
        Throwable problem = it.next();
        builder.append(getProblemInfo(it.previousIndex() + 1, problem, problemTemplate, escaper));
    }
    return builder.toString();
}
Also used : EvalContext(io.quarkus.qute.EvalContext) Template(io.quarkus.qute.Template) ReflectionValueResolver(io.quarkus.qute.ReflectionValueResolver) TemplateHtmlBuilder(io.quarkus.runtime.TemplateHtmlBuilder) ValueResolver(io.quarkus.qute.ValueResolver) ReflectionValueResolver(io.quarkus.qute.ReflectionValueResolver) Escaper(io.quarkus.qute.Escaper) CompletionStage(java.util.concurrent.CompletionStage)

Example 2 with ReflectionValueResolver

use of io.quarkus.qute.ReflectionValueResolver in project quarkus-ls by redhat-developer.

the class TestLiteralQute method main.

public static void main(String[] args) {
    List<Item> items = new ArrayList<>();
    for (int i = 0; i < 5; i++) {
        Item item = new Item(i);
        items.add(item);
        for (int j = 0; j < 7; j++) {
            item.addReview(new Review(j));
        }
    }
    Map<String, Object> data = new HashMap<>();
    data.put("items", items);
    Engine engine = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()).build();
    Template template = engine.parse(convertStreamToString(TestLiteralQute.class.getResourceAsStream("literal.qute")));
    String s = template.data(data).render();
    System.err.println(s);
}
Also used : ReflectionValueResolver(io.quarkus.qute.ReflectionValueResolver) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Engine(io.quarkus.qute.Engine) Template(io.quarkus.qute.Template)

Example 3 with ReflectionValueResolver

use of io.quarkus.qute.ReflectionValueResolver in project quarkus-ls by redhat-developer.

the class TestOrQute method main.

public static void main(String[] args) {
    Map<String, Object> data = new HashMap<>();
    data.put("item", new Item(0));
    Engine engine = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()).build();
    Template template = engine.parse(convertStreamToString(TestOrQute.class.getResourceAsStream("or.qute")));
    String s = template.data(data).render();
    System.err.println(s);
}
Also used : ReflectionValueResolver(io.quarkus.qute.ReflectionValueResolver) HashMap(java.util.HashMap) Engine(io.quarkus.qute.Engine) Template(io.quarkus.qute.Template)

Example 4 with ReflectionValueResolver

use of io.quarkus.qute.ReflectionValueResolver in project quarkus-ls by redhat-developer.

the class TestTemplateExtensionQute method main.

public static void main(String[] args) {
    Map<String, Object> data = new HashMap<>();
    data.put("item", new Item(0));
    Engine engine = Engine.builder().addDefaults().addValueResolver(new ReflectionValueResolver()).build();
    Template template = engine.parse(convertStreamToString(TestTemplateExtensionQute.class.getResourceAsStream("template-extensions.qute.html")));
    String s = template.data(data).render();
    System.err.println(s);
}
Also used : ReflectionValueResolver(io.quarkus.qute.ReflectionValueResolver) HashMap(java.util.HashMap) Engine(io.quarkus.qute.Engine) Template(io.quarkus.qute.Template)

Example 5 with ReflectionValueResolver

use of io.quarkus.qute.ReflectionValueResolver in project camel-quarkus by apache.

the class QuteEndpoint method getQuteEngine.

private synchronized Engine getQuteEngine() {
    if (quteEngine == null) {
        EngineBuilder builder = Engine.builder().addDefaults();
        builder.addValueResolver(ReflectionValueResolver::new);
        builder.addLocator(this::locate);
        quteEngine = builder.build();
    }
    return quteEngine;
}
Also used : ReflectionValueResolver(io.quarkus.qute.ReflectionValueResolver) EngineBuilder(io.quarkus.qute.EngineBuilder)

Aggregations

ReflectionValueResolver (io.quarkus.qute.ReflectionValueResolver)13 Engine (io.quarkus.qute.Engine)11 Template (io.quarkus.qute.Template)11 HashMap (java.util.HashMap)11 ArrayList (java.util.ArrayList)3 EngineBuilder (io.quarkus.qute.EngineBuilder)2 DevConsoleRouteBuildItem (io.quarkus.devconsole.spi.DevConsoleRouteBuildItem)1 Escaper (io.quarkus.qute.Escaper)1 EvalContext (io.quarkus.qute.EvalContext)1 Expression (io.quarkus.qute.Expression)1 HtmlEscaper (io.quarkus.qute.HtmlEscaper)1 RawString (io.quarkus.qute.RawString)1 ResultMapper (io.quarkus.qute.ResultMapper)1 TemplateException (io.quarkus.qute.TemplateException)1 Origin (io.quarkus.qute.TemplateNode.Origin)1 UserTagSectionHelper (io.quarkus.qute.UserTagSectionHelper)1 ValueResolver (io.quarkus.qute.ValueResolver)1 TemplateHtmlBuilder (io.quarkus.runtime.TemplateHtmlBuilder)1 RouteBuildItem (io.quarkus.vertx.http.deployment.RouteBuildItem)1 Map (java.util.Map)1