Simplest and small Kotlin HTML DSL library ever. Supports HTML5 standard (and some obsolete HTML4 tags according to that page)
3 artifact versions are available:
-
1.0.PLUS
- Stateless PLUS API: operator+
allow concat two or more siblings in same parent -
1.0.DOM
- Stateful DOM API: functiontext
and propertyinnerHTML
-
1.0.ALL
- Both APIs
repositories {
jcenter() // available in bintray jcenter
// or:
mavenCentral() // also available in maven central
}
dependencies {
compile "com.github.daggerok:kotlin-html-dsl:1.0.ALL"
}
<dependencies>
<dependency>
<groupId>com.github.daggerok</groupId>
<artifactId>kotlin-html-dsl</artifactId>
<version>1.0.ALL</version>
</dependency>
</dependencies>
<!-- only if you want use bintray jcetner -->
<repositories>
<repository>
<id>jcentral</id>
<url>https://jcenter.bintray.com</url>
</repository>
</repositories>
text
function:import daggerok.extensions.html.dom.*
fun main(args: Array<String>) {
println(
html("lang" to "en") {
head {
meta("charset" to "UTF-8")
title {
text("Kotlin HTML DSL")
}
}
body {
h1 {
text("Hello, World!")
}
}
}
)
}
import daggerok.extensions.html.dom.*
fun main(args: Array<String>) {
println(
html("lang" to "en") {
head {
meta("charset" to "UTF-8")
title {
innerHTML += "Kotlin HTML DSL"
}
}
body {
h1 {
innerHTML += "Hello, World!"
}
}
}
)
}
+
operator:import daggerok.extensions.html.plus.*
fun main(args: Array<String>) {
println(
html("lang" to "en") {
head {
meta("charset" to "UTF-8")+
title {
"Kotlin HTML DSL"
}
}+
body {
h1 {
"Hello, World!"
}
}
}
)
}
<!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='UTF-8'/>
<title>Kotlin HTML DSL</title>
</head>
<body>
<h1>Hello, World!</h1>
</body>
</html>
The following tags are supported in HTML5 (and/or the WHATWG HTML Living Standard):
a abbr address area article aside audio b base bdi bdo blockquote body br button canvas caption cite code col colgroup data datalist dd del details dfn dialog div dl dt em embed fieldset figcaption figure footer form h1 h2 h3 h4 h5 h6 head header hgroup hr html i iframe img input ins kbd keygen label legend li link main map mark menu menuitem meta meter nav noscript object ol optgroup option output p param pre progress q rb rp rt rtc ruby s samp script section select small source span strong style sub summary sup table tbody td template textarea tfoot th thead time title tr track u ul var video wbr
repositories {
maven { url "https://dl.bintray.com/daggerok/daggerok" }
}
dependencies {
compile "com.github.daggerok:kotlin-html-dsl:1.0.ALL"
}
<repositories>
<repository>
<id>bintray-daggerok-daggerok</id>
<url>https://dl.bintray.com/daggerok/daggerok</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.daggerok</groupId>
<artifactId>kotlin-html-dsl</artifactId>
<version>1.0.ALL</version>
</dependency>
</dependencies>
repositories {
maven { url "https://jitpack.io" }
}
dependencies {
compile "com.github.daggerok:kotlin-html-dsl:1.0.ALL"
}
Feel free extend and contribute to add more functionality. Personally I’d like to keep it simple as possible, but my Kotlin knowledge not yet good enough. So if you can improve it or make it more DSL-ish — please, create PR
# maven: ./mvnw # or gradle: ./gradlew
generated by jvm yeoman generator
links: