Skip to content

Commit da4431e

Browse files
authored
[jex generation] fix newline in generated code (#523)
1 parent ee26249 commit da4431e

File tree

8 files changed

+40
-22
lines changed

8 files changed

+40
-22
lines changed

http-generator-jex/src/main/java/io/avaje/http/generator/jex/ControllerMethodWriter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ private void write(boolean requestScoped) {
256256
} else {
257257
writer.append(indent);
258258
writeContextReturn(responseMode, "result");
259-
writer.eol();
260259
}
261260
if (includeNoContent) {
262261
writer.append(" }").eol();
@@ -268,7 +267,7 @@ private void writeContextReturn(ResponseMode responseMode, String resultVariable
268267
final UType type = UType.parse(method.returnType());
269268
if ("java.util.concurrent.CompletableFuture".equals(type.mainType())) {
270269
logError(method.element(), "CompletableFuture is not a supported return type.");
271-
writer.append("; //ERROR");
270+
writer.append("; //ERROR").eol();
272271
return;
273272
}
274273

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

285285
private void writeJsonReturn(String produces) {

tests/test-jex/src/main/java/org/example/web/ContentController.java

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@
66
import io.avaje.http.api.Get;
77
import io.avaje.http.api.Path;
88
import org.example.web.template.ViewHome;
9+
import org.example.web.template.ViewPartial;
910

1011
@Controller
1112
@Html
1213
@Path("ui")
1314
public class ContentController {
1415

16+
@HxRequest
1517
@Get
16-
Object index() {
17-
return new ViewHome("Hi");
18+
ViewPartial indexHxPartial() {
19+
return new ViewPartial("Rob");
1820
}
1921

20-
@HxRequest
2122
@Get
22-
Object indexHxReqest() {
23-
return new ViewHome("Hi");
23+
ViewHome index() {
24+
return new ViewHome("Hi");
2425
}
2526

2627
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package org.example.web.template;
2+
3+
import io.jstach.jstache.JStache;
4+
5+
@JStache(path = "partial")
6+
public class ViewPartial {
7+
public final String name;
8+
9+
public ViewPartial(String name) {
10+
this.name = name;
11+
}
12+
}

tests/test-jex/src/main/resources/public/openapi.json

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,7 +1280,7 @@
12801280
"content" : {
12811281
"text/html;charset=UTF8" : {
12821282
"schema" : {
1283-
"$ref" : "#/components/schemas/Object"
1283+
"$ref" : "#/components/schemas/ViewHome"
12841284
}
12851285
}
12861286
}
@@ -1405,8 +1405,21 @@
14051405
}
14061406
}
14071407
},
1408-
"Object" : {
1409-
"type" : "object"
1408+
"ViewHome" : {
1409+
"type" : "object",
1410+
"properties" : {
1411+
"name" : {
1412+
"type" : "string"
1413+
}
1414+
}
1415+
},
1416+
"ViewPartial" : {
1417+
"type" : "object",
1418+
"properties" : {
1419+
"name" : {
1420+
"type" : "string"
1421+
}
1422+
}
14101423
},
14111424
"WebHelloDto" : {
14121425
"type" : "object",

tests/test-jex/src/main/resources/ui/fragments/layout.mustache

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
<script src="https://unpkg.com/htmx.org@1.9.12"></script>
66
</head>
77
<body>
8-
<h1>Heading</h1>
98
{{$body}}Empty body{{/body}}
109
</body>
1110
</html>
Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
{{<fragments/layout}}
2-
{{$body}}
3-
<div id="name">
4-
Hi there {{ name }}
5-
</div>
6-
<button hx-get="name" hx-target="#name">One</button>
2+
{{$body}}
3+
<button hx-get="/ui" hx-target="#replaceMe">Update name</button>
4+
<div id="replaceMe">placeholder</div>
75
{{/body}}
86
{{/fragments/layout}}

tests/test-jex/src/main/resources/ui/name.mustache

Lines changed: 0 additions & 6 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<p>Hi {{ name }}!!</p>

0 commit comments

Comments
 (0)