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

Smart inference of Java type for user tag parameter #913

Open
angelozerr opened this issue Jul 25, 2023 · 6 comments
Open

Smart inference of Java type for user tag parameter #913

angelozerr opened this issue Jul 25, 2023 · 6 comments
Assignees
Labels
enhancement New feature or request qute

Comments

@angelozerr
Copy link
Contributor

Given this user tag src/main/resources/tags/myUser.html:

Login: {user.login}

At this step, we cannot know what is user

Given a Qute template which consumes the user tag

{@org.acme.User userFromJava}
{#myUser user=userFromJava /}

At this step we can inject the org.acme.User Java type inside the myUser.html which will provide completion, validation, hover, defintion,etc

This feature is very important to support for instance https://github.com/FroMage/RivieraDEV-Quarkus/blob/main/src/main/resources/templates/tags/organisers.html

@angelozerr angelozerr added enhancement New feature or request qute labels Jul 25, 2023
@angelozerr angelozerr self-assigned this Jul 25, 2023
@FroMage
Copy link

FroMage commented Jul 26, 2023

Actually, I think the theory is that I should define a Java class to declare the tags parameters, I'm sure I discussed it with @mkouba but I can't find where. Something like:

public class tags {
 @CheckedTemplates
 public static class Templates {
  public static native TemplateInstance myUser(User user);
 }
}

Or was it?

 @CheckedTemplates
public class tags {
 public static native TemplateInstance myUser(User user);
}

I can't recall.

It's been discussed in quarkusio/quarkus#21859 though, as well as default parameter values (added in quarkusio/quarkus#25488). I don't know if we can declare default template parameter values from the Java side, though. Perhaps only when declaring parameters in the template?

@FroMage
Copy link

FroMage commented Jul 26, 2023

Otherwise, we can declare tags/myUser.html as such:

{@model.User user}
Login: {user.login}

@angelozerr
Copy link
Contributor Author

Otherwise, we can declare tags/myUser.html as such:

Indeed it is working. I think it is the best solution, no?

@mkouba
Copy link
Collaborator

mkouba commented Aug 9, 2023

You can both a type-safe template that corresponds to templates/tags/myUser.html or a parameter declaration inside the tag template (e.g. {@org.acme.User user}).

Both

@CheckedTemplates
public class tags {
   static native TemplateInstance myUser(User user);
}

and

@CheckedTemplate(basePath = "tags"
public class Whatever {
   static native TemplateInstance myUser(User user);
}

should work.

Both solutions are equally good.

@FroMage
Copy link

FroMage commented Aug 9, 2023

So I wasn't wrong, yay :)

I didn't find this documented in https://quarkus.io/guides/qute-reference#typesafe_templates though, probably it should, no?

@mkouba
Copy link
Collaborator

mkouba commented Aug 9, 2023

So I wasn't wrong, yay :)

I didn't find this documented in https://quarkus.io/guides/qute-reference#typesafe_templates though, probably it should, no?

Well, tags are regular templates located in a special folder (templates/tags) and a special section is registered each. Otherwise the same rules apply. Of course, we could add a NOTE or something... feel free to send a PR ;-).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request qute
Projects
None yet
Development

No branches or pull requests

3 participants