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 module update #557

Merged
merged 2 commits into from
Mar 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@
<module>kamelet</module>
<module>logging/jboss</module>
<module>cache/caffeine</module>
<!-- <module>qute/multimodule</module> -->
<module>qute/multimodule</module>
</modules>
</profile>
<profile>
Expand Down
6 changes: 1 addition & 5 deletions qute/multimodule/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-qute</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jackson</artifactId>
<artifactId>quarkus-resteasy-qute</artifactId>
</dependency>
</dependencies>
</project>
15 changes: 15 additions & 0 deletions qute/multimodule/qute-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,19 @@
<artifactId>qute-api</artifactId>
<packaging>jar</packaging>
<name>Quarkus QE TS: Qute-api</name>
<profiles>
<profile>
<!-- Disable native build on this module -->
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<!-- To not build the module on Native -->
<quarkus.package.type>fast-jar</quarkus.package.type>
</properties>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
@MessageBundle(value = "alert")
public interface AlertMessages {

@Message("")
@Message("Hello")
String withoutParams();

@Message("")
@Message("Hello {name}")
String withParams(String name);
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.qe.qute.api;

import io.quarkus.qute.i18n.Message;
import io.quarkus.qute.i18n.MessageBundle;

@MessageBundle
public interface MyQuteMessages {
@Message("Hello world!")
String hello();

@Message("Hello {name}!")
String hello_name(String name);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package io.quarkus.qe.qute.api;

import static java.util.Objects.requireNonNull;

import java.util.Locale;

import javax.inject.Inject;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import io.quarkus.qute.Template;
import io.quarkus.qute.TemplateInstance;
import io.quarkus.qute.i18n.Localized;
import io.quarkus.qute.i18n.MessageBundles;

@Path("/hello")
public class MyQuteResource {
private final Template page;

@Inject
MyQuteMessages enAppMessages;
@Localized("cs")
MyQuteMessages csAppMessages;

@Inject
AlertMessages enAlertMessages;
@Localized("el")
AlertMessages elAlertMessages;

public MyQuteResource(Template page) {
this.page = requireNonNull(page, "page is required");
}

@GET
@Path("{lang}")
@Produces(MediaType.TEXT_PLAIN)
public String hello(@PathParam("lang") String lang) {
AlertMessages messages = lang.equals("el") ? elAlertMessages : enAlertMessages;
return messages.withoutParams() + ". " + messages.withParams("Nikos");
}

@GET
@Path("/names")
@Produces(MediaType.TEXT_PLAIN)
public String names() {
return MessageBundles.get(MyQuteMessages.class).hello_name("Rostislav") + " == " +
enAppMessages.hello_name("Rostislav") + " | " +
MessageBundles.get(MyQuteMessages.class, Localized.Literal.of("cs")).hello_name("Rostislav") + " == " +
csAppMessages.hello_name("Rostislav");
}

@GET
@Path("/page")
@Produces(MediaType.TEXT_HTML)
public TemplateInstance get(@QueryParam("name") String name) {
return page.data("name", name).setAttribute("locale", Locale.forLanguageTag("cs"));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hello=Ahoj!
hello_name=Ahoj {name}!
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello {name ?: "Qute"}</title>
<style>
body {
background-color: #000;
color: #fff;
}
h1 {
color: #4695EB;
font-size: 6vw;
}

h1 b {
color: #be9100;
}

p {
font-size: 2vw;
}
</style>
</head>
<body>
<h1>Hello <b>{name ?: "Qute"}</b></h1>

{msg:hello} {msg:hello_name('Rostislav')}

<p>Create your web page using Quarkus RESTEasy & Qute</p>
</body>
</html>
1 change: 0 additions & 1 deletion qute/multimodule/qute-test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
<groupId>io.quarkus.ts.qe</groupId>
<artifactId>qute-api</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
hello=Ahoj!
hello_name=Ahoj {name}!
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.quarkus.qe.qute;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.CsvSource;

import io.quarkus.test.scenarios.QuarkusScenario;

@QuarkusScenario
class LocalizedMessagesIT {

@Tag("QUARKUS-1547")
@ParameterizedTest
@CsvSource({ "en, Hello. Hello Nikos", "el, Γειά. Γειά σου Nikos" })
void useLocalizedMessageInstance(String lang, String output) {
given()
.when().get("/hello/" + lang)
.then()
.statusCode(200)
.body(is(output));
}

@Test
void useMessageBundlesAndLocalizedAnnotation() {
given()
.when().get("/hello/names")
.then()
.statusCode(200)
.body(is("Hello Rostislav! == Hello Rostislav! | Ahoj Rostislav! == Ahoj Rostislav!"));
}

@Test
void useLocalizedTemplate() {
given()
.when().get("/hello/page")
.then()
.statusCode(200)
.body(containsString("Ahoj Rostislav!"));
}
}

This file was deleted.

Empty file.

This file was deleted.