Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added "as" attribute for Link tag #265

Merged
merged 3 commits into from May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions buildSrc/src/main/resources/html_5.xsd
Expand Up @@ -495,6 +495,24 @@
<xsd:attribute name="type" type="contentType"/>
<xsd:attribute name="sizes"/>
<xsd:attribute name="integrity" type="xsd:string"/>
<xsd:attribute name="as">
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="audio"/>
<xsd:enumeration value="document"/>
<xsd:enumeration value="embed"/>
<xsd:enumeration value="fetch"/>
<xsd:enumeration value="font"/>
<xsd:enumeration value="image"/>
<xsd:enumeration value="object"/>
<xsd:enumeration value="script"/>
<xsd:enumeration value="style"/>
<xsd:enumeration value="track"/>
<xsd:enumeration value="video"/>
<xsd:enumeration value="worker"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
</xsd:complexType>
</xsd:element>

Expand Down
2 changes: 2 additions & 0 deletions src/commonMain/kotlin/generated/gen-attributes.kt
Expand Up @@ -46,6 +46,8 @@ internal val attributeInputTypeEnumInputTypeValues : Attribute<InputType> = Enum

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

internal val attributeLinkAsEnumLinkAsValues : Attribute<LinkAs> = EnumAttribute(linkAsValues)

internal val attributeRunAtEnumRunAtValues : Attribute<RunAt> = EnumAttribute(runAtValues)

internal val attributeScriptCrossoriginEnumScriptCrossoriginValues : Attribute<ScriptCrossorigin> = EnumAttribute(scriptCrossoriginValues)
Expand Down
5 changes: 4 additions & 1 deletion src/commonMain/kotlin/generated/gen-consumer-tags.kt
Expand Up @@ -88,6 +88,7 @@ import kotlinx.html.LABEL
import kotlinx.html.LEGEND
import kotlinx.html.LI
import kotlinx.html.LINK
import kotlinx.html.LinkAs
import kotlinx.html.MAIN
import kotlinx.html.MAP
import kotlinx.html.MARK
Expand Down Expand Up @@ -938,10 +939,12 @@ public inline fun <T, C : TagConsumer<T>> C.link(
href: String? = null,
rel: String? = null,
type: String? = null,
htmlAs: LinkAs? = null,
crossinline block: LINK.() -> Unit = {},
): T {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return LINK(attributesMapOf("href", href,"rel", rel,"type", type), this)
return LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", htmlAs?.enumEncode()),
this)
.visitAndFinalize(this, block)
}

Expand Down
17 changes: 17 additions & 0 deletions src/commonMain/kotlin/generated/gen-enums.kt
Expand Up @@ -336,6 +336,23 @@ object LinkType {
val values : List<String> = listOf("textAsp", "textAsa", "textCss", "textHtml", "textJavaScript", "textPlain", "textScriptLet", "textXComponent", "textXHtmlInsertion", "textXml")
}

@Suppress("unused")
enum class LinkAs(override val realValue : String) : AttributeEnum {
audio("audio"),
document("document"),
embed("embed"),
fetch("fetch"),
font("font"),
image("image"),
htmlObject("object"),
script("script"),
style("style"),
track("track"),
video("video"),
worker("worker")
}

internal val linkAsValues : Map<String, LinkAs> = LinkAs.values().associateBy { it.realValue }
@Suppress("unused")
object MetaHttpEquiv {
val contentLanguage : String = "content-language"
Expand Down
76 changes: 74 additions & 2 deletions src/commonMain/kotlin/generated/gen-tag-unions.kt
Expand Up @@ -65,9 +65,81 @@ inline fun FlowOrMetaDataOrPhrasingContent.radioCommand(classes : String? = null
*/
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.link(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
inline fun FlowOrMetaDataOrPhrasingContent.link(href : String? = null, rel : String? = null, type : String? = null, htmlAs : LinkAs? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type), consumer).visit(block)
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", htmlAs?.enumEncode()), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.audioLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.audio.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.documentLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.document.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.embedLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.embed.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.fetchLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.fetch.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.fontLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.font.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.imageLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.image.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.htmlObjectLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.htmlObject.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.scriptLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.script.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.styleLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.style.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.trackLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.track.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.videoLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.video.realValue), consumer).visit(block)
}
@HtmlTagMarker
@OptIn(ExperimentalContracts::class)
inline fun FlowOrMetaDataOrPhrasingContent.workerLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.worker.realValue), consumer).visit(block)
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/commonMain/kotlin/generated/gen-tags-l.kt
Expand Up @@ -84,6 +84,10 @@ open class LINK(initialAttributes : Map<String, String>, override val consumer :
get() = attributeStringString.get(this, "integrity")
set(newValue) {attributeStringString.set(this, "integrity", newValue)}

var htmlAs : LinkAs
get() = attributeLinkAsEnumLinkAsValues.get(this, "as")
set(newValue) {attributeLinkAsEnumLinkAsValues.set(this, "as", newValue)}


}
val LINK.asFlowContent : FlowContent
Expand Down
5 changes: 4 additions & 1 deletion src/jsMain/kotlin/generated/gen-consumer-tags-js.kt
Expand Up @@ -88,6 +88,7 @@ import kotlinx.html.LABEL
import kotlinx.html.LEGEND
import kotlinx.html.LI
import kotlinx.html.LINK
import kotlinx.html.LinkAs
import kotlinx.html.MAIN
import kotlinx.html.MAP
import kotlinx.html.MARK
Expand Down Expand Up @@ -992,10 +993,12 @@ public inline fun TagConsumer<HTMLElement>.link(
href: String? = null,
rel: String? = null,
type: String? = null,
htmlAs: LinkAs? = null,
crossinline block: LINK.() -> Unit = {},
): HTMLLinkElement {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return LINK(attributesMapOf("href", href,"rel", rel,"type", type), this)
return LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", htmlAs?.enumEncode()),
this)
.visitAndFinalize(this, block) as HTMLLinkElement
}

Expand Down
12 changes: 8 additions & 4 deletions src/jvmTest/kotlin/streaming.kt
Expand Up @@ -181,10 +181,14 @@ class TestStreaming {
}

@Test fun `test generated enum could be used`() {
assertEquals("<link rel=\"Stylesheet\" href=\"/path\">", StringBuilder().appendHTML(false).link {
rel = LinkRel.stylesheet
href = "/path"
}.toString())
assertEquals(
"<link rel=\"Stylesheet\" href=\"/path\" as=\"style\">",
StringBuilder().appendHTML(false).link {
rel = LinkRel.stylesheet
href = "/path"
htmlAs = LinkAs.style
}.toString()
)
}

@Test fun `anchor with href syntax`() {
Expand Down
5 changes: 4 additions & 1 deletion src/wasmJsMain/kotlin/generated/gen-consumer-tags-wasm-js.kt
Expand Up @@ -88,6 +88,7 @@ import kotlinx.html.LABEL
import kotlinx.html.LEGEND
import kotlinx.html.LI
import kotlinx.html.LINK
import kotlinx.html.LinkAs
import kotlinx.html.MAIN
import kotlinx.html.MAP
import kotlinx.html.MARK
Expand Down Expand Up @@ -991,10 +992,12 @@ public inline fun TagConsumer<Element>.link(
href: String? = null,
rel: String? = null,
type: String? = null,
htmlAs: LinkAs? = null,
crossinline block: LINK.() -> Unit = {},
): HTMLLinkElement {
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
return LINK(attributesMapOf("href", href,"rel", rel,"type", type), this)
return LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", htmlAs?.enumEncode()),
this)
.visitAndFinalize(this, block) as HTMLLinkElement
}

Expand Down