com.github.woojiahao.style.css.CssAttributes.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kMD2PDF Show documentation
Show all versions of kMD2PDF Show documentation
Simple and highly customizable markdown to PDF conversion library
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()
}
}