package online.maestoso.cofront.frontend import io.ktor.http.* import io.ktor.server.application.* import io.ktor.server.html.* import io.ktor.server.routing.* import kotlinx.css.CssBuilder import kotlinx.html.BODY import kotlinx.html.HEAD import kotlinx.html.body import kotlinx.html.head import kotlinx.html.meta import kotlinx.html.style import kotlinx.html.unsafe import online.maestoso.cofront.frontend.pages.Index import kotlin.String import kotlin.Unit abstract class Page(val path: String) { open val style: CssBuilder.() -> Unit = {} open val head: HEAD.() -> Unit = {} open val body: BODY.() -> Unit = {} fun addPage(app: Application) { app.routing { get(this@Page.path) { call.respondHtml { head { meta(charset = Charsets.UTF_8.toString()) stylesheet() favicon() js() apply(this@Page.head) val css = CssBuilder().apply(this@Page.style) unsafe { this@head.style(type = ContentType.Text.CSS.toString(), content = css.toString()) } } body { apply(this@Page.body) } } } } } } fun Application.addAllPages() { Index.addPage(this) }