Skip to content

Commit

Permalink
Added HTML templates (#255)
Browse files Browse the repository at this point in the history
Added template and slot elements.

Co-authored-by: Jukka Papinkivi <jukka@papinkivi.fi>
  • Loading branch information
e5l and jpink committed Jan 23, 2024
1 parent c31e777 commit b6baa5f
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 0 deletions.
22 changes: 22 additions & 0 deletions api/kotlinx-html.api
Expand Up @@ -3367,6 +3367,8 @@ public final class kotlinx/html/Gen_consumer_tagsKt {
public static synthetic fun section$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun select (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static synthetic fun select$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun slot (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static synthetic fun slot$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun small (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static synthetic fun small$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun source (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
Expand Down Expand Up @@ -3395,6 +3397,8 @@ public final class kotlinx/html/Gen_consumer_tagsKt {
public static synthetic fun tbody$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun td (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static synthetic fun td$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun template (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static synthetic fun template$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object;
public static final fun textArea (Lkotlinx/html/TagConsumer;Ljava/lang/String;Ljava/lang/String;Lkotlinx/html/TextAreaWrap;Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;
public static final fun textArea (Lkotlinx/html/TagConsumer;Ljava/lang/String;Ljava/lang/String;Lkotlinx/html/TextAreaWrap;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
public static synthetic fun textArea$default (Lkotlinx/html/TagConsumer;Ljava/lang/String;Ljava/lang/String;Lkotlinx/html/TextAreaWrap;Ljava/lang/String;Ljava/lang/String;ILjava/lang/Object;)Ljava/lang/Object;
Expand Down Expand Up @@ -3466,10 +3470,14 @@ public final class kotlinx/html/Gen_tag_groupsKt {
public static synthetic fun putForm$default (Lkotlinx/html/FlowContent;Ljava/lang/String;Lkotlinx/html/FormEncType;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun s (Lkotlinx/html/FlowContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun s$default (Lkotlinx/html/FlowContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun slot (Lkotlinx/html/PhrasingContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun slot$default (Lkotlinx/html/PhrasingContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun summary (Lkotlinx/html/FlowContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun summary$default (Lkotlinx/html/FlowContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun table (Lkotlinx/html/FlowContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun table$default (Lkotlinx/html/FlowContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun template (Lkotlinx/html/PhrasingContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun template$default (Lkotlinx/html/PhrasingContent;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun title (Lkotlinx/html/MetaDataContent;Ljava/lang/String;)V
public static final fun title (Lkotlinx/html/MetaDataContent;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun title$default (Lkotlinx/html/MetaDataContent;Ljava/lang/String;ILjava/lang/Object;)V
Expand Down Expand Up @@ -3990,9 +3998,11 @@ public final class kotlinx/html/Gen_tags_tKt {
public static synthetic fun colGroupTh$default (Lkotlinx/html/TR;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun colTh (Lkotlinx/html/TR;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
public static synthetic fun colTh$default (Lkotlinx/html/TR;Ljava/lang/String;Lkotlin/jvm/functions/Function1;ILjava/lang/Object;)V
public static final fun getAsFlowContent (Lkotlinx/html/TEMPLATE;)Lkotlinx/html/FlowContent;
public static final fun getAsFlowContent (Lkotlinx/html/TEXTAREA;)Lkotlinx/html/FlowContent;
public static final fun getAsFlowContent (Lkotlinx/html/TIME;)Lkotlinx/html/FlowContent;
public static final fun getAsInteractiveContent (Lkotlinx/html/TEXTAREA;)Lkotlinx/html/InteractiveContent;
public static final fun getAsPhrasingContent (Lkotlinx/html/TEMPLATE;)Lkotlinx/html/PhrasingContent;
public static final fun getAsPhrasingContent (Lkotlinx/html/TEXTAREA;)Lkotlinx/html/PhrasingContent;
public static final fun getAsPhrasingContent (Lkotlinx/html/TIME;)Lkotlinx/html/PhrasingContent;
public static final fun rowGroupTh (Lkotlinx/html/TR;Ljava/lang/String;Lkotlin/jvm/functions/Function1;)V
Expand Down Expand Up @@ -4830,6 +4840,13 @@ public class kotlinx/html/SELECT : kotlinx/html/HTMLTag, kotlinx/html/CommonAttr
public final fun setSize (Ljava/lang/String;)V
}

public class kotlinx/html/SLOT : kotlinx/html/HTMLTag, kotlinx/html/HtmlInlineTag {
public fun <init> (Ljava/util/Map;Lkotlinx/html/TagConsumer;)V
public fun getConsumer ()Lkotlinx/html/TagConsumer;
public final fun getName ()Ljava/lang/String;
public final fun setName (Ljava/lang/String;)V
}

public class kotlinx/html/SMALL : kotlinx/html/HTMLTag, kotlinx/html/HtmlBlockInlineTag {
public fun <init> (Ljava/util/Map;Lkotlinx/html/TagConsumer;)V
public fun getConsumer ()Lkotlinx/html/TagConsumer;
Expand Down Expand Up @@ -4999,6 +5016,11 @@ public class kotlinx/html/TD : kotlinx/html/HTMLTag, kotlinx/html/HtmlBlockTag {
public final fun setRowSpan (Ljava/lang/String;)V
}

public class kotlinx/html/TEMPLATE : kotlinx/html/HTMLTag, kotlinx/html/HtmlBlockInlineTag {
public fun <init> (Ljava/util/Map;Lkotlinx/html/TagConsumer;)V
public fun getConsumer ()Lkotlinx/html/TagConsumer;
}

public class kotlinx/html/TEXTAREA : kotlinx/html/HTMLTag, kotlinx/html/CommonAttributeGroupFacadeFlowInteractivePhrasingContent {
public fun <init> (Ljava/util/Map;Lkotlinx/html/TagConsumer;)V
public final fun getAutoFocus ()Z
Expand Down
22 changes: 22 additions & 0 deletions buildSrc/src/main/resources/html_5.xsd
Expand Up @@ -207,6 +207,7 @@
<xsd:element ref="noscript"/>
<xsd:element ref="script"/>
<xsd:element ref="style"/>
<!-- Excluding template element here because it will allow phrasing content here. -->
<xsd:element ref="title" minOccurs="1" maxOccurs="1"/>
</xsd:choice>
</xsd:group>
Expand Down Expand Up @@ -403,13 +404,15 @@
<xsd:element ref="samp"/>
<xsd:element ref="script"/>
<xsd:element ref="select"/>
<xsd:element ref="slot"/>
<xsd:element ref="small"/>
<xsd:element ref="span"/>
<xsd:element ref="strong"/>
<xsd:element ref="sub"/>
<xsd:element ref="sup"/>
<xsd:element ref="svg"/>

<xsd:element ref="template"/>
<xsd:element ref="textarea"/>
<xsd:element ref="time"/>

Expand Down Expand Up @@ -634,6 +637,25 @@
</xsd:complexType>
</xsd:element>

<xsd:element name="template">
<xsd:complexType mixed="true">
<xsd:choice>
<xsd:group ref="flowContent"/>
</xsd:choice>
<xsd:attributeGroup ref="commonAttributeGroup"/>
</xsd:complexType>
</xsd:element>

<xsd:element name="slot">
<xsd:complexType mixed="true">
<xsd:choice>
<xsd:group ref="phrasingContent"/>
</xsd:choice>
<xsd:attributeGroup ref="commonAttributeGroup"/>
<xsd:attribute name="name"/>
</xsd:complexType>
</xsd:element>

<!--=================== Document Body ====================================-->

<xsd:element name="body">
Expand Down
15 changes: 15 additions & 0 deletions src/commonMain/kotlin/generated/gen-consumer-tags.kt
Expand Up @@ -113,6 +113,7 @@ import kotlinx.html.SAMP
import kotlinx.html.SCRIPT
import kotlinx.html.SECTION
import kotlinx.html.SELECT
import kotlinx.html.SLOT
import kotlinx.html.SMALL
import kotlinx.html.SOURCE
import kotlinx.html.SPAN
Expand All @@ -126,6 +127,7 @@ import kotlinx.html.ScriptCrossorigin
import kotlinx.html.TABLE
import kotlinx.html.TBODY
import kotlinx.html.TD
import kotlinx.html.TEMPLATE
import kotlinx.html.TEXTAREA
import kotlinx.html.TFOOT
import kotlinx.html.TH
Expand Down Expand Up @@ -965,6 +967,11 @@ public inline fun <T, C : TagConsumer<T>> C.select(classes: String? = null, cros
block: SELECT.() -> Unit = {}): T = SELECT(attributesMapOf("class", classes), this)
.visitAndFinalize(this, block)

@HtmlTagMarker
public inline fun <T, C : TagConsumer<T>> C.slot(classes: String? = null, crossinline
block: SLOT.() -> Unit = {}): T = SLOT(attributesMapOf("class", classes), this)
.visitAndFinalize(this, block)

/**
* Small text style
*/
Expand Down Expand Up @@ -1073,6 +1080,14 @@ public inline fun <T, C : TagConsumer<T>> C.td(classes: String? = null, crossinl
block: TD.() -> Unit = {}): T = TD(attributesMapOf("class", classes), this)
.visitAndFinalize(this, block)

/**
* Template
*/
@HtmlTagMarker
public inline fun <T, C : TagConsumer<T>> C.template(classes: String? = null, crossinline
block: TEMPLATE.() -> Unit = {}): T = TEMPLATE(attributesMapOf("class", classes), this)
.visitAndFinalize(this, block)

/**
* Multi-line text field
*/
Expand Down
9 changes: 9 additions & 0 deletions src/commonMain/kotlin/generated/gen-tag-groups.kt
Expand Up @@ -177,3 +177,12 @@ inline fun MetaDataContent.title(crossinline block : TITLE.() -> Unit = {}) : Un
@HtmlTagMarker
fun MetaDataContent.title(content : String = "") : Unit = TITLE(emptyMap, consumer).visit({+content})

@HtmlTagMarker
inline fun PhrasingContent.slot(classes : String? = null, crossinline block : SLOT.() -> Unit = {}) : Unit = SLOT(attributesMapOf("class", classes), consumer).visit(block)

/**
* Template
*/
@HtmlTagMarker
inline fun PhrasingContent.template(classes : String? = null, crossinline block : TEMPLATE.() -> Unit = {}) : Unit = TEMPLATE(attributesMapOf("class", classes), consumer).visit(block)

9 changes: 9 additions & 0 deletions src/commonMain/kotlin/generated/gen-tags-s.kt
Expand Up @@ -171,6 +171,15 @@ val SELECT.asPhrasingContent : PhrasingContent
get() = this


@Suppress("unused")
open class SLOT(initialAttributes : Map<String, String>, override val consumer : TagConsumer<*>) : HTMLTag("slot", consumer, initialAttributes, null, false, false), HtmlInlineTag {
var name : String
get() = attributeStringString.get(this, "name")
set(newValue) {attributeStringString.set(this, "name", newValue)}


}

@Suppress("unused")
open class SMALL(initialAttributes : Map<String, String>, override val consumer : TagConsumer<*>) : HTMLTag("small", consumer, initialAttributes, null, true, false), HtmlBlockInlineTag {

Expand Down
11 changes: 11 additions & 0 deletions src/commonMain/kotlin/generated/gen-tags-t.kt
Expand Up @@ -82,6 +82,17 @@ open class TD(initialAttributes : Map<String, String>, override val consumer : T

}

@Suppress("unused")
open class TEMPLATE(initialAttributes : Map<String, String>, override val consumer : TagConsumer<*>) : HTMLTag("template", consumer, initialAttributes, null, false, false), HtmlBlockInlineTag {

}
val TEMPLATE.asFlowContent : FlowContent
get() = this

val TEMPLATE.asPhrasingContent : PhrasingContent
get() = this


@Suppress("unused")
open class TEXTAREA(initialAttributes : Map<String, String>, override val consumer : TagConsumer<*>) : HTMLTag("textarea", consumer, initialAttributes, null, true, false), CommonAttributeGroupFacadeFlowInteractivePhrasingContent {
var autoFocus : Boolean
Expand Down
17 changes: 17 additions & 0 deletions src/jsMain/kotlin/generated/gen-consumer-tags-js.kt
Expand Up @@ -113,6 +113,7 @@ import kotlinx.html.SAMP
import kotlinx.html.SCRIPT
import kotlinx.html.SECTION
import kotlinx.html.SELECT
import kotlinx.html.SLOT
import kotlinx.html.SMALL
import kotlinx.html.SOURCE
import kotlinx.html.SPAN
Expand All @@ -126,6 +127,7 @@ import kotlinx.html.ScriptCrossorigin
import kotlinx.html.TABLE
import kotlinx.html.TBODY
import kotlinx.html.TD
import kotlinx.html.TEMPLATE
import kotlinx.html.TEXTAREA
import kotlinx.html.TFOOT
import kotlinx.html.TH
Expand Down Expand Up @@ -187,6 +189,7 @@ import org.w3c.dom.HTMLTableColElement
import org.w3c.dom.HTMLTableElement
import org.w3c.dom.HTMLTableRowElement
import org.w3c.dom.HTMLTableSectionElement
import org.w3c.dom.HTMLTemplateElement
import org.w3c.dom.HTMLTextAreaElement
import org.w3c.dom.HTMLTimeElement
import org.w3c.dom.HTMLTitleElement
Expand Down Expand Up @@ -1032,6 +1035,11 @@ public inline fun TagConsumer<HTMLElement>.select(classes: String? = null, cross
this)
.visitAndFinalize(this, block) as HTMLSelectElement

@HtmlTagMarker
public inline fun TagConsumer<HTMLElement>.slot(classes: String? = null, crossinline
block: SLOT.() -> Unit = {}): HTMLElement = SLOT(attributesMapOf("class", classes), this)
.visitAndFinalize(this, block)

/**
* Small text style
*/
Expand Down Expand Up @@ -1142,6 +1150,15 @@ public inline fun TagConsumer<HTMLElement>.td(classes: String? = null, crossinli
block: TD.() -> Unit = {}): HTMLTableCellElement = TD(attributesMapOf("class", classes), this)
.visitAndFinalize(this, block) as HTMLTableCellElement

/**
* Template
*/
@HtmlTagMarker
public inline fun TagConsumer<HTMLElement>.template(classes: String? = null, crossinline
block: TEMPLATE.() -> Unit = {}): HTMLTemplateElement = TEMPLATE(attributesMapOf("class",
classes), this)
.visitAndFinalize(this, block) as HTMLTemplateElement

/**
* Multi-line text field
*/
Expand Down
10 changes: 10 additions & 0 deletions src/jsTest/kotlin/generated/gen-tag-tests.kt
Expand Up @@ -453,6 +453,11 @@ public class JsTagCastTests {
wrapper().select {}
}

@test
public fun testSlot() {
wrapper().slot {}
}

@test
public fun testSmall() {
wrapper().small {}
Expand Down Expand Up @@ -513,6 +518,11 @@ public class JsTagCastTests {
wrapper().td {}
}

@test
public fun testTemplate() {
wrapper().template {}
}

@test
public fun testTextArea() {
wrapper().textArea {}
Expand Down
17 changes: 17 additions & 0 deletions src/wasmJsMain/kotlin/generated/gen-consumer-tags-wasm-js.kt
Expand Up @@ -113,6 +113,7 @@ import kotlinx.html.SAMP
import kotlinx.html.SCRIPT
import kotlinx.html.SECTION
import kotlinx.html.SELECT
import kotlinx.html.SLOT
import kotlinx.html.SMALL
import kotlinx.html.SOURCE
import kotlinx.html.SPAN
Expand All @@ -126,6 +127,7 @@ import kotlinx.html.ScriptCrossorigin
import kotlinx.html.TABLE
import kotlinx.html.TBODY
import kotlinx.html.TD
import kotlinx.html.TEMPLATE
import kotlinx.html.TEXTAREA
import kotlinx.html.TFOOT
import kotlinx.html.TH
Expand Down Expand Up @@ -187,6 +189,7 @@ import org.w3c.dom.HTMLTableColElement
import org.w3c.dom.HTMLTableElement
import org.w3c.dom.HTMLTableRowElement
import org.w3c.dom.HTMLTableSectionElement
import org.w3c.dom.HTMLTemplateElement
import org.w3c.dom.HTMLTextAreaElement
import org.w3c.dom.HTMLTimeElement
import org.w3c.dom.HTMLTitleElement
Expand Down Expand Up @@ -1030,6 +1033,11 @@ public inline fun TagConsumer<Element>.select(classes: String? = null, crossinli
this)
.visitAndFinalize(this, block) as HTMLSelectElement

@HtmlTagMarker
public inline fun TagConsumer<Element>.slot(classes: String? = null, crossinline
block: SLOT.() -> Unit = {}): Element = SLOT(attributesMapOf("class", classes), this)
.visitAndFinalize(this, block)

/**
* Small text style
*/
Expand Down Expand Up @@ -1140,6 +1148,15 @@ public inline fun TagConsumer<Element>.td(classes: String? = null, crossinline b
= {}): HTMLTableCellElement = TD(attributesMapOf("class", classes), this)
.visitAndFinalize(this, block) as HTMLTableCellElement

/**
* Template
*/
@HtmlTagMarker
public inline fun TagConsumer<Element>.template(classes: String? = null, crossinline
block: TEMPLATE.() -> Unit = {}): HTMLTemplateElement = TEMPLATE(attributesMapOf("class",
classes), this)
.visitAndFinalize(this, block) as HTMLTemplateElement

/**
* Multi-line text field
*/
Expand Down
10 changes: 10 additions & 0 deletions src/wasmJsTest/kotlin/generated/gen-tag-tests.kt
Expand Up @@ -453,6 +453,11 @@ public class JsTagCastTests {
wrapper().select {}
}

@test
public fun testSlot() {
wrapper().slot {}
}

@test
public fun testSmall() {
wrapper().small {}
Expand Down Expand Up @@ -513,6 +518,11 @@ public class JsTagCastTests {
wrapper().td {}
}

@test
public fun testTemplate() {
wrapper().template {}
}

@test
public fun testTextArea() {
wrapper().textArea {}
Expand Down

0 comments on commit b6baa5f

Please sign in to comment.