Skip to content

Commit

Permalink
Added "as" attribute for Link tag
Browse files Browse the repository at this point in the history
  • Loading branch information
severn-everett committed Mar 26, 2024
1 parent f1b51c6 commit 52d3e33
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 8 deletions.
18 changes: 18 additions & 0 deletions buildSrc/src/main/resources/html_5.xsd
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
4 changes: 3 additions & 1 deletion src/commonMain/kotlin/generated/gen-consumer-tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 @@ -699,8 +700,9 @@ 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 = LINK(attributesMapOf("href", href,"rel", rel,"type", type), this)
): T = 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
Original file line number Diff line number Diff line change
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
26 changes: 25 additions & 1 deletion src/commonMain/kotlin/generated/gen-tag-unions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,31 @@ inline fun FlowOrMetaDataOrPhrasingContent.radioCommand(classes : String? = null
* A media-independent link
*/
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.link(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type), consumer).visit(block)
inline fun FlowOrMetaDataOrPhrasingContent.link(href : String? = null, rel : String? = null, type : String? = null, htmlAs : LinkAs? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", htmlAs?.enumEncode()), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.audioLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.audio.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.documentLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.document.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.embedLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.embed.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.fetchLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.fetch.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.fontLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.font.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.imageLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.image.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.htmlObjectLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.htmlObject.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.scriptLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.script.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.styleLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.style.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.trackLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.track.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.videoLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.video.realValue), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrMetaDataOrPhrasingContent.workerLink(href : String? = null, rel : String? = null, type : String? = null, crossinline block : LINK.() -> Unit = {}) : Unit = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as", LinkAs.worker.realValue), consumer).visit(block)

/**
* Generic metainformation
Expand Down
4 changes: 4 additions & 0 deletions src/commonMain/kotlin/generated/gen-tags-l.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 @@ -762,8 +763,10 @@ public inline fun TagConsumer<HTMLElement>.link(
href: String? = null,
rel: String? = null,
type: String? = null,
htmlAs: LinkAs? = null,
crossinline block: LINK.() -> Unit = {},
): HTMLLinkElement = LINK(attributesMapOf("href", href,"rel", rel,"type", type), this)
): HTMLLinkElement = 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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,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 @@ -761,8 +762,10 @@ public inline fun TagConsumer<Element>.link(
href: String? = null,
rel: String? = null,
type: String? = null,
htmlAs: LinkAs? = null,
crossinline block: LINK.() -> Unit = {},
): HTMLLinkElement = LINK(attributesMapOf("href", href,"rel", rel,"type", type), this)
): HTMLLinkElement = LINK(attributesMapOf("href", href,"rel", rel,"type", type,"as",
htmlAs?.enumEncode()), this)
.visitAndFinalize(this, block) as HTMLLinkElement

/**
Expand Down

0 comments on commit 52d3e33

Please sign in to comment.