All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.woojiahao.style.css.CssSelector.kt Maven / Gradle / Ivy

package com.github.woojiahao.style.css

class CssSelector(private val selector: String, val attributes: CssAttributes = CssAttributes()) {

  private val nestedCssSelectors by lazy { mutableListOf() }

  fun attributes(attributes: CssAttributes.() -> Unit) = this.attributes.attributes()

  fun nested(nested: MutableList.() -> Unit) = nestedCssSelectors.nested()

  fun toCss(): String =
    with(mutableListOf("$selector {")) {
      if (attributes.attrs.isNotEmpty())
        this += attributes.toCss()

      if (nestedCssSelectors.isNotEmpty())
        this += nestedCssSelectors.joinToString("\n") { it.toCss() }

      this += "}"
      joinToString("\n")
    }
}

inline fun cssSelector(selectorName: String, style: CssSelector.() -> Unit) =
  CssSelector(selectorName).apply(style)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy