Builder test

This commit is contained in:
2020-03-01 15:22:19 +01:00
parent 1f819c925f
commit 5a0eeac2fe
10 changed files with 166 additions and 110 deletions

View File

@@ -8,6 +8,16 @@ typealias Css = Style.() -> Unit
@DslMarker
annotation class CssTagMarker
private fun toProp(vararg css: CssValue): List<CssProperty> {
val result = mutableListOf<CssProperty>()
for (c in css) {
result.add(CssProperty(c.css()))
}
return result
}
abstract class CssGenerator {
val definitions: MutableMap<String, Css> = mutableMapOf()
val properties: MutableMap<String, List<CssProperty>> = mutableMapOf()
@@ -87,7 +97,7 @@ abstract class CssGenerator {
if (!minified) {
builder.append("\n")
}
builder.append(ff.generatePropertyCss(" $indent", minified))
builder.append(ff.generatePropertyCss( " $indent", minified))
builder.append(indent)
builder.append("}")
if (!minified) {
@@ -112,10 +122,6 @@ abstract class CssGenerator {
@CssTagMarker
open class Style(
/*
var alignContent: AlignContent? = null,
var alignItems: AlignItems? = null,
var alignSelf: AlignSelf? = null,
var all: All? = null,
var animation: TextProperty? = null,
var animationDelay: List<DelayDuration>? = null,
var animationDirection: List<AnimationDirection>? = null,
@@ -131,7 +137,6 @@ open class Style(
var backgroundAttachment: BackgroundAttachment? = null,
var backgroundBlendMode: BackgroundBlendMode? = null,
var backgroundClip: ClipOrigin? = null,
var backgroundColor: Color? = null,
var backgroundImage: Image? = null,
var backgroundOrigin: ClipOrigin? = null,
var backgroundPosition: List<BackgroundPosition>? = null,
@@ -156,7 +161,6 @@ open class Style(
var borderLeftColor: Color? = null,
var borderLeftStyle: RuleBorderStyle? = null,
var borderLeftWidth: BorderWidth? = null,
var borderRadius: BorderRadius? = null,
var borderRight: TextProperty? = null,
var borderRightColor: Color? = null,
var borderRightStyle: RuleBorderStyle? = null,
@@ -211,7 +215,6 @@ open class Style(
var font: TextProperty? = null,
var color: Color? = null,
var fontFamily: TextProperty? = null,
var fontSize: FontSize? = null,
var height: Measurement? = null,
var left: Measurement? = null,
@@ -241,10 +244,6 @@ open class Style(
/*
override fun getMapping(): Map<String, Any?> = mapOf(
"align-content" to alignContent,
"align-items" to alignItems,
"align-self" to alignSelf,
"all" to all,
"animation" to animation,
"animation-delay" to animationDelay,
"animation-direction" to animationDirection,
@@ -285,7 +284,6 @@ open class Style(
"border-left-color" to borderLeftColor,
"border-left-style" to borderLeftStyle,
"border-left-width" to borderLeftWidth,
"border-radius" to borderRadius,
"border-right" to borderRight,
"border-right-color" to borderRightColor,
"border-right-style" to borderRightStyle,
@@ -361,19 +359,55 @@ open class Style(
face.invoke(fontFace!!)
}
fun alignContent(value: AlignContentValue) {
properties["align-content"] = listOf(CssProperty(value.css()))
fun alignContent(value: AlignContentValue) { properties["align-content"] = toProp(value) }
fun alignItems(alignItems: AlignItems) { properties["align-items"] = toProp(alignItems) }
fun all(all: All) { properties["all"] = toProp(all) }
fun alignSelf(alignSelf: AlignSelf) { properties["align-self"] = toProp(alignSelf) }
fun animation(text: String) { properties["animation"] = listOf(CssProperty(text)) }
fun backgroundColor(color: Color) { properties["background-color"] = listOf(color) }
fun borderRadius(radius: Measurement) { properties["border-radius"] = listOf(radius) }
fun borderRadius(
topLeftBottomRight: Measurement,
topRightBottomLeft: Measurement
) {
properties["border-radius"] = listOf(
topLeftBottomRight, topRightBottomLeft
)
}
fun margin(all: Measurement) {
properties["margin"] = listOf(all)
fun borderRadius(
topLeft: Measurement,
topRightBottomLeft: Measurement,
bottomRight: Measurement
) {
properties["border-radius"] = listOf(
topLeft, topRightBottomLeft, bottomRight
)
}
fun margin(topBottom: Measurement, leftRight: Measurement) {
properties["margin"] = listOf(topBottom, leftRight)
fun borderRadius(
topLeft: Measurement,
topRight: Measurement,
bottomRight: Measurement,
bottomLeft: Measurement
) {
properties["border-radius"] = listOf(
topLeft, topRight, bottomRight, bottomLeft
)
}
fun bottom(bottom: Measurement) { properties["bottom"] = listOf(bottom) }
fun fontFamily(font: String) { properties["font-family"] = listOf(CssProperty(font)) }
fun fontSize(size: Measurement) { properties["font-size"] = listOf(size) }
fun height(height: Measurement) { properties["height"] = listOf(height) }
fun left(left: Measurement) { properties["left"] = listOf(left) }
fun margin(all: Measurement) { properties["margin"] = listOf(all) }
fun margin(topBottom: Measurement, leftRight: Measurement) { properties["margin"] = listOf(topBottom, leftRight) }
fun margin(top: Measurement, right: Measurement, bottom: Measurement, left: Measurement) {
properties["margin"] = listOf(top, right, bottom, left)
}
fun right(right: Measurement) { properties["right"] = listOf(right) }
fun top(top: Measurement) { properties["top"] = listOf(top) }
fun width(width: Measurement) { properties["width"] = listOf(width) }
}