From 17dccdd91aca94091c27070e79f032e754c72548 Mon Sep 17 00:00:00 2001 From: Clement Escoffier Date: Sun, 7 Jul 2024 16:46:57 +0200 Subject: [PATCH] Enhance JBang Documentation with Configuration and Qute Template The existing configuration section was not functional due to issue #30087. This commit addresses this by documenting alternative methods using `application.properties` or `application.yaml`, as recommended in issue #41739. Additionally, integrating Qute templates was not straightforward. This commit adds a dedicated section to the JBang documentation, providing instructions on how to include and use Qute templates. --- docs/src/main/asciidoc/scripting.adoc | 42 ++++++++++++++++++++++----- 1 file changed, 35 insertions(+), 7 deletions(-) diff --git a/docs/src/main/asciidoc/scripting.adoc b/docs/src/main/asciidoc/scripting.adoc index a57f94b7702f4..c2ea4bddbee9c 100644 --- a/docs/src/main/asciidoc/scripting.adoc +++ b/docs/src/main/asciidoc/scripting.adoc @@ -375,18 +375,29 @@ With that in place running `jbang quarkusapp.java` will log and render as expect == Configuring Application -You can use `//Q:CONFIG =` to set up static configuration for your application. +To configure the application you can use the `application.properties` file as usual, but you need to _add_ it to the script: -I.e. if you wanted to add the `smallrye-openapi` and `swagger-ui` extensions and have the Swagger UI always show up you would add the following: +[source,java] +---- +//FILES application.properties -[source,java,subs=attributes+] +// ... +@ConfigProperty(name = "prefix", defaultValue = "WG -") +String prefix; +---- + +This will make the `application.properties` file available to the script, and process the configuration as usual. + +You can also use the `application.yaml` file. +For this, you need to _add_ it to the `application.yaml` file to the script and include the `quarkus-config-yaml` dependency: + +[source,java] ---- -//DEPS io.quarkus:quarkus-smallrye-openapi:{quarkus-version} -//DEPS io.quarkus:quarkus-swagger-ui:{quarkus-version} -//Q:CONFIG quarkus.swagger-ui.always-include=true +//DEPS io.quarkus:quarkus-config-yaml +//FILES application.yaml ---- -Now during build the `quarkus.swagger-ui.always-include` will be generated into the resulting jar and `http://0.0.0.0:8080/q/swagger-ui` will be available when run. +NOTE: The path to the `application.properties` and `application.yaml` files are relative to the script file. == Running as a native application @@ -440,6 +451,23 @@ __ ____ __ _____ ___ __ ____ ______ 2023-03-22 09:38:45,450 INFO [io.quarkus] (main) Installed features: [cdi, rest, smallrye-context-propagation, vertx] ---- +=== Using Qute + +You can use the xref:./qute.adoc[Qute templating engine] in your JBang script by adding the `quarkus-qute` dependency. +You also need to include the `templates` directory in the script: +[source,java] +---- +//DEPS io.quarkus:quarkus-qute +//FILES templates/=templates/* + +// ... + + @Inject + Template template; // Locate and load the `templates/template.html` file +---- + +If your `templates` directory includes sub-directories, use `templates/=templates/**/*` instead. + === Conclusion If you want to get started with Quarkus or write something quickly, Quarkus Scripting with jbang lets you do that. No Maven, no Gradle - just a Java file. In this guide we outlined the very basics on using Quarkus with JBang; if you want to learn more about what JBang can do, go see https://jbang.dev.