Alex Fairley
02/14/2024, 3:07 PMval htmlString = buildString {
appendHTML().html {
// build html here
}
}
but the html file is getting to long for StringBuilder to handle and I am running out of java heap space. Aside from allocating more heap space to my process would another (stream based) approach work?Alex Fairley
02/15/2024, 3:56 PM<div class="a">
<div class="b">
<div class="c"></div>
<div class="c"></div>
</div>
</div>
How does appendHTML() work? Does it wait for a tag to be closed before appending or does it append everytime it encounters a new tag (the latter behaviour would be desired for my use case)Reuben Firmin
04/13/2024, 7:50 PMdata class AuxResponse(val target: HTMXTarget, val tag: TagConsumer<*>.() -> CommonAttributeGroupFacade)
fun render(target: HTMXTarget,
vararg composed: AuxResponse,
block: FlowContent.() -> Unit): Response {
which ideally users of the library could call with:
render(someTarget,
AuxResponse(someOtherTarget) {
some_adapter {
p {
+"Hello world supplemented"
}
}
)) {
p {
+"Hello world main"
}
Reuben Firmin
04/22/2024, 5:07 PMMario Palka
05/29/2024, 7:42 PMli
is unresolved reference?Kirill Gagarski
05/30/2024, 11:27 PM<label><input type=checkbox checked name=cheese disabled> Cheese</label>
I am aware about checked="checked"
or checked=""
options and how to do it with kotlinx.html, but I want the exact syntax as above in the outputAnders Sveen
06/11/2024, 12:00 PMCies
06/11/2024, 2:55 PMFormDto
. The library sets a standard for the names (the name
attribute on HTML form fields) so they can be used to provide a structure to the data.Cies
06/11/2024, 2:55 PMCies
06/11/2024, 2:56 PMAhmed
07/12/2024, 6:09 PMAhmed
07/14/2024, 2:10 AMBernhard
07/20/2024, 10:24 PMMario Andhika
08/06/2024, 2:18 AMrobnik
08/15/2024, 3:00 PM<link rel="preconnect" href="<https://fonts.gstatic.com>" crossorigin>
This guess doesn't work (crossorigin is not a parameter).
link(rel="preconnect", href="<https://fonts.gstatic.com>", crossorigin=true)
Cies
10/15/2024, 8:31 AM/** Evaluate a TemplateRenderer block into a String. Used in email rendering. */
fun stringFromHtml(renderer: TemplateRenderer): String {
return StringBuilder().apply {
append("<!DOCTYPE html>\n")
appendHTML().renderer()
}.toString()
}
/** Evaluate a TemplateRenderer block into a RePlay RenderHtml Result. <------- so this would be different for KTor! */
fun resultFromHtml(renderer: TemplateRenderer): RenderHtml {
return RenderHtml(stringFromHtml(renderer))
}
typealias TemplateRenderer = TagConsumer<*>.() -> Unit
typealias LayoutBuilder<T> = TagConsumer<*>.(data: T, renderer: TemplateRenderer) -> Unit
fun <T> layout(builder: LayoutBuilder<T>): LayoutBuilder<T> {
return { data, renderer -> builder(data, renderer) }
}
// In a render method we simply do:
fun render(input: Whatever): RenderHtml {
return resultFromHtml {
table {
tr {
+input.toString()
}
}
}
}
Cies
10/15/2024, 8:32 AMCies
10/15/2024, 8:37 AMdmcg
10/15/2024, 9:22 AMfun partial(block: FlowContent.() -> Unit): String {
val writer = StringWriter()
val consumer = writer.appendHTML()
// hacky stuff so we don't have to return a wrapper div
object : FlowContent {
override val consumer = consumer
override val attributes: MutableMap<String, String>
get() = mutableMapOf()
override val attributesEntries: Collection<Map.Entry<String, String>>
get() = emptyList()
override val emptyTag: Boolean
get() = true
override val inlineTag: Boolean
get() = true
override val namespace: String?
get() = null
override val tagName: String
get() = ""
}.block()
return writer.toString()
}
I don’t know the library well enough to choose between the approaches, but thanks giving for your experience.Tim Schraepen
10/15/2024, 12:58 PMe5l
10/16/2024, 7:07 AMReuben Firmin
10/16/2024, 11:37 AMAnders Sveen
11/13/2024, 4:28 PMReuben Firmin
12/05/2024, 3:49 PMMikael Ståldal
01/01/2025, 7:50 PMMikael Ståldal
01/03/2025, 3:24 PMe5l
01/15/2025, 12:49 PMMario Andhika
02/04/2025, 3:02 AMBernhard
03/11/2025, 12:19 PM