From aac64654698340f547ae847a72c716ae7a0a3f64 Mon Sep 17 00:00:00 2001 From: ms Date: Mon, 21 Jun 2021 12:32:27 +0200 Subject: Serving a first / test Jinja page --- sandbox/build.gradle | 1 + sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt | 19 +++++++++++++++++++ sandbox/src/main/resources/templates/hello.html | 1 + 3 files changed, 21 insertions(+) create mode 100644 sandbox/src/main/resources/templates/hello.html diff --git a/sandbox/build.gradle b/sandbox/build.gradle index b7ab2234..ce04568e 100644 --- a/sandbox/build.gradle +++ b/sandbox/build.gradle @@ -44,6 +44,7 @@ def ktor_version = "1.5.0" def exposed_version = "0.25.1" dependencies { + implementation "com.hubspot.jinjava:jinjava:2.5.9" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8" implementation "ch.qos.logback:logback-classic:1.2.3" implementation group: 'javax.xml.bind', name: 'jaxb-api', version: '2.3.1' diff --git a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt index efea0410..25ef80f6 100644 --- a/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt +++ b/sandbox/src/main/kotlin/tech/libeufin/sandbox/Main.kt @@ -20,6 +20,8 @@ package tech.libeufin.sandbox +import com.hubspot.jinjava.Jinjava +import com.hubspot.jinjava.JinjavaConfig import com.fasterxml.jackson.core.JsonParseException import io.ktor.application.ApplicationCallPipeline import io.ktor.application.call @@ -63,6 +65,8 @@ import com.github.ajalt.clikt.parameters.options.default import com.github.ajalt.clikt.parameters.options.option import com.github.ajalt.clikt.parameters.options.versionOption import com.github.ajalt.clikt.parameters.types.int +import com.google.common.collect.Maps +import com.google.common.io.Resources import execThrowableOrTerminate import io.ktor.application.ApplicationCall import io.ktor.http.* @@ -87,6 +91,7 @@ import tech.libeufin.util.ebics_h004.EbicsTypes import java.net.BindException import java.util.* import kotlin.random.Random +import kotlin.reflect.jvm.internal.impl.load.kotlin.JvmType import kotlin.system.exitProcess val SANDBOX_DB_ENV_VAR_NAME = "LIBEUFIN_SANDBOX_DB_CONNECTION" @@ -290,7 +295,21 @@ fun serverMain(dbName: String, port: Int) { } } routing { + get("/jinja-test") { + val template = Resources.toString( + Resources.getResource("templates/hello.html"), + Charsets.UTF_8 + ) + val context = mapOf("token" to "dynamic") + val page = Jinjava().render(template, context) + call.respond(page) + return@get + } + static("/static") { + /** + * Here Sandbox will serve the CSS files. + */ resources("static") } diff --git a/sandbox/src/main/resources/templates/hello.html b/sandbox/src/main/resources/templates/hello.html new file mode 100644 index 00000000..70e073e2 --- /dev/null +++ b/sandbox/src/main/resources/templates/hello.html @@ -0,0 +1 @@ +Hello, I'm a Jinja '{{ token }}' page! \ No newline at end of file -- cgit v1.2.3