From 95fb7ec923891da060f66bb8f129381b07ed1124 Mon Sep 17 00:00:00 2001 From: rnentjes Date: Fri, 11 Jun 2021 09:45:04 +0200 Subject: [PATCH] Allow multiple selectors for one style (or operator) --- build.gradle.kts | 2 +- .../kotlin/nl/astraeus/css/style/Style.kt | 72 ++++++++++++------- .../kotlin/nl/astraeus/css/TestCssBuilder.kt | 20 ++++++ 3 files changed, 69 insertions(+), 25 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 88a0265..17b1df4 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -4,7 +4,7 @@ plugins { } group = "nl.astraeus" -version = "0.4.19" +version = "0.4.20" repositories { maven { setUrl("https://dl.bintray.com/kotlin/kotlin-eap") } diff --git a/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt b/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt index 7cc2046..e5250ce 100644 --- a/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt +++ b/src/commonMain/kotlin/nl/astraeus/css/style/Style.kt @@ -275,52 +275,76 @@ open class Style : CssGenerator() { * like the scss & * @param selector blabla */ - fun and(selector: DescriptionProvider, style: Css) { - addStyle(selector.description(), style) + fun and(vararg selectors: DescriptionProvider, style: Css) { + for (selector in selectors) { + addStyle(selector.description(), style) + } } - fun and(selector: String, style: Css) { - addStyle(selector, style) + fun and(vararg selectors: String, style: Css) { + for (selector in selectors) { + addStyle(selector, style) + } } - fun select(selector: DescriptionProvider, style: Css) { - addStyle(" ${selector.description()}", style) + fun select(vararg selectors: DescriptionProvider, style: Css) { + for (selector in selectors) { + addStyle(" ${selector.description()}", style) + } } - fun select(selector: String, style: Css) { - addStyle(" $selector", style) + fun select(vararg selectors: String, style: Css) { + for (selector in selectors) { + addStyle(" $selector", style) + } } - fun descendant(descName: DescriptionProvider, style: Css) { - addStyle(" ${descName.description()}", style) + fun descendant(vararg descNames: DescriptionProvider, style: Css) { + for (descName in descNames) { + addStyle(" ${descName.description()}", style) + } } - fun descendant(descName: String, style: Css) { - addStyle(" $descName", style) + fun descendant(vararg descNames: String, style: Css) { + for (descName in descNames) { + addStyle(" $descName", style) + } } - fun child(childName: DescriptionProvider, style: Css) { - addStyle(" > ${childName.description()}", style) + fun child(vararg childNames: DescriptionProvider, style: Css) { + for (childName in childNames) { + addStyle(" > ${childName.description()}", style) + } } - fun child(childName: String, style: Css) { - addStyle(" > $childName", style) + fun child(vararg childNames: String, style: Css) { + for (childName in childNames) { + addStyle(" > $childName", style) + } } - fun sibling(childName: DescriptionProvider, style: Css) { - addStyle(" ~ ${childName.description()}", style) + fun sibling(vararg childNames: DescriptionProvider, style: Css) { + for (childName in childNames) { + addStyle(" ~ ${childName.description()}", style) + } } - fun sibling(childName: String, style: Css) { - addStyle(" ~ $childName", style) + fun sibling(vararg childNames: String, style: Css) { + for (childName in childNames) { + addStyle(" ~ $childName", style) + } } - fun adjSibling(childName: DescriptionProvider, style: Css) { - addStyle(" + ${childName.description()}", style) + fun adjSibling(vararg childNames: DescriptionProvider, style: Css) { + for (childName in childNames) { + addStyle(" + ${childName.description()}", style) + } } - fun adjSibling(childName: String, style: Css) { - addStyle(" + $childName", style) + fun adjSibling(vararg childNames: String, style: Css) { + for (childName in childNames) { + addStyle(" + $childName", style) + } } fun active(style: Css) { diff --git a/src/commonTest/kotlin/nl/astraeus/css/TestCssBuilder.kt b/src/commonTest/kotlin/nl/astraeus/css/TestCssBuilder.kt index 984165e..4096398 100644 --- a/src/commonTest/kotlin/nl/astraeus/css/TestCssBuilder.kt +++ b/src/commonTest/kotlin/nl/astraeus/css/TestCssBuilder.kt @@ -154,4 +154,24 @@ class TestCssBuilder { println(css2.generateCss()) } + + + @Test + fun testOr() { + val css = style { + select("h1") { + color(Color.blue) + + select("table") { + color(Color.red) + + select("th", "td") { + color(Color.green) + } + } + } + } + + println(css.generateCss()) + } }