Skip to content
This repository was archived by the owner on Mar 3, 2026. It is now read-only.

Commit 58915ba

Browse files
committed
API change: View model must be a Map and not any object fix jooby-project#47
before: ```java View.of("viewname", model); // where model was of anything ``` after: ```java // view with empty model View.of("viewname"); // view with a initial model attr View.of("viewname", "model", model); // view with model built incrementally View.of("viewname") .put("model1", model1) .put("model2", model2); ```
1 parent 51941a6 commit 58915ba

File tree

15 files changed

+87
-96
lines changed

15 files changed

+87
-96
lines changed

coverage-report/src/test/java/org/jooby/ContentNegotiationFeature.java

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
package org.jooby;
22

3-
import org.jooby.Body;
4-
import org.jooby.MediaType;
5-
import org.jooby.Status;
6-
import org.jooby.View;
73
import org.jooby.mvc.Consumes;
84
import org.jooby.mvc.GET;
95
import org.jooby.mvc.Path;
@@ -52,7 +48,7 @@ public String json() {
5248

5349
get("/any", (req, resp) ->
5450
resp.format()
55-
.when("text/html", () -> View.of("test", "body"))
51+
.when("text/html", () -> View.of("test", "this", "body"))
5652
.when("*/*", () -> "body")
5753
.send());
5854

@@ -63,11 +59,11 @@ public String json() {
6359

6460
get("/like", (req, resp) ->
6561
resp.format()
66-
.when("text/html", () -> View.of("test", "body"))
62+
.when("text/html", () -> View.of("test", "this", "body"))
6763
.when("application/json", () -> "body")
6864
.send());
6965

70-
get("/html", (req, resp) -> resp.send(View.of("test", "body")))
66+
get("/html", (req, resp) -> resp.send(View.of("test", "this", "body")))
7167
.produces(MediaType.html);
7268

7369
get("/json", (req, resp) -> resp.send("body"))
@@ -84,35 +80,35 @@ public void chromeAccept() throws Exception {
8480
request()
8581
.get("/any")
8682
.header("Accept", CHROME_ACCEPT)
87-
.expect("<html><body>test: body</body></html>");
83+
.expect("<html><body>test: {this=body}</body></html>");
8884

8985
request()
9086
.get("/r/any")
9187
.header("Accept", CHROME_ACCEPT)
92-
.expect("<html><body>any: body</body></html>");
88+
.expect("<html><body>any: {this=body}</body></html>");
9389
}
9490

9591
@Test
9692
public void htmlAccept() throws Exception {
9793
request()
9894
.get("/any")
9995
.header("Accept", "text/html")
100-
.expect("<html><body>test: body</body></html>");
96+
.expect("<html><body>test: {this=body}</body></html>");
10197

10298
request()
10399
.get("/r/any")
104100
.header("Accept", "text/html")
105-
.expect("<html><body>any: body</body></html>");
101+
.expect("<html><body>any: {this=body}</body></html>");
106102

107103
request()
108104
.get("/html")
109105
.header("Accept", CHROME_ACCEPT)
110-
.expect("<html><body>test: body</body></html>");
106+
.expect("<html><body>test: {this=body}</body></html>");
111107

112108
request()
113109
.get("/r/html")
114110
.header("Accept", CHROME_ACCEPT)
115-
.expect("<html><body>html: body</body></html>");
111+
.expect("<html><body>html: {this=body}</body></html>");
116112

117113
request()
118114
.get("/json")

coverage-report/src/test/java/org/jooby/TemplateEngineFeature.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import java.io.IOException;
44

5-
import org.jooby.Body;
6-
import org.jooby.View;
75
import org.jooby.mvc.GET;
86
import org.jooby.mvc.Path;
97
import org.jooby.mvc.Viewable;
@@ -20,7 +18,7 @@ public static class Resource {
2018
@Path("/view")
2119
@GET
2220
public View view() throws IOException {
23-
return View.of("test", "model");
21+
return View.of("test", "this", "model");
2422
}
2523

2624
@Path("/view/template")
@@ -39,7 +37,7 @@ public Object template() throws IOException {
3937
});
4038

4139
get("/view", (req, resp) -> {
42-
resp.send(View.of("test", "model"));
40+
resp.send(View.of("test", "this", "model"));
4341
});
4442

4543
use(Resource.class);
@@ -49,18 +47,18 @@ public Object template() throws IOException {
4947
public void view() throws Exception {
5048
request()
5149
.get("/view")
52-
.expect("<html><body>test: model</body></html>");
50+
.expect("<html><body>test: {this=model}</body></html>");
5351

5452
request()
5553
.get("/r/view")
56-
.expect("<html><body>test: model</body></html>");
54+
.expect("<html><body>test: {this=model}</body></html>");
5755
}
5856

5957
@Test
6058
public void templateAnnotation() throws Exception {
6159
request()
6260
.get("/r/view/template")
63-
.expect("<html><body>template: model</body></html>");
61+
.expect("<html><body>template: {this=model}</body></html>");
6462

6563
}
6664

coverage-report/src/test/java/org/jooby/ViewWithExplicitEngineFeature.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jooby;
22

33
import org.jooby.Body.Writer;
4-
import org.jooby.View;
54
import org.jooby.test.ServerFeature;
65
import org.junit.Test;
76

@@ -37,7 +36,7 @@ public void render(final View viewable, final Writer writer) throws Exception {
3736

3837
get("/:engine", (req, rsp) -> {
3938
String engine = req.param("engine").value();
40-
rsp.send(View.of("view", new Object()).engine(engine));
39+
rsp.send(View.of("view", "this", new Object()).engine(engine));
4140
});
4241

4342
}

coverage-report/src/test/java/org/jooby/hbs/HbsCacheOffFeature.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.junit.Assert.assertSame;
44

5-
import org.jooby.hbs.Hbs;
65
import org.jooby.test.ServerFeature;
76
import org.junit.Test;
87

@@ -29,7 +28,7 @@ public class HbsCacheOffFeature extends ServerFeature {
2928
@Test
3029
public void hbs() throws Exception {
3130
request()
32-
.get("/?model=jooby")
31+
.get("/")
3332
.expect("noop");
3433
}
3534

coverage-report/src/test/java/org/jooby/hbs/HbsCustomFeature.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import static org.junit.Assert.assertSame;
44

55
import org.jooby.View;
6-
import org.jooby.hbs.Hbs;
76
import org.jooby.test.ServerFeature;
87
import org.junit.Test;
98

@@ -16,7 +15,7 @@ public class HbsCustomFeature extends ServerFeature {
1615
Handlebars handlebars = new Handlebars(new ClassPathTemplateLoader("/org/jooby/hbs", ".html"));
1716
use(new Hbs(handlebars).doWith(h -> assertSame(handlebars, h)));
1817

19-
get("/", req -> View.of("index", req.param("model").value()));
18+
get("/", req -> View.of("index", "model", req.param("model").value()));
2019
}
2120

2221
@Test

coverage-report/src/test/java/org/jooby/hbs/HbsFeature.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package org.jooby.hbs;
22

33
import org.jooby.View;
4-
import org.jooby.hbs.Hbs;
54
import org.jooby.test.ServerFeature;
65
import org.junit.Test;
76

@@ -10,7 +9,7 @@ public class HbsFeature extends ServerFeature {
109
{
1110
use(new Hbs());
1211

13-
get("/", req -> View.of("/org/jooby/hbs/index", req.param("model").value()));
12+
get("/", req -> View.of("org/jooby/hbs/index", "model", req.param("model").value()));
1413
}
1514

1615
@Test

coverage-report/src/test/java/org/jooby/hbs/HbsNoCacheFeature.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import static org.junit.Assert.assertSame;
44

5-
import org.jooby.hbs.Hbs;
65
import org.jooby.test.ServerFeature;
76
import org.junit.Test;
87

@@ -23,7 +22,7 @@ public class HbsNoCacheFeature extends ServerFeature {
2322
@Test
2423
public void hbs() throws Exception {
2524
request()
26-
.get("/?model=jooby")
25+
.get("/")
2726
.expect("noop");
2827
}
2928

coverage-report/src/test/java/org/jooby/hbs/HbsWithContextResultFeature.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

coverage-report/src/test/java/org/jooby/issues/Issue27.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ public class Issue27 extends ServerFeature {
1818

1919
get("*", (req, rsp) -> req.set("session", req.session()));
2020

21-
get("/config", req -> View.of("org/jooby/issues/27/config", new Object()));
21+
get("/config", req -> View.of("org/jooby/issues/27/config", "this", new Object()));
2222

23-
get("/req", req -> View.of("org/jooby/issues/27/req", new Object()));
23+
get("/req", req -> View.of("org/jooby/issues/27/req", "this", new Object()));
2424

2525
get("/session", req -> {
2626
req.session().set("attr", "session-attr");
27-
return View.of("org/jooby/issues/27/session", new Object());
27+
return View.of("org/jooby/issues/27/session", "this", new Object());
2828
});
2929
}
3030

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<html><body>{{this}}</body></html>
1+
<html><body>{{model}}</body></html>

0 commit comments

Comments
 (0)