v. 1.0.2, fix minified option
Took 8 minutes
This commit is contained in:
@@ -3,10 +3,11 @@ plugins {
|
|||||||
`maven-publish`
|
`maven-publish`
|
||||||
signing
|
signing
|
||||||
id("org.jetbrains.dokka") version "1.5.31"
|
id("org.jetbrains.dokka") version "1.5.31"
|
||||||
|
id("com.adarshr.test-logger") version "3.0.0"
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "nl.astraeus"
|
group = "nl.astraeus"
|
||||||
version = "1.0.1"
|
version = "1.0.2"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@@ -47,8 +48,12 @@ kotlin {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testlogger {
|
||||||
|
showStandardStreams = true
|
||||||
|
}
|
||||||
|
|
||||||
extra["PUBLISH_GROUP_ID"] = "nl.astraeus"
|
extra["PUBLISH_GROUP_ID"] = "nl.astraeus"
|
||||||
extra["PUBLISH_VERSION"] = "1.0.1"
|
extra["PUBLISH_VERSION"] = "1.0.2"
|
||||||
extra["PUBLISH_ARTIFACT_ID"] = "kotlin-css-generator"
|
extra["PUBLISH_ARTIFACT_ID"] = "kotlin-css-generator"
|
||||||
|
|
||||||
// Stub secrets to let the project sync and build without the publication values set up
|
// Stub secrets to let the project sync and build without the publication values set up
|
||||||
|
|||||||
@@ -35,7 +35,12 @@ abstract class CssGenerator {
|
|||||||
|
|
||||||
abstract fun getValidator(name: String): List<Validator>?
|
abstract fun getValidator(name: String): List<Validator>?
|
||||||
|
|
||||||
private fun propertyCss(indent: String, name: String, props: List<CssProperty>): String {
|
private fun propertyCss(
|
||||||
|
indent: String,
|
||||||
|
name: String,
|
||||||
|
minified: Boolean,
|
||||||
|
props: List<CssProperty>
|
||||||
|
): String {
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
|
|
||||||
getValidator(name)?.forEach {
|
getValidator(name)?.forEach {
|
||||||
@@ -52,18 +57,23 @@ abstract class CssGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val paddedName = StringBuilder()
|
val paddedName = StringBuilder()
|
||||||
paddedName.append(indent)
|
if (!minified) {
|
||||||
|
paddedName.append(indent)
|
||||||
|
}
|
||||||
paddedName.append(name)
|
paddedName.append(name)
|
||||||
paddedName.append(":")
|
paddedName.append(":")
|
||||||
while (paddedName.length < 32) {
|
if (!minified) {
|
||||||
paddedName.append(' ')
|
while (paddedName.length < 32) {
|
||||||
|
paddedName.append(' ')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return "$paddedName$builder;\n"
|
return "$paddedName$builder;"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generatePropertyCss(
|
fun generatePropertyCss(
|
||||||
indent: String,
|
indent: String,
|
||||||
sortProperties: Boolean
|
sortProperties: Boolean,
|
||||||
|
minified: Boolean
|
||||||
): String {
|
): String {
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
|
|
||||||
@@ -71,11 +81,17 @@ abstract class CssGenerator {
|
|||||||
for (name in props.keys.sorted()) {
|
for (name in props.keys.sorted()) {
|
||||||
val prop = props[name] ?: error("$name not found in properties after sorting!")
|
val prop = props[name] ?: error("$name not found in properties after sorting!")
|
||||||
|
|
||||||
builder.append(propertyCss(indent, name, prop))
|
builder.append(propertyCss(indent, name, minified, prop))
|
||||||
|
if (!minified) {
|
||||||
|
builder.append("\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for ((name, prop) in props) {
|
for ((name, prop) in props) {
|
||||||
builder.append(propertyCss(indent, name, prop))
|
builder.append(propertyCss(indent, name, minified, prop))
|
||||||
|
if (!minified) {
|
||||||
|
builder.append("\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,11 +123,20 @@ abstract class CssGenerator {
|
|||||||
) {
|
) {
|
||||||
if (selectors.isNotEmpty() && block != null) {
|
if (selectors.isNotEmpty() && block != null) {
|
||||||
append(indent)
|
append(indent)
|
||||||
append(selectors.joinToString(",\n"))
|
append(selectors.joinToString(if (minified) { "," } else { ",\n" }))
|
||||||
append(" {\n")
|
if (!minified) {
|
||||||
|
append(" ")
|
||||||
|
}
|
||||||
|
append("{")
|
||||||
|
if (!minified) {
|
||||||
|
append("\n")
|
||||||
|
}
|
||||||
append(block.content)
|
append(block.content)
|
||||||
append(indent)
|
append(indent)
|
||||||
append("}\n\n")
|
append("}")
|
||||||
|
if (!minified) {
|
||||||
|
append("\n\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -165,18 +190,7 @@ abstract class CssGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return if (minified) {
|
return builder.toString()
|
||||||
val stripped = StringBuilder()
|
|
||||||
val skip = arrayOf(' ', '\t', '\n', '\r')
|
|
||||||
for (char in builder) {
|
|
||||||
if (!skip.contains(char)) {
|
|
||||||
stripped.append(char)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stripped.toString()
|
|
||||||
} else {
|
|
||||||
builder.toString()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
open fun generateCssBlocks(
|
open fun generateCssBlocks(
|
||||||
@@ -203,7 +217,7 @@ abstract class CssGenerator {
|
|||||||
prop(finalStyle)
|
prop(finalStyle)
|
||||||
}
|
}
|
||||||
|
|
||||||
css.append(finalStyle.generatePropertyCss(" $indent", sortProperties))
|
css.append(finalStyle.generatePropertyCss(" $indent", sortProperties, minified))
|
||||||
|
|
||||||
if (css.isNotBlank()) {
|
if (css.isNotBlank()) {
|
||||||
val builder = StringBuilder()
|
val builder = StringBuilder()
|
||||||
@@ -218,40 +232,79 @@ abstract class CssGenerator {
|
|||||||
//builder.append(" {\n")
|
//builder.append(" {\n")
|
||||||
|
|
||||||
finalStyle.fontFace?.let { ff ->
|
finalStyle.fontFace?.let { ff ->
|
||||||
builder.append(" $indent")
|
if (!minified) {
|
||||||
builder.append("@font-face {\n")
|
builder.append(" $indent")
|
||||||
builder.append(ff.generatePropertyCss(" $indent", sortProperties))
|
}
|
||||||
builder.append(" $indent")
|
builder.append("@font-face")
|
||||||
builder.append("}\n")
|
if (!minified) {
|
||||||
|
builder.append(" ")
|
||||||
|
}
|
||||||
|
builder.append("{")
|
||||||
|
if (!minified) {
|
||||||
|
builder.append("\n")
|
||||||
|
}
|
||||||
|
builder.append(ff.generatePropertyCss(" $indent", sortProperties, minified))
|
||||||
|
if (!minified) {
|
||||||
|
builder.append(" $indent")
|
||||||
|
}
|
||||||
|
builder.append("}")
|
||||||
|
if (!minified) {
|
||||||
|
builder.append("\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
finalStyle.keyFrames.let { kf ->
|
finalStyle.keyFrames.let { kf ->
|
||||||
kf.keys.sorted().forEach { frameName ->
|
kf.keys.sorted().forEach { frameName ->
|
||||||
val css = kf[frameName]
|
val css = kf[frameName]
|
||||||
|
|
||||||
builder.append(" $indent")
|
if (!minified) {
|
||||||
|
builder.append(" $indent")
|
||||||
|
}
|
||||||
builder.append("@keyframes ")
|
builder.append("@keyframes ")
|
||||||
builder.append(frameName)
|
builder.append(frameName)
|
||||||
builder.append(" {\n")
|
if (!minified) {
|
||||||
|
builder.append(" ")
|
||||||
|
}
|
||||||
|
builder.append("{")
|
||||||
|
if (!minified) {
|
||||||
|
builder.append("\n")
|
||||||
|
}
|
||||||
css?.let { css ->
|
css?.let { css ->
|
||||||
for ((nr, style) in css.frames) {
|
for ((nr, style) in css.frames) {
|
||||||
builder.append(" $indent")
|
if (!minified) {
|
||||||
|
builder.append(" $indent")
|
||||||
|
}
|
||||||
builder.append("${nr}% ")
|
builder.append("${nr}% ")
|
||||||
builder.append(" $indent")
|
if (!minified) {
|
||||||
builder.append("{\n")
|
builder.append(" $indent")
|
||||||
|
}
|
||||||
|
builder.append("{")
|
||||||
|
if (!minified) {
|
||||||
|
builder.append("\n")
|
||||||
|
}
|
||||||
|
|
||||||
val finalStyle = Style()
|
val finalStyle = Style()
|
||||||
|
|
||||||
style(finalStyle)
|
style(finalStyle)
|
||||||
|
|
||||||
builder.append(finalStyle.generatePropertyCss(" $indent", sortProperties))
|
builder.append(finalStyle.generatePropertyCss(" $indent", sortProperties, minified))
|
||||||
|
|
||||||
builder.append(" $indent")
|
if (!minified) {
|
||||||
builder.append("}\n")
|
builder.append(" $indent")
|
||||||
|
}
|
||||||
|
builder.append("}")
|
||||||
|
if (!minified) {
|
||||||
|
builder.append("\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.append(" $indent")
|
if (!minified) {
|
||||||
builder.append("}\n")
|
builder.append(" $indent")
|
||||||
|
}
|
||||||
|
builder.append("}")
|
||||||
|
if (!minified) {
|
||||||
|
builder.append("\n")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user