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

Improving Tag Generation #274

Merged
merged 1 commit into from
May 17, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions buildSrc/src/main/kotlin/kotlinx/html/generate/attributes.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,12 @@ fun Appendable.attributeProperty(

indent(indent)
getter().defineIs(StringBuilder().apply {
receiverDot(request.delegatePropertyName)
functionCall("get", listOf("this", attributeName.quote()))
append(request.delegatePropertyName).append("[this, ${attributeName.quote()}]")
})

indent(indent)
setter {
receiverDot(request.delegatePropertyName)
functionCall("set", listOf("this", attributeName.quote(), "newValue"))
append(request.delegatePropertyName).append("[this, ${attributeName.quote()}] = newValue")
}

emptyLine()
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/kotlinx/html/generate/codegen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,4 @@ fun Appendable.suppress(vararg warnings: String) {
append("@")
functionCall("Suppress", warnings.map { it.quote() })
append("\n")
}
}
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/kotlinx/html/generate/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ private fun generateConsumerTags(
yield(
consumerBuilder(tag, false)
.toBuilder()
.addSuppressAnnotation("DEPRECATION")
.addSuppressAnnotation("DEPRECATION", "DeprecatedCallableAddReplaceWith")
.addDeprecatedAnnotation("This tag doesn't support content or requires unsafe (try unsafe {})")
.build()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ fun Appendable.htmlTagBuilders(receiver : String, tag : TagInfo) {
if (probablyContentOnly) {
htmlTagBuilderMethod(receiver, tag, false)
} else if (contentlessTag) {
suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
deprecated("This tag doesn't support content or requires unsafe (try unsafe {})")
suppress("DEPRECATION")
htmlTagBuilderMethod(receiver, tag, false)
}

Expand All @@ -41,11 +41,11 @@ fun Appendable.htmlTagBuilders(receiver : String, tag : TagInfo) {
if (probablyContentOnly) {
htmlTagEnumBuilderMethod(receiver, tag, false, someEnumAttribute, 0)
} else if (contentlessTag) {
suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
deprecated("This tag doesn't support content or requires unsafe (try unsafe {})")
suppress("DEPRECATION")
htmlTagEnumBuilderMethod(receiver, tag, false, someEnumAttribute, 0)
}
}

emptyLine()
}
}
9 changes: 5 additions & 4 deletions buildSrc/src/main/kotlin/kotlinx/html/generate/tagsgen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ fun Appendable.tagClass(repository: Repository, tag: TagInfo, excludeAttributes:

fun contentlessTagDeprecation() {
indent()
appendLine("@Deprecated(\"This tag most likely doesn't support text content or requires unsafe content (try unsafe {}\")")
appendLine("@Suppress(\"DeprecatedCallableAddReplaceWith\")")
indent()
appendLine("@Deprecated(\"This tag most likely doesn't support text content or requires unsafe content (try unsafe {})\")")
}

if (tag.name.lowercase() in contentlessTags) {
Expand Down Expand Up @@ -224,11 +226,10 @@ fun tagConsumer(parameter: TypeName): TypeName =
ClassName("kotlinx.html", "TagConsumer")
.parameterizedBy(parameter)

fun FunSpec.Builder.addSuppressAnnotation(suppress: String) =
fun FunSpec.Builder.addSuppressAnnotation(vararg suppress: String) =
addAnnotation(
AnnotationSpec
.builder(Suppress::class)
.addMember("%S", suppress)
.builder(Suppress::class).apply { suppress.forEach { addMember("%S", it) } }
.build()
)

Expand Down
380 changes: 190 additions & 190 deletions src/commonMain/kotlin/generated/gen-attr-traits.kt

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions src/commonMain/kotlin/generated/gen-consumer-tags.kt
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,10 @@ public inline fun <T, C : TagConsumer<T>> C.h6(classes: String? = null, crossinl
* Document head
*/
@HtmlTagMarker
@Suppress("DEPRECATION")
@Suppress(
"DEPRECATION",
"DeprecatedCallableAddReplaceWith",
)
@Deprecated("This tag doesn't support content or requires unsafe (try unsafe {})")
public fun <T, C : TagConsumer<T>> C.head(content: String = ""): T = HEAD(emptyMap, this)
.visitAndFinalize(this, {+content})
Expand Down Expand Up @@ -764,7 +767,10 @@ public inline fun <T, C : TagConsumer<T>> C.hr(classes: String? = null, crossinl
* Document root element
*/
@HtmlTagMarker
@Suppress("DEPRECATION")
@Suppress(
"DEPRECATION",
"DeprecatedCallableAddReplaceWith",
)
@Deprecated("This tag doesn't support content or requires unsafe (try unsafe {})")
public fun <T, C : TagConsumer<T>> C.html(content: String = "", namespace: String? = null): T =
HTML(emptyMap, this, namespace)
Expand Down Expand Up @@ -1274,7 +1280,10 @@ public inline fun <T, C : TagConsumer<T>> C.samp(classes: String? = null, crossi
* Script statements
*/
@HtmlTagMarker
@Suppress("DEPRECATION")
@Suppress(
"DEPRECATION",
"DeprecatedCallableAddReplaceWith",
)
@Deprecated("This tag doesn't support content or requires unsafe (try unsafe {})")
public fun <T, C : TagConsumer<T>> C.script(
type: String? = null,
Expand Down Expand Up @@ -1387,7 +1396,10 @@ public inline fun <T, C : TagConsumer<T>> C.strong(classes: String? = null, cros
* Style info
*/
@HtmlTagMarker
@Suppress("DEPRECATION")
@Suppress(
"DEPRECATION",
"DeprecatedCallableAddReplaceWith",
)
@Deprecated("This tag doesn't support content or requires unsafe (try unsafe {})")
public fun <T, C : TagConsumer<T>> C.style(type: String? = null, content: String = ""): T =
STYLE(attributesMapOf("type", type), this)
Expand Down
6 changes: 3 additions & 3 deletions src/commonMain/kotlin/generated/gen-tag-unions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@ inline fun FlowOrMetaDataOrPhrasingContent.script(type : String? = null, src : S
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
SCRIPT(attributesMapOf("type", type,"src", src,"crossorigin", crossorigin?.enumEncode()), consumer).visit(block)
}
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("This tag doesn't support content or requires unsafe (try unsafe {})")
@Suppress("DEPRECATION")
/**
* Script statements
*/
Expand All @@ -190,8 +190,8 @@ inline fun FlowOrMetaDataOrPhrasingContent.useCredentialsScript(type : String? =
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
SCRIPT(attributesMapOf("type", type,"src", src,"crossorigin", ScriptCrossorigin.useCredentials.realValue), consumer).visit(block)
}
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("This tag doesn't support content or requires unsafe (try unsafe {})")
@Suppress("DEPRECATION")
@HtmlTagMarker
fun FlowOrMetaDataOrPhrasingContent.anonymousScript(type : String? = null, src : String? = null, content : String = "") : Unit = SCRIPT(attributesMapOf("type", type,"src", src,"crossorigin", ScriptCrossorigin.anonymous.realValue), consumer).visit({+content})
@HtmlTagMarker
Expand Down Expand Up @@ -275,8 +275,8 @@ inline fun FlowOrMetaDataContent.style(type : String? = null, crossinline block
contract { callsInPlace(block, InvocationKind.EXACTLY_ONCE) }
STYLE(attributesMapOf("type", type), consumer).visit(block)
}
@Suppress("DEPRECATION", "DeprecatedCallableAddReplaceWith")
@Deprecated("This tag doesn't support content or requires unsafe (try unsafe {})")
@Suppress("DEPRECATION")
/**
* Style info
*/
Expand Down
96 changes: 48 additions & 48 deletions src/commonMain/kotlin/generated/gen-tags-a.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,40 +15,40 @@ import kotlinx.html.attributes.*
@Suppress("unused")
open class A(initialAttributes : Map<String, String>, override val consumer : TagConsumer<*>) : HTMLTag("a", consumer, initialAttributes, null, true, false), CommonAttributeGroupFacadeFlowInteractivePhrasingContent {
var href : String
get() = attributeStringString.get(this, "href")
set(newValue) {attributeStringString.set(this, "href", newValue)}
get() = attributeStringString[this, "href"]
set(newValue) {attributeStringString[this, "href"] = newValue}

var target : String
get() = attributeStringString.get(this, "target")
set(newValue) {attributeStringString.set(this, "target", newValue)}
get() = attributeStringString[this, "target"]
set(newValue) {attributeStringString[this, "target"] = newValue}

var ping : String
get() = attributeStringString.get(this, "ping")
set(newValue) {attributeStringString.set(this, "ping", newValue)}
get() = attributeStringString[this, "ping"]
set(newValue) {attributeStringString[this, "ping"] = newValue}

var rel : String
get() = attributeStringString.get(this, "rel")
set(newValue) {attributeStringString.set(this, "rel", newValue)}
get() = attributeStringString[this, "rel"]
set(newValue) {attributeStringString[this, "rel"] = newValue}

var hrefLang : String
get() = attributeStringString.get(this, "hreflang")
set(newValue) {attributeStringString.set(this, "hreflang", newValue)}
get() = attributeStringString[this, "hreflang"]
set(newValue) {attributeStringString[this, "hreflang"] = newValue}

var type : String
get() = attributeStringString.get(this, "type")
set(newValue) {attributeStringString.set(this, "type", newValue)}
get() = attributeStringString[this, "type"]
set(newValue) {attributeStringString[this, "type"] = newValue}

var referrerPolicy : AReferrerPolicy
get() = attributeAReferrerPolicyEnumAReferrerPolicyValues.get(this, "referrerpolicy")
set(newValue) {attributeAReferrerPolicyEnumAReferrerPolicyValues.set(this, "referrerpolicy", newValue)}
get() = attributeAReferrerPolicyEnumAReferrerPolicyValues[this, "referrerpolicy"]
set(newValue) {attributeAReferrerPolicyEnumAReferrerPolicyValues[this, "referrerpolicy"] = newValue}

var media : String
get() = attributeStringString.get(this, "media")
set(newValue) {attributeStringString.set(this, "media", newValue)}
get() = attributeStringString[this, "media"]
set(newValue) {attributeStringString[this, "media"] = newValue}

var downLoad : String
get() = attributeStringString.get(this, "download")
set(newValue) {attributeStringString.set(this, "download", newValue)}
get() = attributeStringString[this, "download"]
set(newValue) {attributeStringString[this, "download"] = newValue}


}
Expand Down Expand Up @@ -81,44 +81,44 @@ open class ADDRESS(initialAttributes : Map<String, String>, override val consume
@Suppress("unused")
open class AREA(initialAttributes : Map<String, String>, override val consumer : TagConsumer<*>) : HTMLTag("area", consumer, initialAttributes, null, true, true), HtmlBlockInlineTag {
var shape : AreaShape
get() = attributeAreaShapeEnumAreaShapeValues.get(this, "shape")
set(newValue) {attributeAreaShapeEnumAreaShapeValues.set(this, "shape", newValue)}
get() = attributeAreaShapeEnumAreaShapeValues[this, "shape"]
set(newValue) {attributeAreaShapeEnumAreaShapeValues[this, "shape"] = newValue}

var coords : String
get() = attributeStringString.get(this, "coords")
set(newValue) {attributeStringString.set(this, "coords", newValue)}
get() = attributeStringString[this, "coords"]
set(newValue) {attributeStringString[this, "coords"] = newValue}

var href : String
get() = attributeStringString.get(this, "href")
set(newValue) {attributeStringString.set(this, "href", newValue)}
get() = attributeStringString[this, "href"]
set(newValue) {attributeStringString[this, "href"] = newValue}

var hrefLang : String
get() = attributeStringString.get(this, "hreflang")
set(newValue) {attributeStringString.set(this, "hreflang", newValue)}
get() = attributeStringString[this, "hreflang"]
set(newValue) {attributeStringString[this, "hreflang"] = newValue}

var alt : String
get() = attributeStringString.get(this, "alt")
set(newValue) {attributeStringString.set(this, "alt", newValue)}
get() = attributeStringString[this, "alt"]
set(newValue) {attributeStringString[this, "alt"] = newValue}

var target : String
get() = attributeStringString.get(this, "target")
set(newValue) {attributeStringString.set(this, "target", newValue)}
get() = attributeStringString[this, "target"]
set(newValue) {attributeStringString[this, "target"] = newValue}

var media : String
get() = attributeStringString.get(this, "media")
set(newValue) {attributeStringString.set(this, "media", newValue)}
get() = attributeStringString[this, "media"]
set(newValue) {attributeStringString[this, "media"] = newValue}

var rel : String
get() = attributeStringString.get(this, "rel")
set(newValue) {attributeStringString.set(this, "rel", newValue)}
get() = attributeStringString[this, "rel"]
set(newValue) {attributeStringString[this, "rel"] = newValue}

var ping : String
get() = attributeStringString.get(this, "ping")
set(newValue) {attributeStringString.set(this, "ping", newValue)}
get() = attributeStringString[this, "ping"]
set(newValue) {attributeStringString[this, "ping"] = newValue}

var type : String
get() = attributeStringString.get(this, "type")
set(newValue) {attributeStringString.set(this, "type", newValue)}
get() = attributeStringString[this, "type"]
set(newValue) {attributeStringString[this, "type"] = newValue}


}
Expand Down Expand Up @@ -154,24 +154,24 @@ val ASIDE.asSectioningContent : SectioningContent
@Suppress("unused")
open class AUDIO(initialAttributes : Map<String, String>, override val consumer : TagConsumer<*>) : HTMLTag("audio", consumer, initialAttributes, null, false, false), CommonAttributeGroupFacadeFlowInteractivePhrasingContent {
var src : String
get() = attributeStringString.get(this, "src")
set(newValue) {attributeStringString.set(this, "src", newValue)}
get() = attributeStringString[this, "src"]
set(newValue) {attributeStringString[this, "src"] = newValue}

var autoBuffer : Boolean
get() = attributeBooleanTicker.get(this, "autobuffer")
set(newValue) {attributeBooleanTicker.set(this, "autobuffer", newValue)}
get() = attributeBooleanTicker[this, "autobuffer"]
set(newValue) {attributeBooleanTicker[this, "autobuffer"] = newValue}

var autoPlay : Boolean
get() = attributeBooleanTicker.get(this, "autoplay")
set(newValue) {attributeBooleanTicker.set(this, "autoplay", newValue)}
get() = attributeBooleanTicker[this, "autoplay"]
set(newValue) {attributeBooleanTicker[this, "autoplay"] = newValue}

var loop : Boolean
get() = attributeBooleanTicker.get(this, "loop")
set(newValue) {attributeBooleanTicker.set(this, "loop", newValue)}
get() = attributeBooleanTicker[this, "loop"]
set(newValue) {attributeBooleanTicker[this, "loop"] = newValue}

var controls : Boolean
get() = attributeBooleanTicker.get(this, "controls")
set(newValue) {attributeBooleanTicker.set(this, "controls", newValue)}
get() = attributeBooleanTicker[this, "controls"]
set(newValue) {attributeBooleanTicker[this, "controls"] = newValue}


}
Expand Down
Loading
Loading