Skip to content

Commit 8531fec

Browse files
Added "as" attribute for Link tag (#265)
* Added "as" attribute for Link tag * Updated generated tags for code merged in from master
1 parent 43ca4ba commit 8531fec

File tree

9 files changed

+135
-9
lines changed

9 files changed

+135
-9
lines changed

buildSrc/src/main/resources/html_5.xsd

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,24 @@
495495
<xsd:attribute name="type" type="contentType"/>
496496
<xsd:attribute name="sizes"/>
497497
<xsd:attribute name="integrity" type="xsd:string"/>
498+
<xsd:attribute name="as">
499+
<xsd:simpleType>
500+
<xsd:restriction base="xsd:NMTOKEN">
501+
<xsd:enumeration value="audio"/>
502+
<xsd:enumeration value="document"/>
503+
<xsd:enumeration value="embed"/>
504+
<xsd:enumeration value="fetch"/>
505+
<xsd:enumeration value="font"/>
506+
<xsd:enumeration value="image"/>
507+
<xsd:enumeration value="object"/>
508+
<xsd:enumeration value="script"/>
509+
<xsd:enumeration value="style"/>
510+
<xsd:enumeration value="track"/>
511+
<xsd:enumeration value="video"/>
512+
<xsd:enumeration value="worker"/>
513+
</xsd:restriction>
514+
</xsd:simpleType>
515+
</xsd:attribute>
498516
</xsd:complexType>
499517
</xsd:element>
500518

src/commonMain/kotlin/generated/gen-attributes.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ internal val attributeInputTypeEnumInputTypeValues : Attribute<InputType> = Enum
4646

4747
internal val attributeKeyGenKeyTypeEnumKeyGenKeyTypeValues : Attribute<KeyGenKeyType> = EnumAttribute(keyGenKeyTypeValues)
4848

49+
internal val attributeLinkAsEnumLinkAsValues : Attribute<LinkAs> = EnumAttribute(linkAsValues)
50+
4951
internal val attributeRunAtEnumRunAtValues : Attribute<RunAt> = EnumAttribute(runAtValues)
5052

5153
internal val attributeScriptCrossoriginEnumScriptCrossoriginValues : Attribute<ScriptCrossorigin> = EnumAttribute(scriptCrossoriginValues)

src/commonMain/kotlin/generated/gen-consumer-tags.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import kotlinx.html.LABEL
8888
import kotlinx.html.LEGEND
8989
import kotlinx.html.LI
9090
import kotlinx.html.LINK
91+
import kotlinx.html.LinkAs
9192
import kotlinx.html.MAIN
9293
import kotlinx.html.MAP
9394
import kotlinx.html.MARK
@@ -938,10 +939,12 @@ public inline fun <T, C : TagConsumer<T>> C.link(
938939
href: String? = null,
939940
rel: String? = null,
940941
type: String? = null,
942+
htmlAs: LinkAs? = null,
941943
crossinline block: LINK.() -> Unit = {},
942944
): T {
943945
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
944-
return LINK(attributesMapOf("href", href,"rel", rel,"type", type), this)
946+
return LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", htmlAs?.enumEncode()),
947+
this)
945948
.visitAndFinalize(this, block)
946949
}
947950

src/commonMain/kotlin/generated/gen-enums.kt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,23 @@ object LinkType {
336336
val values : List<String> = listOf("textAsp", "textAsa", "textCss", "textHtml", "textJavaScript", "textPlain", "textScriptLet", "textXComponent", "textXHtmlInsertion", "textXml")
337337
}
338338

339+
@Suppress("unused")
340+
enum class LinkAs(override val realValue : String) : AttributeEnum {
341+
audio("audio"),
342+
document("document"),
343+
embed("embed"),
344+
fetch("fetch"),
345+
font("font"),
346+
image("image"),
347+
htmlObject("object"),
348+
script("script"),
349+
style("style"),
350+
track("track"),
351+
video("video"),
352+
worker("worker")
353+
}
354+
355+
internal val linkAsValues : Map<String, LinkAs> = LinkAs.values().associateBy { it.realValue }
339356
@Suppress("unused")
340357
object MetaHttpEquiv {
341358
val contentLanguage : String = "content-language"

src/commonMain/kotlin/generated/gen-tag-unions.kt

Lines changed: 74 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,81 @@ inline fun FlowOrMetaDataOrPhrasingContent.radioCommand(classes : String? = null
6565
*/
6666
@HtmlTagMarker
6767
@OptIn(ExperimentalContracts::class)
68-
inline fun FlowOrMetaDataOrPhrasingContent.link(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
68+
inline fun FlowOrMetaDataOrPhrasingContent.link(href : String? = null, rel : String? = null, type : String? = null, htmlAs : LinkAs? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
6969
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
70-
LINK(attributesMapOf("href", href,"rel", rel,"type", type), consumer).visit(block)
70+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", htmlAs?.enumEncode()), consumer).visit(block)
71+
}
72+
@HtmlTagMarker
73+
@OptIn(ExperimentalContracts::class)
74+
inline fun FlowOrMetaDataOrPhrasingContent.audioLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
75+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
76+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.audio.realValue), consumer).visit(block)
77+
}
78+
@HtmlTagMarker
79+
@OptIn(ExperimentalContracts::class)
80+
inline fun FlowOrMetaDataOrPhrasingContent.documentLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
81+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
82+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.document.realValue), consumer).visit(block)
83+
}
84+
@HtmlTagMarker
85+
@OptIn(ExperimentalContracts::class)
86+
inline fun FlowOrMetaDataOrPhrasingContent.embedLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
87+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
88+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.embed.realValue), consumer).visit(block)
89+
}
90+
@HtmlTagMarker
91+
@OptIn(ExperimentalContracts::class)
92+
inline fun FlowOrMetaDataOrPhrasingContent.fetchLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
93+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
94+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.fetch.realValue), consumer).visit(block)
95+
}
96+
@HtmlTagMarker
97+
@OptIn(ExperimentalContracts::class)
98+
inline fun FlowOrMetaDataOrPhrasingContent.fontLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
99+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
100+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.font.realValue), consumer).visit(block)
101+
}
102+
@HtmlTagMarker
103+
@OptIn(ExperimentalContracts::class)
104+
inline fun FlowOrMetaDataOrPhrasingContent.imageLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
105+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
106+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.image.realValue), consumer).visit(block)
107+
}
108+
@HtmlTagMarker
109+
@OptIn(ExperimentalContracts::class)
110+
inline fun FlowOrMetaDataOrPhrasingContent.htmlObjectLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
111+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
112+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.htmlObject.realValue), consumer).visit(block)
113+
}
114+
@HtmlTagMarker
115+
@OptIn(ExperimentalContracts::class)
116+
inline fun FlowOrMetaDataOrPhrasingContent.scriptLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
117+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
118+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.script.realValue), consumer).visit(block)
119+
}
120+
@HtmlTagMarker
121+
@OptIn(ExperimentalContracts::class)
122+
inline fun FlowOrMetaDataOrPhrasingContent.styleLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
123+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
124+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.style.realValue), consumer).visit(block)
125+
}
126+
@HtmlTagMarker
127+
@OptIn(ExperimentalContracts::class)
128+
inline fun FlowOrMetaDataOrPhrasingContent.trackLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
129+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
130+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.track.realValue), consumer).visit(block)
131+
}
132+
@HtmlTagMarker
133+
@OptIn(ExperimentalContracts::class)
134+
inline fun FlowOrMetaDataOrPhrasingContent.videoLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
135+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
136+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.video.realValue), consumer).visit(block)
137+
}
138+
@HtmlTagMarker
139+
@OptIn(ExperimentalContracts::class)
140+
inline fun FlowOrMetaDataOrPhrasingContent.workerLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
141+
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
142+
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.worker.realValue), consumer).visit(block)
71143
}
72144

73145
/**

src/commonMain/kotlin/generated/gen-tags-l.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ open class LINK(initialAttributes : Map<String, String>, override val consumer :
8484
get() = attributeStringString.get(this, "integrity")
8585
set(newValue) {attributeStringString.set(this, "integrity", newValue)}
8686

87+
var htmlAs : LinkAs
88+
get() = attributeLinkAsEnumLinkAsValues.get(this, "as")
89+
set(newValue) {attributeLinkAsEnumLinkAsValues.set(this, "as", newValue)}
90+
8791

8892
}
8993
val LINK.asFlowContent : FlowContent

src/jsMain/kotlin/generated/gen-consumer-tags-js.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import kotlinx.html.LABEL
8888
import kotlinx.html.LEGEND
8989
import kotlinx.html.LI
9090
import kotlinx.html.LINK
91+
import kotlinx.html.LinkAs
9192
import kotlinx.html.MAIN
9293
import kotlinx.html.MAP
9394
import kotlinx.html.MARK
@@ -992,10 +993,12 @@ public inline fun TagConsumer<HTMLElement>.link(
992993
href: String? = null,
993994
rel: String? = null,
994995
type: String? = null,
996+
htmlAs: LinkAs? = null,
995997
crossinline block: LINK.() -> Unit = {},
996998
): HTMLLinkElement {
997999
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
998-
return LINK(attributesMapOf("href", href,"rel", rel,"type", type), this)
1000+
return LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", htmlAs?.enumEncode()),
1001+
this)
9991002
.visitAndFinalize(this, block) as HTMLLinkElement
10001003
}
10011004

src/jvmTest/kotlin/streaming.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,10 +181,14 @@ class TestStreaming {
181181
}
182182

183183
@Test fun `test generated enum could be used`() {
184-
assertEquals("<link rel=\"Stylesheet\" href=\"/path\">", StringBuilder().appendHTML(false).link {
185-
rel = LinkRel.stylesheet
186-
href = "/path"
187-
}.toString())
184+
assertEquals(
185+
"<link rel=\"Stylesheet\" href=\"/path\" as=\"style\">",
186+
StringBuilder().appendHTML(false).link {
187+
rel = LinkRel.stylesheet
188+
href = "/path"
189+
htmlAs = LinkAs.style
190+
}.toString()
191+
)
188192
}
189193

190194
@Test fun `anchor with href syntax`() {

src/wasmJsMain/kotlin/generated/gen-consumer-tags-wasm-js.kt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ import kotlinx.html.LABEL
8888
import kotlinx.html.LEGEND
8989
import kotlinx.html.LI
9090
import kotlinx.html.LINK
91+
import kotlinx.html.LinkAs
9192
import kotlinx.html.MAIN
9293
import kotlinx.html.MAP
9394
import kotlinx.html.MARK
@@ -991,10 +992,12 @@ public inline fun TagConsumer<Element>.link(
991992
href: String? = null,
992993
rel: String? = null,
993994
type: String? = null,
995+
htmlAs: LinkAs? = null,
994996
crossinline block: LINK.() -> Unit = {},
995997
): HTMLLinkElement {
996998
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
997-
return LINK(attributesMapOf("href", href,"rel", rel,"type", type), this)
999+
return LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", htmlAs?.enumEncode()),
1000+
this)
9981001
.visitAndFinalize(this, block) as HTMLLinkElement
9991002
}
10001003

0 commit comments

Comments
 (0)