Skip to content

[jex generation] fix newline in generated code #523

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

Merged
merged 1 commit into from
Dec 2, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,6 @@ private void write(boolean requestScoped) {
} else {
writer.append(indent);
writeContextReturn(responseMode, "result");
writer.eol();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the change - move this to be inside the writeContextReturn()

}
if (includeNoContent) {
writer.append(" }").eol();
Expand All @@ -268,7 +267,7 @@ private void writeContextReturn(ResponseMode responseMode, String resultVariable
final UType type = UType.parse(method.returnType());
if ("java.util.concurrent.CompletableFuture".equals(type.mainType())) {
logError(method.element(), "CompletableFuture is not a supported return type.");
writer.append("; //ERROR");
writer.append("; //ERROR").eol();
return;
}

Expand All @@ -280,6 +279,7 @@ private void writeContextReturn(ResponseMode responseMode, String resultVariable
case Templating -> writer.append("ctx.html(%s);", resultVariable);
default -> writer.append("ctx.contentType(\"%s\").write(%s);", produces, resultVariable);
}
writer.eol();
}

private void writeJsonReturn(String produces) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,22 @@
import io.avaje.http.api.Get;
import io.avaje.http.api.Path;
import org.example.web.template.ViewHome;
import org.example.web.template.ViewPartial;

@Controller
@Html
@Path("ui")
public class ContentController {

@HxRequest
@Get
Object index() {
return new ViewHome("Hi");
ViewPartial indexHxPartial() {
return new ViewPartial("Rob");
}

@HxRequest
@Get
Object indexHxReqest() {
return new ViewHome("Hi");
ViewHome index() {
return new ViewHome("Hi");
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.example.web.template;

import io.jstach.jstache.JStache;

@JStache(path = "partial")
public class ViewPartial {
public final String name;

public ViewPartial(String name) {
this.name = name;
}
}
19 changes: 16 additions & 3 deletions tests/test-jex/src/main/resources/public/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1280,7 +1280,7 @@
"content" : {
"text/html;charset=UTF8" : {
"schema" : {
"$ref" : "#/components/schemas/Object"
"$ref" : "#/components/schemas/ViewHome"
}
}
}
Expand Down Expand Up @@ -1405,8 +1405,21 @@
}
}
},
"Object" : {
"type" : "object"
"ViewHome" : {
"type" : "object",
"properties" : {
"name" : {
"type" : "string"
}
}
},
"ViewPartial" : {
"type" : "object",
"properties" : {
"name" : {
"type" : "string"
}
}
},
"WebHelloDto" : {
"type" : "object",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
<script src="https://unpkg.com/htmx.org@1.9.12"></script>
</head>
<body>
<h1>Heading</h1>
{{$body}}Empty body{{/body}}
</body>
</html>
8 changes: 3 additions & 5 deletions tests/test-jex/src/main/resources/ui/home.mustache
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
{{<fragments/layout}}
{{$body}}
<div id="name">
Hi there {{ name }}
</div>
<button hx-get="name" hx-target="#name">One</button>
{{$body}}
<button hx-get="/ui" hx-target="#replaceMe">Update name</button>
<div id="replaceMe">placeholder</div>
{{/body}}
{{/fragments/layout}}
6 changes: 0 additions & 6 deletions tests/test-jex/src/main/resources/ui/name.mustache

This file was deleted.

1 change: 1 addition & 0 deletions tests/test-jex/src/main/resources/ui/partial.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>Hi {{ name }}!!</p>