Skip to content

Commit 7448e47

Browse files
committed
v2.0.6
1 parent 9c68b13 commit 7448e47

File tree

34 files changed

+101
-40
lines changed

34 files changed

+101
-40
lines changed

docs/asciidoc/modules.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Available modules are listed next.
2525
=== Template Engine
2626
* link:modules/handlebars[Handlebars]: Handlebars templates for Jooby.
2727
* link:modules/freemarker[Freemarker]: Freemarker templates for Jooby.
28-
* link:modules/rocker[Rocker]: Rocker templates for Jooby.
2928
* link:modules/pebble[Pebble]: Pebble templates for Jooby.
29+
* link:modules/rocker[Rocker]: Rocker templates for Jooby.
3030

3131
.

docs/asciidoc/routing.adoc

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,10 @@ A javadoc:Route[] consists of three part:
6161
The javadoc:Route.Handler[text="handler"] function always produces a result, which is send it back
6262
to the client.
6363

64-
==== Route attributes
64+
==== Attributes
6565

6666
Attributes let you annotate a route at application bootstrap time. It functions like static metadata available at runtime:
67+
6768
.Java
6869
[source, java, role="primary"]
6970
----
@@ -72,8 +73,20 @@ Attributes let you annotate a route at application bootstrap time. It functions
7273
.attribute("foo", "bar");
7374
}
7475
----
76+
77+
.Kotlin
78+
[source, kotlin, role="secondary"]
79+
----
80+
{
81+
get("/foo") {
82+
"Foo"
83+
}.attribute("foo", "bar")
84+
}
85+
----
86+
7587
An attribute consist of a name and value. Values can be any object.
7688
Attributes can be accessed at runtime in a request/response cycle. For example, a security module might check for a role attribute.
89+
7790
.Java
7891
[source, java, role="primary"]
7992
----
@@ -91,7 +104,25 @@ Attributes can be accessed at runtime in a request/response cycle. For example,
91104
}
92105
----
93106

107+
.Kotlin
108+
[source, kotlin, role="secondary"]
109+
----
110+
{
111+
decorator(
112+
val user = ...
113+
val role = ctx.route.attribute("Role")
114+
115+
if (user.hasRole(role)) {
116+
return next.apply(ctx)
117+
} else {
118+
throw StatusCodeException(StatusCode.FORBIDDEN)
119+
}
120+
}
121+
----
122+
123+
94124
In MVC routes you can set attributes via annotations:
125+
95126
.Java
96127
[source, java, role="primary"]
97128
----
@@ -113,24 +144,42 @@ public class AdminResource {
113144
114145
{
115146
decorator(next -> ctx -> {
116-
System.out.println(ctx.getRoute().attribute("Role"))
147+
System.out.println(ctx.getRoute().attribute("Role"));
117148
});
118149
}
119150
----
151+
152+
.Kotlin
153+
[source, kotlin, role="secondary"]
154+
----
155+
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION)
156+
@Retention(AnnotationRetention.RUNTIME)
157+
annotation class Role (val value: String)
158+
159+
@Path("/path")
160+
class AdminResource {
161+
162+
@Role("admin")
163+
fun doSomething() : Any {
164+
...
165+
}
166+
167+
}
168+
169+
{
170+
decorator {
171+
println(ctx.route.attribute("Role"))
172+
}
173+
}
174+
----
175+
120176
The previous example will print: admin.
121177
You can retrieve all the attributes of the route by calling `ctx.getRoute().getAttributes()`.
122178

123179
Any runtime annotation is automatically added as route attributes following these rules:
124180
- If the annotation has a value method, then we use the annotation’s name as the attribute name.
125181
- Otherwise, we use the method name as the attribute name.
126182

127-
.request attributes vs route attributes
128-
[NOTE]
129-
====
130-
Route attributes are created at bootstrap. They are global, and once set, they won’t change.
131-
On the other hand, request attributes are created in a request/response cycle.
132-
====
133-
134183

135184
=== Path Pattern
136185

docs/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.jooby</groupId>
88
<artifactId>jooby-project</artifactId>
9-
<version>2.0.6-SNAPSHOT</version>
9+
<version>2.0.6</version>
1010
</parent>
1111

1212
<modelVersion>4.0.0</modelVersion>

examples/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.jooby</groupId>
88
<artifactId>jooby-project</artifactId>
9-
<version>2.0.6-SNAPSHOT</version>
9+
<version>2.0.6</version>
1010
</parent>
1111

1212
<modelVersion>4.0.0</modelVersion>
@@ -24,6 +24,11 @@
2424
<artifactId>jooby-jackson</artifactId>
2525
<version>${jooby.version}</version>
2626
</dependency>
27+
<dependency>
28+
<groupId>io.jooby</groupId>
29+
<artifactId>jooby-banner</artifactId>
30+
<version>${jooby.version}</version>
31+
</dependency>
2732
<dependency>
2833
<groupId>io.jooby</groupId>
2934
<artifactId>jooby-run</artifactId>

examples/src/main/java/examples/HelloApp.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,15 @@
99
import io.jooby.RouterOptions;
1010
import io.jooby.TraceHandler;
1111
import io.jooby.annotations.QueryParam;
12+
import io.jooby.banner.BannerModule;
1213

1314
import java.util.stream.Stream;
1415

1516
public class HelloApp extends Jooby {
1617

1718
{
19+
install(new BannerModule("My App"));
20+
1821
decorator(new TraceHandler());
1922

2023
setRouterOptions(new RouterOptions().setIgnoreCase(false).setIgnoreTrailingSlash(true));

jooby/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.jooby</groupId>
88
<artifactId>jooby-project</artifactId>
9-
<version>2.0.6-SNAPSHOT</version>
9+
<version>2.0.6</version>
1010
</parent>
1111

1212
<modelVersion>4.0.0</modelVersion>

jooby/src/test/kotlin/io/jooby/Idioms.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ class Idioms : Kooby({
7777
ctx
7878
}
7979

80+
get("/attributes") {
81+
"some"
82+
}.attribute("k", "v")
83+
8084
/** Router DSL: */
8185
before {
8286
ctx.path()

modules/jooby-apt/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.jooby</groupId>
88
<artifactId>modules</artifactId>
9-
<version>2.0.6-SNAPSHOT</version>
9+
<version>2.0.6</version>
1010
</parent>
1111

1212
<modelVersion>4.0.0</modelVersion>

modules/jooby-archetype/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>io.jooby</groupId>
99
<artifactId>modules</artifactId>
10-
<version>2.0.6-SNAPSHOT</version>
10+
<version>2.0.6</version>
1111
</parent>
1212

1313
<artifactId>jooby-archetype</artifactId>

modules/jooby-banner/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>io.jooby</groupId>
88
<artifactId>modules</artifactId>
9-
<version>2.0.6-SNAPSHOT</version>
9+
<version>2.0.6</version>
1010
</parent>
1111

1212
<modelVersion>4.0.0</modelVersion>

0 commit comments

Comments
 (0)