Skip to content

Commit

Permalink
Add documentation for vertx and qute integration
Browse files Browse the repository at this point in the history
  • Loading branch information
mcruzdev committed Aug 14, 2024
1 parent 1466fcc commit 12eecc5
Showing 1 changed file with 73 additions and 0 deletions.
73 changes: 73 additions & 0 deletions docs/src/main/asciidoc/qute-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2650,6 +2650,79 @@ class DetailResource {

WARNING: Unlike with `@Inject` the templates obtained via `RestTemplate` are not validated, i.e. the build does not fail if a template does not exist.

[[vertx_integration]]
=== Vert.x Integration

If you want to use `io.vertx.core.json.JsonObject` as data in your templates, then you will need to add the `quarkus-vertx` extension to your build file if not already part of your dependencies (most applications use this extension by default).

Check warning on line 2656 in docs/src/main/asciidoc/qute-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/qute-reference.adoc", "range": {"start": {"line": 2656, "column": 52}}}, "severity": "INFO"}

Check warning on line 2656 in docs/src/main/asciidoc/qute-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'. Raw Output: {"message": "[Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'.", "location": {"path": "docs/src/main/asciidoc/qute-reference.adoc", "range": {"start": {"line": 2656, "column": 93}}}, "severity": "INFO"}


[source,xml,role="primary maven-dependency"]
.pom.xml
----
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-vertx</artifactId>
</dependency>
----

[source,gradle,role="secondary gradle-dependency"]

Check warning on line 2668 in docs/src/main/asciidoc/qute-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.CaseSensitiveTerms] Use 'Gradle' rather than 'gradle'. Raw Output: {"message": "[Quarkus.CaseSensitiveTerms] Use 'Gradle' rather than 'gradle'.", "location": {"path": "docs/src/main/asciidoc/qute-reference.adoc", "range": {"start": {"line": 2668, "column": 48}}}, "severity": "INFO"}
.build.gradle
----
implementation("io.quarkus:quarkus-vertx")
----

With this dependency included, we have a special value resolver for `io.vertx.core.json.JsonObject` which makes it possible to access the properties of a JSON object in a template:

.src/main/resources/templates/foo.txt
[source,text]
----
{tool.name}
{tool.fieldNames}
{tool.fields}
{tool.size}
{tool.empty}
{tool.isEmpty}
{tool.get('name')}
{tool.containsKey('name')}
----

.QuteVertxIntegration.java
[source,java]
----
import java.util.HashMap;
import jakarta.inject.Inject;
import io.vertx.core.json.JsonObject;
import io.quarkus.qute.Template;
public class QuteVertxIntegration {
@Inject
Template foo;
public String render() {
HashMap<String, Object> toolMap = new Map<String, Object>();
toolMap.put("name", "Roq");
JsonObject jsonObject = new JsonObject(toolMap);
return foo.data("tool", jsonObject).render();
}
}
----

The `QuteVertxIntegration#render()` output should look like:

Check failure on line 2711 in docs/src/main/asciidoc/qute-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsErrors] Use 'you' rather than 'i'. Raw Output: {"message": "[Quarkus.TermsErrors] Use 'you' rather than 'i'.", "location": {"path": "docs/src/main/asciidoc/qute-reference.adoc", "range": {"start": {"line": 2711, "column": 57}}}, "severity": "ERROR"}

[source,text]
----
Roq
[name]
[name]
1
false
false
Roq
true
----


=== Development Mode

Check warning on line 2726 in docs/src/main/asciidoc/qute-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Headings] Use sentence-style capitalization in '4.12. Development Mode'. Raw Output: {"message": "[Quarkus.Headings] Use sentence-style capitalization in '4.12. Development Mode'.", "location": {"path": "docs/src/main/asciidoc/qute-reference.adoc", "range": {"start": {"line": 2726, "column": 8}}}, "severity": "INFO"}

In the development mode, all files located in `src/main/resources/templates` are watched for changes.
Expand Down

0 comments on commit 12eecc5

Please sign in to comment.