mirror of
https://github.com/ethauvin/rife2-hello.git
synced 2025-04-25 15:37:10 -07:00
Initial commit
This commit is contained in:
parent
05b1ce9e95
commit
c40209698c
15 changed files with 584 additions and 0 deletions
98
app/build.gradle.kts
Normal file
98
app/build.gradle.kts
Normal file
|
@ -0,0 +1,98 @@
|
|||
/*
|
||||
* This file was generated by the Gradle 'init' task.
|
||||
*
|
||||
* This generated file contains a sample Java application project to get you started.
|
||||
* For more details take a look at the 'Building Java & JVM projects' chapter in the Gradle
|
||||
* User Manual available at https://docs.gradle.org/7.6/userguide/building_java_projects.html
|
||||
*/
|
||||
|
||||
plugins {
|
||||
// Apply the application plugin to add support for building a CLI application in Java.
|
||||
application
|
||||
}
|
||||
|
||||
base {
|
||||
archivesName.set("hello")
|
||||
version = 1.0
|
||||
}
|
||||
|
||||
repositories {
|
||||
// Use Maven Central for resolving dependencies.
|
||||
mavenCentral()
|
||||
maven { url = uri("https://s01.oss.sonatype.org/content/repositories/snapshots") } // only needed for SNAPSHOT
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
main {
|
||||
runtimeClasspath = files(file("src/main/resources"), runtimeClasspath);
|
||||
}
|
||||
}
|
||||
|
||||
sourceSets.main {
|
||||
resources.exclude("templates/**")
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation("com.uwyn.rife2:rife2:1.1.0-SNAPSHOT")
|
||||
runtimeOnly("org.eclipse.jetty:jetty-server:11.0.13")
|
||||
runtimeOnly("org.eclipse.jetty:jetty-servlet:11.0.13")
|
||||
runtimeOnly("org.slf4j:slf4j-simple:2.0.5")
|
||||
|
||||
testImplementation("org.jsoup:jsoup:1.15.3")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter:5.9.1")
|
||||
}
|
||||
|
||||
application {
|
||||
// Define the main class for the application.
|
||||
mainClass.set("hello.App")
|
||||
}
|
||||
|
||||
tasks {
|
||||
named<Test>("test") {
|
||||
// Use JUnit Platform for unit tests.
|
||||
useJUnitPlatform()
|
||||
}
|
||||
|
||||
// Pre-compile the RIFE2 templates to bytecode for deployment
|
||||
register<JavaExec>("precompileHtmlTemplates") {
|
||||
classpath = sourceSets["main"].runtimeClasspath
|
||||
mainClass.set("rife.template.TemplateDeployer")
|
||||
args = listOf(
|
||||
"-verbose",
|
||||
"-t", "html",
|
||||
"-d", "${projectDir}/build/classes/java/main",
|
||||
"-encoding", "UTF-8", "${projectDir}/src/main/resources/templates"
|
||||
)
|
||||
}
|
||||
|
||||
register("precompileTemplates") {
|
||||
dependsOn("precompileHtmlTemplates")
|
||||
}
|
||||
|
||||
// Ensure that the templates are pre-compiled before building the jar
|
||||
jar {
|
||||
dependsOn("precompileTemplates")
|
||||
}
|
||||
|
||||
// These two tasks create a self-container UberJar
|
||||
register<Copy>("copyWebapp") {
|
||||
from("src/main/")
|
||||
include("webapp/**")
|
||||
into("$buildDir/webapp")
|
||||
}
|
||||
|
||||
register<Jar>("uberJar") {
|
||||
dependsOn("jar")
|
||||
dependsOn("copyWebapp")
|
||||
archiveBaseName.set("hello-uber")
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
manifest {
|
||||
attributes["Main-Class"] = "hello.AppUber"
|
||||
}
|
||||
val dependencies = configurations
|
||||
.runtimeClasspath.get()
|
||||
.map(::zipTree)
|
||||
from(dependencies, "$buildDir/webapp")
|
||||
with(jar.get())
|
||||
}
|
||||
}
|
16
app/src/main/java/hello/App.java
Normal file
16
app/src/main/java/hello/App.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package hello;
|
||||
|
||||
import rife.engine.*;
|
||||
|
||||
public class App extends Site {
|
||||
public void setup() {
|
||||
var hello = get("/hello", c -> c.print(c.template("hello")));
|
||||
get("/", c -> c.redirect(hello));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new Server()
|
||||
.staticResourceBase("src/main/webapp")
|
||||
.start(new App());
|
||||
}
|
||||
}
|
12
app/src/main/java/hello/AppUber.java
Normal file
12
app/src/main/java/hello/AppUber.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package hello;
|
||||
|
||||
import rife.engine.Server;
|
||||
import rife.engine.Site;
|
||||
|
||||
public class AppUber extends App {
|
||||
public static void main(String[] args) {
|
||||
new Server()
|
||||
.staticUberJarResourceBase("webapp")
|
||||
.start(new AppUber());
|
||||
}
|
||||
}
|
11
app/src/main/resources/templates/hello.html
Normal file
11
app/src/main/resources/templates/hello.html
Normal 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</p>
|
||||
</body>
|
||||
</html>
|
21
app/src/main/webapp/css/style.css
Normal file
21
app/src/main/webapp/css/style.css
Normal file
|
@ -0,0 +1,21 @@
|
|||
:root {
|
||||
/* fonts */
|
||||
--main-font: sans-serif;
|
||||
|
||||
/* font sizes */
|
||||
--main-font-size: 18px;
|
||||
|
||||
/* colors */
|
||||
--main-background-color: #0d0d0d;
|
||||
--main-text-color: #d0d0d0;
|
||||
|
||||
/* margins and padding */
|
||||
--content-padding: 2em;
|
||||
}
|
||||
body {
|
||||
background: var(--main-background-color);
|
||||
font-family: var(--main-font);
|
||||
font-style: var(--main-font-size);
|
||||
color: var(--main-text-color);
|
||||
padding: var(--content-padding);
|
||||
}
|
18
app/src/test/java/hello/AppTest.java
Normal file
18
app/src/test/java/hello/AppTest.java
Normal file
|
@ -0,0 +1,18 @@
|
|||
/*
|
||||
* This Java source file was generated by the Gradle 'init' task.
|
||||
*/
|
||||
package hello;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import rife.test.MockConversation;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
public class AppTest {
|
||||
@Test
|
||||
void verifyHello() {
|
||||
var m = new MockConversation(new App());
|
||||
assertEquals("Hello", m.doRequest("/hello")
|
||||
.getTemplate().getValue("title"));
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue