Skip to content

Commit

Permalink
Qute: add SectionResolutionContext.evaluate()
Browse files Browse the repository at this point in the history
  • Loading branch information
mkouba committed Jun 13, 2023
1 parent 197c921 commit 4a768af
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.qute;

import static io.quarkus.qute.Futures.evaluateParams;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand All @@ -26,7 +24,7 @@ public EvalSectionHelper(Map<String, Expression> parameters, Engine engine) {
@Override
public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
CompletableFuture<ResultNode> result = new CompletableFuture<>();
evaluateParams(parameters, context.resolutionContext()).whenComplete((evaluatedParams, t1) -> {
context.evaluate(parameters).whenComplete((evaluatedParams, t1) -> {
if (t1 != null) {
result.completeExceptionally(t1);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.qute;

import static io.quarkus.qute.Futures.evaluateParams;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -51,7 +49,7 @@ public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
return root.resolve(resolutionContext, t.isFragment() ? FRAGMENT_PARAMS : null);
} else {
CompletableFuture<ResultNode> result = new CompletableFuture<>();
evaluateParams(parameters, context.resolutionContext()).whenComplete((evaluatedParams, t1) -> {
context.evaluate(parameters).whenComplete((evaluatedParams, t1) -> {
if (t1 != null) {
result.completeExceptionally(t1);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ public interface SectionHelper {
*/
public interface SectionResolutionContext {

/**
* Evaluates the given expressions and returns the map of expression keys to evaluated values.
*
* @param expressions
* @return the map of expression keys to evaluated values
*/
CompletionStage<Map<String, Object>> evaluate(Map<String, Expression> expressions);

/**
*
* @return the current resolution context
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ public SectionResolutionContextImpl(ResolutionContext resolutionContext, Map<Str
this.params = params;
}

@Override
public CompletionStage<Map<String, Object>> evaluate(Map<String, Expression> parameters) {
return Futures.evaluateParams(parameters, resolutionContext);
}

@Override
public CompletionStage<ResultNode> execute(SectionBlock block, ResolutionContext context) {
if (block == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package io.quarkus.qute;

import static io.quarkus.qute.Futures.evaluateParams;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -41,7 +39,7 @@ public class SetSectionHelper implements SectionHelper {
public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
CompletableFuture<ResultNode> result = new CompletableFuture<>();
if (defaultKeys.isEmpty()) {
evaluateParams(parameters, context.resolutionContext()).whenComplete((r, t) -> {
context.evaluate(parameters).whenComplete((r, t) -> {
if (t != null) {
result.completeExceptionally(t);
} else {
Expand All @@ -57,7 +55,7 @@ public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
});
} else {
// First evaluate the keys
evaluateParams(defaultKeys, context.resolutionContext()).whenComplete((r, t) -> {
context.evaluate(defaultKeys).whenComplete((r, t) -> {
if (t != null) {
result.completeExceptionally(t);
} else {
Expand All @@ -80,7 +78,7 @@ public CompletionStage<ResultNode> resolve(SectionResolutionContext context) {
});
} else {
// Evaluate the default values
evaluateParams(toEval, context.resolutionContext()).whenComplete((r2, t2) -> {
context.evaluate(toEval).whenComplete((r2, t2) -> {
if (t2 != null) {
result.completeExceptionally(t2);
} else {
Expand Down

0 comments on commit 4a768af

Please sign in to comment.