Skip to content

Commit 7b3b4af

Browse files
committed
fix some silly issues
1 parent af93728 commit 7b3b4af

File tree

2 files changed

+24
-17
lines changed
  • cli/src/main/kotlin/dev/fishies/coho/cli
  • core/src/main/kotlin/dev/fishies/coho

2 files changed

+24
-17
lines changed

cli/src/main/kotlin/dev/fishies/coho/cli/Main.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ package dev.fishies.coho.cli
22

33
import dev.fishies.coho.Element
44
import dev.fishies.coho.RootPath
5+
import dev.fishies.coho.cdata
56
import dev.fishies.coho.core.*
7+
import dev.fishies.coho.invoke
68
import io.ktor.server.engine.*
79
import io.ktor.server.netty.*
10+
import jdk.javadoc.internal.doclets.formats.html.markup.RawHtml.cdata
811
import kotlinx.cli.*
912
import kotlinx.coroutines.flow.MutableStateFlow
1013
import java.net.BindException
1114
import java.nio.file.*
15+
import java.time.ZoneOffset
16+
import java.time.format.DateTimeFormatter
1217
import java.util.concurrent.TimeUnit
1318
import kotlin.concurrent.atomics.AtomicBoolean
1419
import kotlin.concurrent.atomics.ExperimentalAtomicApi

core/src/main/kotlin/dev/fishies/coho/XmlDsl.kt

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff 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()

0 commit comments

Comments
 (0)