Skip to content

Commit 1a56911

Browse files
committed
Merge pull request #18 from decebals/release-0.6.0
update to release 0.6.0
2 parents db33550 + 63f5e15 commit 1a56911

15 files changed

+239
-33
lines changed

_posts/2015-03-17-reverse-routing.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,40 @@ parameters.put("action", "new");
4444
String url = routeContext.uriFor("/contacts/{id}", parameters);
4545
```
4646

47-
By default (via `DefaultRouter`) the `uriFor` method automatically encode the parameters values.
47+
Are some scenarios when it's more ease to use the route name for `uriFor()`.
48+
In few words I can add a route (in an hypothetical blog application) that render a template with:
49+
50+
```java
51+
GET("/blogs/{year}/{month}/{day}/{title}", (routeContext) -> { routeContext.render("myTemplate")});
52+
```
53+
54+
It's hard to create the reverse routing using the `uriPattern`:
55+
56+
```java
57+
Map<String, Object> parameters = ...
58+
routeContext.uriFor("/blogs/{year}/{month}/{day}/{title}", parameters);
59+
```
60+
61+
The simplest solution is to add a `name` to our route and to use this name when we build the URL(reverse routing) to that route:
62+
63+
```java
64+
GET("/blogs/{year}/{month}/{day}/{title}", (routeContext) -> { routeContext.render("myTemplate")}).named("blog");
65+
```
66+
67+
The new code becomes more short and readable:
68+
69+
```java
70+
Map<String, Object> parameters = ...
71+
routeContext.uriFor("blog", parameters);
72+
```
73+
74+
Advantages:
75+
76+
- it is often more descriptive than hard-coding the `uriPattern`
77+
- it allows you to change `uriPattern` in one go, without having to remember to change URLs all over the place.
78+
79+
80+
**Note:** By default (via `DefaultRouter`) the `uriFor` method automatically encode the parameters values.
4881

4982
In conclusion if you want to create links to routes or controllers you must use `Router.uriFor` methods.
5083

_posts/2015-03-17-server.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ Pippo comes (out of the box) with some web servers:
5353

5454
- [Jetty](http://eclipse.org/jetty) `pippo-jetty`
5555
- [Undertow](http://undertow.io) `pippo-undertow`
56+
- [Tomcat](http://tomcat.apache.org) `pippo-tomcat`
5657
- [TJWS](http://tjws.sourceforge.net) `pippo-tjws`
5758

5859
To use one of these servers just add a dependency in your project:
@@ -83,5 +84,5 @@ public interface WebServer {
8384

8485
If you want to make your embedded server plugable for Pippo than you must add file
8586
`ro.pippo.core.WebServer` in _src/main/resources/META-INF/services_ folder with your class name that implements
86-
WebServer as content (for an hypothetical Tomcat integration the content file should be _ro.pippo.tomcat.TomcatServer_).
87+
WebServer as content (for a Tomcat integration the content file should be _ro.pippo.tomcat.TomcatServer_).
8788

_posts/2015-03-17-static-files.md

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,19 @@ For example:
1919

2020
```java
2121
Pippo pippo = new Pippo();
22-
pippo.getApplication().GET(new PublicResourceHandler());
23-
pippo.getApplication().GET(new WebjarsResourceHandler());
22+
pippo.getApplication().addPublicResourceRoute();
23+
pippo.getApplication().addWebjarsResourceRoute();
2424
```
2525

26-
You can use multiple `FileResourceHandler` but it is nonsense to use more `PublicResourceHandler` or more `WebjarsResourceHandler`.
26+
or more verbose:
27+
28+
```java
29+
Pippo pippo = new Pippo();
30+
pippo.getApplication().addResourceRoute(new PublicResourceHandler());
31+
pippo.getApplication().addResourceRoute(new WebjarsResourceHandler());
32+
```
33+
34+
You can use multiple `FileResourceRoute` but it is nonsense to use more `PublicResourceRoute` or more `WebjarsResourceRoute`.
2735

2836
The [CrudNgDemo]({{ site.demourl }}/pippo-demo-crudng) (demo pippo-angularjs integration) is a good application that demonstrates the concept of static files.
2937
In `src/main/resources` we created a folder __public__ and we put all assets in that folder (imgs, css, js, fonts, ...).
@@ -52,12 +60,21 @@ In this demo, the html template page (freemarker engine) contains a head section
5260
<meta content="IE=edge" http-equiv="X-UA-Compatible">
5361
<meta name="viewport" content="width=device-width, initial-scale=1.0">
5462

55-
<link href="${webjarsAt('bootstrap/3.3.1/css/bootstrap.min.css')}" rel="stylesheet">
56-
<link href="${webjarsAt('font-awesome/4.2.0/css/font-awesome.min.css')}" rel="stylesheet">
63+
<link href="${webjarsAt('bootstrap/css/bootstrap.min.css')}" rel="stylesheet">
64+
<link href="${webjarsAt('font-awesome/css/font-awesome.min.css')}" rel="stylesheet">
5765
<link href="${publicAt('css/style.css')}" rel="stylesheet">
5866
</head>
5967
```
6068

69+
If you want to have more control over webjars artifact version you can use this declaration:
70+
71+
```html
72+
<head>
73+
<link href="${webjarsAt('bootstrap/3.3.1/css/bootstrap.min.css')}" rel="stylesheet">
74+
<link href="${webjarsAt('font-awesome/4.2.0/css/font-awesome.min.css')}" rel="stylesheet">
75+
</head>
76+
```
77+
6178
Sure in your pom.xml file (if you use Maven) you must declare the dependencies to these webjars:
6279

6380
```xml
@@ -75,12 +92,12 @@ Sure in your pom.xml file (if you use Maven) you must declare the dependencies t
7592
</dependency>
7693
```
7794

78-
If you want to serve static files that are not on the classpath then you may use the `FileResourceHandler`.
95+
If you want to serve static files that are not on the classpath then you may use the `FileResourceRoute`.
7996

8097
```java
8198
Pippo pippo = new Pippo();
8299
// make available some files from a local folder (try a request like 'src/main/resources/simplelogger.properties')
83-
pippo.getApplication().GET(new FileResourceHandler("/src", "src"));
100+
pippo.getApplication().addFileResourceRoute("/src", "src");
84101
```
85102

86-
From security reason the `FileResourceHandler` doesn't serve resources from outside it's base directory by using relative paths such as `../../../private.txt`.
103+
From security reason the `FileResourceRoute` doesn't serve resources from outside it's base directory by using relative paths such as `../../../private.txt`.

_posts/2015-03-17-templates.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ Pippo comes (out of the box) with some template engines:
2020
- [Groovy](/doc/templates/groovy.html) `pippo-groovy`
2121
- [Pebble](/doc/templates/pebble.html) `pippo-pebble`
2222
- [Trimou](/doc/templates/trimou.html) `pippo-trimou`
23+
- [Velocity]({{ site.codeurl }}/pippo-velocity) `pippo-velocity`
2324

2425
To use one of these template engines just add a dependency in your project:
2526

_posts/2015-04-03-freemarker.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ pippo-freemarker supports context-aware url generation for your classpath resour
7676
<script src="${publicAt('js/main.js')}"></script>
7777
```
7878

79-
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceHandler` and/or a `PublicResourcehandler`.
79+
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceRoute` and/or a `PublicResourceRoute`.
8080

8181
```java
8282
public class MyApplication extends Application {
8383

8484
@Override
8585
protected void onInit() {
86-
// add classpath resource handlers
87-
GET(new WebjarsResourceHandler());
88-
GET(new PublicResourceHandler());
86+
// add routes for static content
87+
addPublicResourceRoute();
88+
addWebjarsResourceRoute();
8989
...
9090
}
9191

_posts/2015-04-03-groovy.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ script(src: webjarsAt('bootstrap/3.3.1/js/bootstrap.min.js')) {}
7575
script(src: publicAt('js/main.js')) {}
7676
```
7777

78-
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceHandler` and/or a `PublicResourcehandler`.
78+
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceRoute` and/or a `PublicResourceRoute`.
7979

8080
```java
8181
public class MyApplication extends Application {
8282

8383
@Override
8484
protected void onInit() {
85-
// add classpath resource handlers
86-
GET(new WebjarsResourceHandler());
87-
GET(new PublicResourceHandler());
85+
// add routes for static content
86+
addPublicResourceRoute();
87+
addWebjarsResourceRoute();
8888
...
8989
}
9090

_posts/2015-04-03-jade.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,16 @@ script(src=pippo.webjarsAt('bootstrap/3.3.1/js/bootstrap.min.js'))
7676
script(src=pippo.publicAt('js/main.js'))
7777
```
7878

79-
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceHandler` and/or a `PublicResourcehandler`.
79+
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceRoute` and/or a `PublicResourceRoute`.
8080

8181
```java
8282
public class MyApplication extends Application {
8383

8484
@Override
8585
protected void onInit() {
86-
// add classpath resource handlers
87-
GET(new WebjarsResourceHandler());
88-
GET(new PublicResourceHandler());
86+
// add routes for static content
87+
addPublicResourceRoute();
88+
addWebjarsResourceRoute();
8989
...
9090
}
9191

_posts/2015-04-03-pebble.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,16 +79,16 @@ pippo-pebble supports context-aware url generation for your classpath resources
7979
{% endraw %}
8080
```
8181

82-
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceHandler` and/or a `PublicResourcehandler`.
82+
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceRoute` and/or a `PublicResourceRoute`.
8383

8484
```java
8585
public class MyApplication extends Application {
8686

8787
@Override
8888
protected void onInit() {
89-
// add classpath resource handlers
90-
GET(new WebjarsResourceHandler());
91-
GET(new PublicResourceHandler());
89+
// add routes for static content
90+
addPublicResourceRoute();
91+
addWebjarsResourceRoute();
9292
...
9393
}
9494

_posts/2015-04-03-trimou.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,16 @@ pippo-trimou supports context-aware url generation for your classpath resources
8484
{% endraw %}
8585
```
8686

87-
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceHandler` and/or a `PublicResourcehandler`.
87+
**NOTE:** Use of these methods require that you have registered a `WebjarsResourceRoute` and/or a `PublicResourceRoute`.
8888

8989
```java
9090
public class MyApplication extends Application {
9191

9292
@Override
9393
protected void onInit() {
94-
// add classpath resource handlers
95-
GET(new WebjarsResourceHandler());
96-
GET(new PublicResourceHandler());
94+
// add routes for static content
95+
addPublicResourceRoute();
96+
addWebjarsResourceRoute();
9797
...
9898
}
9999

_posts/2015-05-05-routes.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,18 @@ If you want to be more riguros you can use something like:
5656
```java
5757
GET("/contact/{id: [0-9]+}", (routeContext) -> { ... });
5858
```
59+
60+
`Named` routes make referring to routes when generating redirects or URLs more convenient. You may specify a name for a route like so:
61+
62+
```java
63+
GET("/blogs/{year}/{month}/{day}/{title}", (routeContext) -> { routeContext.render("myTemplate")}).named("blog");
64+
```
65+
66+
Now, you may use the route's name when generating URLs or redirects:
67+
68+
```java
69+
Map<String, Object> parameters = ...
70+
routeContext.uriFor("blog", parameters);
71+
// or
72+
routeContext.redirect("blog", parameters);
73+
```

0 commit comments

Comments
 (0)