dave08
11/11/2018, 12:20 PMdave08
11/11/2018, 3:23 PMimport io.ktor.html.*
import kotlinx.html.*
interface BaseTemplate: Template<HTML> {
val content: Placeholder<FlowContent>
}
class BootstrapBaseTemplate(
private val cssUrls: List<String> = emptyList(),
private val scriptUrls: List<String> = emptyList()
) : BaseTemplate {
override val content = Placeholder<FlowContent>()
override fun HTML.apply() {
lang = "en"
head {
meta(charset = "utf-8")
meta("viewport", content = "width=device-width, initial-scale=1, shrink-to-fit=no")
link {
rel = LinkRel.stylesheet
type = LinkType.textCss
href = "<https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css>"
attributes["integrity"] = "sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO"
attributes["crossorigin"] = "anonymous"
}
cssUrls.forEach { styleLink(it) }
scriptUrls.forEach { script(ScriptType.textJavaScript, it) {} }
}
body {
div("container") {
insert(content)
}
}
}
}
class NAV(initialAttributes: Map<String, String>, consumer: TagConsumer<*>) :
HTMLTag("nav", consumer, initialAttributes, null,false,false), HtmlBlockTag {
}
@HtmlTagMarker
fun FlowContent.nav(classes: String?, block: NAV.() -> Unit = {}) {
NAV(attributesMapOf("class", classes), consumer).visit(block)
}
But maybe someone already did all this?adeln
11/12/2018, 8:11 AM