From 644fcfd8f97c90180485e686d0b593efb986541e Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Tue, 2 Apr 2019 22:25:14 +0200 Subject: Tried implementing rocker templating engine --- src/main/kotlin/App.kt | 15 +++++++++++++-- src/main/resources/test.rocker.html | 2 ++ src/main/resources/upload.html | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 src/main/resources/test.rocker.html (limited to 'src/main') diff --git a/src/main/kotlin/App.kt b/src/main/kotlin/App.kt index d7467a4..b5d6042 100644 --- a/src/main/kotlin/App.kt +++ b/src/main/kotlin/App.kt @@ -1,16 +1,27 @@ package space.anity +import com.fizzed.rocker.* import io.javalin.* import io.javalin.core.util.* +import io.javalin.rendering.* +import io.javalin.rendering.template.TemplateUtil.model import java.io.* import java.nio.file.* fun main(args: Array) { val fileHome = "files" + JavalinRenderer.register( + FileRenderer { filepath, model -> Rocker.template(filepath).bind(model).render().toString() }, ".rocker.html" + ) val app = Javalin.create().enableStaticFiles("../resources/").start(7000) + // TODO: Fix rocker templating + app.get("/test") { ctx -> + ctx.render("test.rocker.html", model("message", "Testy testy!")) + } + // TODO: Fix possible security issue with "../" - app.get("/files/*") { ctx -> + app.get("/api/files/*") { ctx -> val files = ArrayList() try { Files.list(Paths.get("$fileHome/${ctx.splats()[0]}/")).forEach { @@ -28,7 +39,7 @@ fun main(args: Array) { app.get("/upload") { ctx -> ctx.redirect("/upload.html") } // TODO: Fix possible security issue with "../" - app.post("/upload") { ctx -> + app.post("/api/upload") { ctx -> ctx.uploadedFiles("files").forEach { (contentType, content, name, extension) -> if (ctx.queryParam("dir") !== null) { FileUtil.streamToFile(content, "files/${ctx.queryParam("dir")}/$name") diff --git a/src/main/resources/test.rocker.html b/src/main/resources/test.rocker.html new file mode 100644 index 0000000..8deedcd --- /dev/null +++ b/src/main/resources/test.rocker.html @@ -0,0 +1,2 @@ +@args (String message) +

@message

diff --git a/src/main/resources/upload.html b/src/main/resources/upload.html index 550f841..16c8a94 100644 --- a/src/main/resources/upload.html +++ b/src/main/resources/upload.html @@ -8,7 +8,7 @@ Upload Testing -
+
-- cgit v1.2.3