com.github.woojiahao.style.css.CssAttributes.kt Maven / Gradle / Ivy
package com.github.woojiahao.style.css
class CssAttributes {
private val attributes = mutableMapOf()
val attrs
get() = attributes.toMap()
fun append(attributes: CssAttributes) = this.attributes.putAll(attributes.attributes)
fun add(name: String, value: T?): CssAttributes {
addAttribute(name, value)
return this
}
fun remove(name: String): CssAttributes {
attributes.remove(name)
return this
}
infix fun String.to(value: T?) = addAttribute(this, value)
fun toCss() =
attributes
.entries
.filter { it.value != null }
.joinToString("\n") { "\t${it.key}: ${it.value.toString()};" }
private fun addAttribute(name: String, value: T?) {
attributes[name] = value?.toString()
}
}