Skip to content

Commit

Permalink
Make templates adjust with scala version
Browse files Browse the repository at this point in the history
  • Loading branch information
ia3andy committed May 2, 2022
1 parent 82e0259 commit 1e160d4
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,12 @@
<arg>-deprecation</arg>
<arg>-feature</arg>
<arg>-explaintypes</arg>
{#if scala.version.startsWith("2.12")}
<arg>-target:jvm-1.8</arg>
<arg>-Ypartial-unification</arg>
{#else}
<arg>-target:jvm-11</arg>
{/if}
</args>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,13 @@
import io.quarkus.devtools.codestarts.CodestartException;
import io.quarkus.devtools.codestarts.CodestartResource;
import io.quarkus.devtools.codestarts.CodestartResource.Source;
import io.quarkus.qute.Engine;
import io.quarkus.qute.Expression;
import io.quarkus.qute.ResultMapper;
import io.quarkus.qute.Results;
import io.quarkus.qute.TemplateException;
import io.quarkus.qute.TemplateLocator;
import io.quarkus.qute.TemplateNode;
import io.quarkus.qute.Variant;
import io.quarkus.qute.*;
import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletionStage;
import org.apache.commons.io.FilenameUtils;

final class QuteCodestartFileReader implements CodestartFileReader {
Expand Down Expand Up @@ -49,6 +43,7 @@ public static String readQuteFile(CodestartResource projectResource, Source sour
final String content = source.read();
final String templateId = source.absolutePath();
final Engine engine = Engine.builder().addDefaults()
.addValueResolver(new StringValueResolver())
.addResultMapper(new MissingValueMapper())
.removeStandaloneLines(true)
// For now we need to disable strict rendering for codestarts
Expand Down Expand Up @@ -142,4 +137,38 @@ public String map(Object result, Expression expression) {
* }
* }
**/

private static class StringValueResolver implements ValueResolver {
@Override
public boolean appliesTo(EvalContext context) {
return ValueResolver.matchClass(context, String.class);
}

@Override
public CompletionStage<Object> resolve(EvalContext context) {
String value = (String) context.getBase();
switch (context.getName()) {
case "startsWith":
if (context.getParams().size() == 1) {
return context.evaluate(context.getParams().get(0)).thenCompose(e -> {
return CompletedStage.of(value.startsWith((String) e));
});
}
case "contains":
if (context.getParams().size() == 1) {
return context.evaluate(context.getParams().get(0)).thenCompose(e -> {
return CompletedStage.of(value.contains((CharSequence) e));
});
}
case "endsWith":
if (context.getParams().size() == 1) {
return context.evaluate(context.getParams().get(0)).thenCompose(e -> {
return CompletedStage.of(value.endsWith((String) e));
});
}
default:
return Results.notFound(context);
}
}
}
}

0 comments on commit 1e160d4

Please sign in to comment.