2
0
Fork 0
mirror of https://github.com/ethauvin/rife2-hello.git synced 2025-04-25 23:37:12 -07:00

Add support for extra template directories

By default, the template was using `src/main/templates` as the source directory
for templates. This has the benefit of properly isolating the templates from
the application classpath: the framework is then responsible for injecting them
to the app runtime in whatever suitable form: either untouched as sources (in
development mode), or precompiled (for production).

With this change, it is also possible to use `src/main/resources/templates` as
a source directory. It _may_ feel more natural to users (although I would disagree),
but it has the drawback that the jars have to be configured to _exclude_ those
resources, because by default whatever is in `src/main/resources` MUST be included
in a jar (independently of the run mode).

It is also possible for the user to configure additional source directories should
they want to.
This commit is contained in:
Cedric Champeau 2023-03-05 15:10:46 +01:00
parent 5ca1fa305b
commit 21c85ea93b
No known key found for this signature in database
GPG key ID: 825C06C827AF6B66
7 changed files with 70 additions and 23 deletions

View file

@ -6,6 +6,7 @@ public class App extends Site {
public void setup() {
var hello = get("/hello", c -> c.print(c.template("hello")));
get("/", c -> c.redirect(hello));
get("/world", c -> c.print(c.template("world")));
}
public static void main(String[] args) {
@ -13,4 +14,4 @@ public class App extends Site {
.staticResourceBase("src/main/webapp")
.start(new App());
}
}
}

View file

@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title><!--v title-->Hello<!--/v--></title>
<link rel="stylesheet" href="{{v webapp:rootUrl/}}css/style.css?{{v context:paramRandom/}}">
</head>
<body>
<p>Hello World from src/main/resources/templates</p>
</body>
</html>