File tree Expand file tree Collapse file tree 2 files changed +24
-17
lines changed
cli/src/main/kotlin/dev/fishies/coho/cli
core/src/main/kotlin/dev/fishies/coho Expand file tree Collapse file tree 2 files changed +24
-17
lines changed Original file line number Diff line number Diff line change @@ -2,13 +2,18 @@ package dev.fishies.coho.cli
22
33import dev.fishies.coho.Element
44import dev.fishies.coho.RootPath
5+ import dev.fishies.coho.cdata
56import dev.fishies.coho.core.*
7+ import dev.fishies.coho.invoke
68import io.ktor.server.engine.*
79import io.ktor.server.netty.*
10+ import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml.cdata
811import kotlinx.cli.*
912import kotlinx.coroutines.flow.MutableStateFlow
1013import java.net.BindException
1114import java.nio.file.*
15+ import java.time.ZoneOffset
16+ import java.time.format.DateTimeFormatter
1217import java.util.concurrent.TimeUnit
1318import kotlin.concurrent.atomics.AtomicBoolean
1419import kotlin.concurrent.atomics.ExperimentalAtomicApi
Original file line number Diff line number Diff line change @@ -6,6 +6,14 @@ fun StringBuilder.cdata(configure: StringBuilder.() -> Unit = {}) {
66 append(" ]]>" )
77}
88
9+ fun StringBuilder.doctype () {
10+ append(" <!doctype html>" )
11+ }
12+
13+ fun StringBuilder.prolog (version : String = "1.0", encoding : String = "UTF -8") {
14+ append(" <?xml version=\" $version \" encoding=\" $encoding \" ?>" )
15+ }
16+
917/* *
1018 * Append an XML tag with the name of [this] to [builder].
1119 *
@@ -35,21 +43,15 @@ context(builder: StringBuilder) operator fun String.invoke(
3543/* *
3644 * Create a new XML builder context.
3745 *
38- * ```kotlin
39- * "html" {
40- * "body" {
41- * "h1"("class" to "hi") {
42- * append("hi")
43- * }
44- * }
45- * }
46- * ```
47- * gives
48- * ```xml
49- * <html ><body ><h1 class="hi">hi</h1></body></html>
50- * ```
46+ * @see html
47+ * @see invoke
48+ */
49+ fun xml (inner : StringBuilder .() -> Unit = {}) = StringBuilder ().apply { inner() }.toString()
50+
51+ /* *
52+ * Create a new XML builder context.
53+ *
54+ * @see xml
55+ * @see invoke
5156 */
52- operator fun String.invoke (vararg attributes : Pair <String , Any ?>, inner : StringBuilder .() -> Unit = {}) =
53- with (StringBuilder ()) {
54- this @invoke(* attributes, inner = inner)
55- }.toString()
57+ fun html (inner : StringBuilder .() -> Unit = {}) = StringBuilder ().apply { inner() }.toString()
You can’t perform that action at this time.
0 commit comments