Does anyone have a more real-world example of the ...
# ktor
d
Does anyone have a more real-world example of the use of the HTML-DSL? Preferable with twitter bootstrap and for CRUD purposes.
👍 1
So far I have this:
Copy code
import 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?
a
Hey man. I do html with bootstrap @ http://tawktube.com/