backend migrated to Java 17
This commit is contained in:
11
jpacrepo-frontend/build.gradle
Normal file
11
jpacrepo-frontend/build.gradle
Normal file
@@ -0,0 +1,11 @@
|
||||
plugins {
|
||||
alias(catalog.plugins.kotlin.multiplatform)
|
||||
}
|
||||
|
||||
kotlin {
|
||||
js(IR) {
|
||||
browser {
|
||||
}
|
||||
binaries.executable()
|
||||
}
|
||||
}
|
@@ -0,0 +1,70 @@
|
||||
package net.woggioni.jpacrepo
|
||||
|
||||
import org.w3c.dom.Document
|
||||
import org.w3c.dom.Element
|
||||
|
||||
|
||||
class HtmlBuilder private constructor(private val doc : Document, val el: Element) {
|
||||
|
||||
companion object {
|
||||
fun <T> of(doc : Document, el: Element, cb : HtmlBuilder.(el : Element) -> T) : T {
|
||||
return HtmlBuilder(doc, el).cb(el)
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <T> dfd(
|
||||
name : String,
|
||||
attrs : Map<String, String>,
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T {
|
||||
val child = doc.createElement(name)
|
||||
for((key, value) in attrs) {
|
||||
child.setAttribute(key, value)
|
||||
}
|
||||
el.appendChild(child)
|
||||
return HtmlBuilder(doc, child).cb(child)
|
||||
}
|
||||
|
||||
fun <T> html(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("html", attrs, cb)
|
||||
fun <T> head(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("head", attrs, cb)
|
||||
fun <T> body(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("body", attrs, cb)
|
||||
|
||||
fun <T> div(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("div", attrs, cb)
|
||||
fun <T> header(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("header", attrs, cb)
|
||||
fun <T> main(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("main", attrs, cb)
|
||||
fun <T> footer(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("footer", attrs, cb)
|
||||
fun <T> a(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("a", attrs, cb)
|
||||
fun <T> meta(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("meta", attrs, cb)
|
||||
fun <T> script(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("script", attrs, cb)
|
||||
fun <T> link(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("link", attrs, cb)
|
||||
fun <T> title(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("title", attrs, cb)
|
||||
fun <T> p(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("p", attrs, cb)
|
||||
|
||||
fun <T> h1(attrs : Map<String, String> = emptyMap(),
|
||||
cb : HtmlBuilder.(el : Element) -> T) : T = dfd("h1", attrs, cb)
|
||||
|
||||
|
||||
fun classes(vararg classes : String) {
|
||||
for(cls in classes) el.classList.add(cls)
|
||||
}
|
||||
|
||||
fun attr(key: String, value : String) {
|
||||
el.setAttribute(key, value)
|
||||
}
|
||||
|
||||
fun text(txt : String) {
|
||||
el.textContent = txt
|
||||
}
|
||||
}
|
@@ -0,0 +1,61 @@
|
||||
package net.woggioni.jpacrepo
|
||||
|
||||
import kotlinx.browser.document
|
||||
import net.woggioni.jpacrepo.Component.container
|
||||
import org.w3c.dom.HTMLElement
|
||||
|
||||
|
||||
object Component {
|
||||
val container = document.getElementById("container") as HTMLElement
|
||||
|
||||
fun sayHelloViaDom() {
|
||||
container.textContent = "Hello, DOM! Kotlin is writing…"
|
||||
}
|
||||
}
|
||||
|
||||
fun main(vararg args: String) {
|
||||
// println("JavaScript generated through Kotlin")
|
||||
//
|
||||
// Component.sayHelloViaDom()
|
||||
// sayHelloViaJsConsole()
|
||||
// sayHelloViaInlinedJavaScript()
|
||||
|
||||
HtmlBuilder.of(document, document.body as HTMLElement) {
|
||||
classes("d-flex", "h-100", "text-center", "text-white", "bg-dark")
|
||||
div {
|
||||
classes("cover-container", "d-flex", "w-100", "h-100", "p-3", "mx-auto", "flex-column")
|
||||
|
||||
}
|
||||
header {
|
||||
classes("mb-auto")
|
||||
}
|
||||
main {
|
||||
classes("px-3")
|
||||
h1 {
|
||||
text("Cover your page.")
|
||||
}
|
||||
p {
|
||||
classes("lead")
|
||||
text("Cover is a one-page template for building simple and beautiful home pages. Download, edit the text, and add your own fullscreen background photo to make it your own.")
|
||||
}
|
||||
p {
|
||||
classes("lead")
|
||||
a {
|
||||
classes("btn", "btn-lg", "btn-secondary", "fw-bold", "border-white", "bg-white")
|
||||
text("Learn more")
|
||||
}
|
||||
}
|
||||
}
|
||||
footer {
|
||||
classes("mt-auto", "text-white-50")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun sayHelloViaJsConsole() {
|
||||
console.log("Hello from `console.log()`!")
|
||||
}
|
||||
|
||||
private fun sayHelloViaInlinedJavaScript() {
|
||||
js("document.writeln('Hello, from inlined JavaScript in Kotlin!')")
|
||||
}
|
10
jpacrepo-frontend/src/main/resources/index.html
Normal file
10
jpacrepo-frontend/src/main/resources/index.html
Normal file
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>
|
||||
<script src="jpacrepo-frontend.js" defer="true"></script>
|
||||
<title>Hello World!</title>
|
||||
</html>
|
Reference in New Issue
Block a user