Skip to content

Commit

Permalink
Added loading attribute to img tag; Added warning suppression for cap…
Browse files Browse the repository at this point in the history
…italizing enum names
  • Loading branch information
severn-everett committed Jun 2, 2023
1 parent 18bc15c commit 2d691ff
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 6 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/kotlinx/html/generate/rules.kt
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ val specialTypes = listOf(
).groupBy { it.first }.mapValues { it.value.single().second }

fun specialTypeFor(tagName: String, attributeName: String): AttributeType? =
specialTypes[tagName + "." + attributeName] ?: specialTypes["*." + attributeName]
specialTypes["$tagName.$attributeName"] ?: specialTypes["*.$attributeName"]

val wellKnownWords = listOf("span", "class", "enabled?", "edit(able)?",
"^on", "encoded?", "form", "type",
Expand All @@ -67,7 +67,7 @@ val wellKnownWords = listOf("span", "class", "enabled?", "edit(able)?",
"click", "play(ing)?", "context",
"rows?", "cols?", "group(ed)?", "auto",
"list", "field", "data", "block", "scripts?",
"item", "area", "length", "colors?", "suspend", "focus", "touch"
"item", "area", "length", "colors?", "suspend", "focus", "touch", "loading"
).map { it.toRegex(RegexOption.IGNORE_CASE) }

val excludeAttributes = listOf("^item$").map { Pattern.compile(it, Pattern.CASE_INSENSITIVE) }
Expand Down
8 changes: 8 additions & 0 deletions buildSrc/src/main/resources/html_5.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -968,6 +968,14 @@
</xsd:restriction>
</xsd:simpleType>
</xsd:attribute>
<xsd:attribute name="loading">
<xsd:simpleType>
<xsd:restriction base="xsd:NMTOKEN">
<xsd:enumeration value="eager"/>
<xsd:enumeration value="lazy"/>
</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 @@ -36,6 +36,8 @@ internal val attributeFormMethodEnumFormMethodValues : Attribute<FormMethod> = E

internal val attributeIframeSandboxEnumIframeSandboxValues : Attribute<IframeSandbox> = EnumAttribute(iframeSandboxValues)

internal val attributeImgLoadingEnumImgLoadingValues : Attribute<ImgLoading> = EnumAttribute(imgLoadingValues)

internal val attributeInputFormEncTypeEnumInputFormEncTypeValues : Attribute<InputFormEncType> = EnumAttribute(inputFormEncTypeValues)

internal val attributeInputFormMethodEnumInputFormMethodValues : Attribute<InputFormMethod> = EnumAttribute(inputFormMethodValues)
Expand Down
2 changes: 1 addition & 1 deletion src/commonMain/kotlin/generated/gen-consumer-tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ inline fun <T, C : TagConsumer<T>> C.iframe(sandbox : IframeSandbox? = null, cla
* Embedded image
*/
@HtmlTagMarker
inline fun <T, C : TagConsumer<T>> C.img(alt : String? = null, src : String? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : T = IMG(attributesMapOf("alt", alt,"src", src,"class", classes), this).visitAndFinalize(this, block)
inline fun <T, C : TagConsumer<T>> C.img(alt : String? = null, src : String? = null, loading : ImgLoading? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : T = IMG(attributesMapOf("alt", alt,"src", src,"loading", loading?.enumEncode(),"class", classes), this).visitAndFinalize(this, block)

/**
* Form control
Expand Down
9 changes: 9 additions & 0 deletions src/commonMain/kotlin/generated/gen-enums.kt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:Suppress("EnumEntryName")

package kotlinx.html

import kotlinx.html.*
Expand Down Expand Up @@ -216,6 +218,13 @@ enum class IframeSandbox(override val realValue : String) : AttributeEnum {

internal val iframeSandboxValues : Map<String, IframeSandbox> = IframeSandbox.values().associateBy { it.realValue }
@Suppress("unused")
enum class ImgLoading(override val realValue : String) : AttributeEnum {
eager("eager"),
lazy("lazy")
}

internal val imgLoadingValues : Map<String, ImgLoading> = ImgLoading.values().associateBy { it.realValue }
@Suppress("unused")
enum class InputType(override val realValue : String) : AttributeEnum {
button("button"),
checkBox("checkbox"),
Expand Down
6 changes: 5 additions & 1 deletion src/commonMain/kotlin/generated/gen-tag-unions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,11 @@ fun FlowOrInteractiveOrPhrasingContent.allowScriptsIframe(classes : String? = nu
* Embedded image
*/
@HtmlTagMarker
inline fun FlowOrInteractiveOrPhrasingContent.img(alt : String? = null, src : String? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : Unit = IMG(attributesMapOf("alt", alt,"src", src,"class", classes), consumer).visit(block)
inline fun FlowOrInteractiveOrPhrasingContent.img(alt : String? = null, src : String? = null, loading : ImgLoading? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : Unit = IMG(attributesMapOf("alt", alt,"src", src,"loading", loading?.enumEncode(),"class", classes), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrInteractiveOrPhrasingContent.eagerImg(alt : String? = null, src : String? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : Unit = IMG(attributesMapOf("alt", alt,"src", src,"loading", ImgLoading.eager.realValue,"class", classes), consumer).visit(block)
@HtmlTagMarker
inline fun FlowOrInteractiveOrPhrasingContent.lazyImg(alt : String? = null, src : String? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : Unit = IMG(attributesMapOf("alt", alt,"src", src,"loading", ImgLoading.lazy.realValue,"class", classes), consumer).visit(block)

/**
* Pictures container
Expand Down
4 changes: 4 additions & 0 deletions src/commonMain/kotlin/generated/gen-tags-i.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ open class IMG(initialAttributes : Map<String, String>, override val consumer :
get() = attributeBooleanTicker.get(this, "ismap")
set(newValue) {attributeBooleanTicker.set(this, "ismap", newValue)}

var loading : ImgLoading
get() = attributeImgLoadingEnumImgLoadingValues.get(this, "loading")
set(newValue) {attributeImgLoadingEnumImgLoadingValues.set(this, "loading", newValue)}


}
val IMG.asFlowContent : FlowContent
Expand Down
6 changes: 5 additions & 1 deletion src/commonMain/kotlin/generated/gen-tags-p.kt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ inline fun PICTURE.source(classes : String? = null, crossinline block : SOURCE.(
* Embedded image
*/
@HtmlTagMarker
inline fun PICTURE.img(alt : String? = null, src : String? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : Unit = IMG(attributesMapOf("alt", alt,"src", src,"class", classes), consumer).visit(block)
inline fun PICTURE.img(alt : String? = null, src : String? = null, loading : ImgLoading? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : Unit = IMG(attributesMapOf("alt", alt,"src", src,"loading", loading?.enumEncode(),"class", classes), consumer).visit(block)
@HtmlTagMarker
inline fun PICTURE.eagerImg(alt : String? = null, src : String? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : Unit = IMG(attributesMapOf("alt", alt,"src", src,"loading", ImgLoading.eager.realValue,"class", classes), consumer).visit(block)
@HtmlTagMarker
inline fun PICTURE.lazyImg(alt : String? = null, src : String? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : Unit = IMG(attributesMapOf("alt", alt,"src", src,"loading", ImgLoading.lazy.realValue,"class", classes), consumer).visit(block)

val PICTURE.asFlowContent : FlowContent
get() = this
Expand Down
2 changes: 1 addition & 1 deletion src/jsMain/kotlin/generated/gen-consumer-tags-js.kt
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ public inline fun TagConsumer<HTMLElement>.iframe(sandbox : IframeSandbox? = nul
* Embedded image
*/
@HtmlTagMarker
public inline fun TagConsumer<HTMLElement>.img(alt : String? = null, src : String? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : HTMLImageElement = IMG(attributesMapOf("alt", alt,"src", src,"class", classes), this).visitAndFinalize(this, block) as HTMLImageElement
public inline fun TagConsumer<HTMLElement>.img(alt : String? = null, src : String? = null, loading : ImgLoading? = null, classes : String? = null, crossinline block : IMG.() -> Unit = {}) : HTMLImageElement = IMG(attributesMapOf("alt", alt,"src", src,"loading", loading?.enumEncode(),"class", classes), this).visitAndFinalize(this, block) as HTMLImageElement

/**
* Form control
Expand Down

0 comments on commit 2d691ff

Please sign in to comment.