Skip to content

Commit

Permalink
Documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
hpehl committed May 6, 2024
1 parent 555da38 commit 50358c4
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ public static class TimePage implements Page {
public static class Application {

public void entryPoint() {
body().add(div().id("main"));
new PlaceManager()
PlaceManager placeManager = new PlaceManager()
.root(By.id("main"))
.register(place("/time/:area/:location")
.loader((place, parameter) -> {
Expand All @@ -491,8 +490,11 @@ public static class Application {
JsPropertyMap<String> map = Js.cast(json);
return Promise.resolve(map.get("datetime"));
});
}), TimePage::new)
.start();
}), TimePage::new);
body().add(div().id("main")
.add(link(placeManager, "/time/Europe/Berlin")
.textNode("What time is it in Berlin?")));
placeManager.start();
}
}
```
Expand Down
11 changes: 7 additions & 4 deletions router/src/demo/java/PlaceManagerDemo.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import static org.jboss.elemento.Elements.h;
import static org.jboss.elemento.Elements.p;
import static org.jboss.elemento.Elements.span;
import static org.jboss.elemento.router.Link.link;
import static org.jboss.elemento.router.Place.place;

@SuppressWarnings("unused")
Expand All @@ -60,8 +61,7 @@ public Iterable<HTMLElement> elements(Place place, Parameter parameter, LoaderDa
public static class Application {

public void entryPoint() {
body().add(div().id("main"));
new PlaceManager()
PlaceManager placeManager = new PlaceManager()
.root(By.id("main"))
.register(place("/time/:area/:location")
.loader((place, parameter) -> {
Expand All @@ -74,8 +74,11 @@ public void entryPoint() {
JsPropertyMap<String> map = Js.cast(json);
return Promise.resolve(map.get("datetime"));
});
}), TimePage::new)
.start();
}), TimePage::new);
body().add(div().id("main")
.add(link(placeManager, "/time/Europe/Berlin")
.textNode("What time is it in Berlin?")));
placeManager.start();
}
}
// @end region = placeManager
Expand Down
13 changes: 12 additions & 1 deletion router/src/main/java/org/jboss/elemento/router/Link.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,28 @@

import static org.jboss.elemento.Elements.a;

/**
* The Link class represents a hyperlink element that creates hyperlinks using the {@link PlaceManager}. It extends the
* HTMLContainerBuilder class, which is a builder for container-like HTML elements.
*/
public class Link extends HTMLContainerBuilder<HTMLAnchorElement> {

// ------------------------------------------------------ factory

/**
* Creates a new Link instance based on the given PlaceManager and route.
*
* @param placeManager The PlaceManager used to resolve the route.
* @param route The route of the hyperlink.
* @return The new Link instance.
*/
public static Link link(PlaceManager placeManager, String route) {
return new Link(placeManager, route);
}

// ------------------------------------------------------ instance

public Link(PlaceManager placeManager, String route) {
Link(PlaceManager placeManager, String route) {
super(a(placeManager.href(route)).element());
}

Expand Down

0 comments on commit 50358c4

Please sign in to comment.