mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-12-22 08:37:24 +00:00
Merge pull request #34 from InsanusMokrassar/0.0.33
attribute builder now may skip nullable values
This commit is contained in:
commit
c1c1f847a9
@ -24,9 +24,10 @@ class UIKitAttributeValueBuilder {
|
||||
|
||||
fun AttrsBuilder<*>.buildAndAddAttribute(
|
||||
attributeName: String,
|
||||
skipNullValues: Boolean = true,
|
||||
block: AttributeBuilder.() -> Unit
|
||||
) {
|
||||
buildAttribute(attributeName, block).let {
|
||||
buildAttribute(attributeName, skipNullValues, block).let {
|
||||
attr(it.first, it.second)
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,15 @@ package dev.inmo.jsuikit.utils
|
||||
|
||||
class AttributeBuilder (
|
||||
val attributeName: String,
|
||||
val skipNullValues: Boolean = true,
|
||||
private val parametersPreset: MutableMap<String, String?> = mutableMapOf()
|
||||
) {
|
||||
|
||||
fun add(k: String, v: Any? = null) = parametersPreset.set(k, v ?.toString())
|
||||
fun add(k: String, v: Any? = null) {
|
||||
if (v != null || !skipNullValues) {
|
||||
parametersPreset[k] = v ?.toString()
|
||||
}
|
||||
}
|
||||
infix fun String.to(value: Any?) = add(this, value)
|
||||
operator fun String.unaryPlus() = add(this, null)
|
||||
|
||||
@ -16,6 +21,7 @@ class AttributeBuilder (
|
||||
)
|
||||
}
|
||||
|
||||
inline fun buildAttribute(attributeName: String, block: AttributeBuilder.() -> Unit) = AttributeBuilder(
|
||||
attributeName
|
||||
inline fun buildAttribute(attributeName: String, skipNullValues: Boolean = true, block: AttributeBuilder.() -> Unit) = AttributeBuilder(
|
||||
attributeName,
|
||||
skipNullValues
|
||||
).apply(block).build()
|
||||
|
Loading…
Reference in New Issue
Block a user