Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Qute: add some more built-in string extensions #46258

Merged
merged 1 commit into from
Feb 18, 2025

Conversation

mkouba
Copy link
Contributor

@mkouba mkouba commented Feb 13, 2025

  • str:concat, str:join, str:builder, str:eval

@quarkus-bot quarkus-bot bot added area/documentation area/qute The template engine labels Feb 13, 2025
Copy link

github-actions bot commented Feb 13, 2025

🙈 The PR is closed and the preview is expired.

@mkouba mkouba marked this pull request as ready for review February 14, 2025 10:14
@mkouba mkouba requested a review from ia3andy February 14, 2025 10:14

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

Copy link
Contributor

@ia3andy ia3andy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thansk!

- str:concat, str:join, str:builder, str:eval
- also slightly optimize EvalSectionHelper for the cases where a
  template literal with no params is used
@mkouba mkouba added the triage/waiting-for-ci Ready to merge when CI successfully finishes label Feb 17, 2025
Copy link

quarkus-bot bot commented Feb 17, 2025

Status for workflow Quarkus Documentation CI

This is the status report for running Quarkus Documentation CI on commit aae8420.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

Warning

There are other workflow runs running, you probably need to wait for their status before merging.

This comment has been minimized.

Copy link

quarkus-bot bot commented Feb 18, 2025

Status for workflow Quarkus CI

This is the status report for running Quarkus CI on commit aae8420.

✅ The latest workflow run for the pull request has completed successfully.

It should be safe to merge provided you have a look at the other checks in the summary.

You can consult the Develocity build scans.

@mkouba mkouba merged commit be7e613 into quarkusio:main Feb 18, 2025
59 checks passed
@quarkus-bot quarkus-bot bot removed the triage/waiting-for-ci Ready to merge when CI successfully finishes label Feb 18, 2025
@quarkus-bot quarkus-bot bot added this to the 3.21 - main milestone Feb 18, 2025
@gsmet gsmet modified the milestones: 3.21 - main, 3.19.0 Feb 18, 2025
@gbourant
Copy link

I think that eval is implemented but not used in StringTemplateExtensions.java class. Sorry for commenting on a closed one :)

@mkouba
Copy link
Contributor Author

mkouba commented Feb 27, 2025

I think that eval is implemented but not used in StringTemplateExtensions.java class. Sorry for commenting on a closed one :)

Indeed, it has to be implemented as a NamespaceResolver: https://github.com/quarkusio/quarkus/blob/main/independent-projects/qute/core/src/main/java/io/quarkus/qute/StrEvalNamespaceResolver.java

But from user POV it's kind of a "string extension" ;-).

@gbourant
Copy link

Is this a bug? I'm confused. When I use {str:eval('Hello')} in my Qute template I get {str:eval('Hello')}: No matching namespace [str] extension. The other goodies (str:concat, str:join, str:builder) you have added are working fine.

@mkouba
Copy link
Contributor Author

mkouba commented Feb 27, 2025

Is this a bug? I'm confused. When I use {str:eval('Hello')} in my Qute template I get {str:eval('Hello')}: No matching namespace [str] extension. The other goodies (str:concat, str:join, str:builder) you have added are working fine.

That's weird. This namespace resolver was also added in this PR. Could you share a sample of your app that would demonstrate the problem? What does the stack trace look like?

@gbourant
Copy link

This is the error that I get. Check the reproducer here

Caused by: io.quarkus.qute.TemplateException: Found incorrect expressions (1):
	[1] root.html:19:1 - {str:eval('Hello')}: No matching namespace [str] extension method found

	at io.quarkus.qute.deployment.QuteProcessor.processTemplateErrors(QuteProcessor.java:272)
	at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:733)
	at io.quarkus.deployment.ExtensionLoader$3.execute(ExtensionLoader.java:856)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:255)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.doRunWith(EnhancedQueueExecutor.java:2675)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2654)
	at org.jboss.threads.EnhancedQueueExecutor.runThreadBody(EnhancedQueueExecutor.java:1627)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1594)
	at java.base/java.lang.Thread.run(Thread.java:1583)
	at org.jboss.threads.JBossThread.run(JBossThread.java:499)
	Suppressed: io.quarkus.qute.TemplateException: root.html:19:1 - {str:eval('Hello')}: No matching namespace [str] extension method found
		at io.quarkus.qute.TemplateException$Builder.build(TemplateException.java:169)
		at io.quarkus.qute.deployment.QuteProcessor.processTemplateErrors(QuteProcessor.java:237)
		... 10 more

@mkouba
Copy link
Contributor Author

mkouba commented Feb 27, 2025

Ok, so it's the build-time validation failure. Maybe we don't have a test for this. I'll take a look. Thanks for the report!

@mkouba
Copy link
Contributor Author

mkouba commented Feb 28, 2025

@gbourant You're absolutely right, we do fail the build if there's at least one template extension method for a namespace (str:) and no matching extension method is found during validation. This assumption is incorrect and we should just ignore the relevant expression. I'll send a follow-up PR.

A workaround exists, just add the following dummy template extension method - it will be never used but tricks the validation:

@TemplateExtension(namespace = "str", matchName = "eval", priority = Integer.MIN_VALUE)
static String dummy(String template) {
   throw new UnsupportedOperationException();
}

mkouba added a commit to mkouba/quarkus that referenced this pull request Feb 28, 2025
- when a matching template extension method exists
- this is a follow-up of quarkusio#46258
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants