add colors

This commit is contained in:
InsanusMokrassar 2024-05-04 23:57:45 +06:00
parent 4dd90738ba
commit a6c1aacf40
6 changed files with 144 additions and 2 deletions

View File

@ -18,5 +18,12 @@
"program": "poetry", "program": "poetry",
"args": ["run", "mkdocs", "serve"], "args": ["run", "mkdocs", "serve"],
}, },
{
"type": "command",
"name": "Generate MicroUtils",
"program": "kotlin",
"args": ["../../generate_from_template.kts"],
"workingDir": "./docs/micro_utils/",
},
] ]
} }

View File

@ -0,0 +1,37 @@
# Colors [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/colors.common/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/colors.common)
* `Group`: `dev.inmo`
* `ArtifactId`: `colors.common`
Adding dependency:
```groovy
implementation "dev.inmo:colors.common:latest"
```
> INFO:
>
> All the samples below will represent `HEXAColor` with `r==0xaa`, `g==0xff`, `b==0x00` and `a==0xff`
This package contains mainly one file: [HEXAColor](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.colors.common/-h-e-x-a-color/index.html). This file
contains unified color with HEXA format. It consumes `UInt` by default constructor and r/g/b/a parameters in other main constructors:
```kotlin
HEXAColor(0xaaff00ffu) // 0xRGBAu as UInt
HEXAColor(r = 0xaa, g = 0xff, b = 0x00, a = 0xff)
HEXAColor(r = 0xaa, g = 0xff, b = 0x00, aOfOne = 1f)
```
Besides, you may use one of converters:
```kotlin
HEXAColor.fromAhex(0xffaaff00u) // 0xARGBu as UInt
HEXAColor.parse("rgba(aa, ff, 00, ff)")
HEXAColor.parse("rgba(aa, ff, 00)")
HEXAColor.parse("#af0")
HEXAColor.parse("#af0f")
HEXAColor.parse("#aaff00")
HEXAColor.parse("#aaff00ff")
```

View File

@ -0,0 +1,42 @@
group=dev.inmo
artifact=colors.common
package=$group.$artifact
central_package=$group/$artifact
# Colors [![Maven Central](https://maven-badges.herokuapp.com/maven-central/${central_package}/badge.svg)](https://maven-badges.herokuapp.com/maven-central/${central_package})
* `Group`: `$group`
* `ArtifactId`: `$artifact`
Adding dependency:
```groovy
implementation "$group:$artifact:latest"
```
> INFO:
>
> All the samples below will represent `HEXAColor` with `r==0xaa`, `g==0xff`, `b==0x00` and `a==0xff`
This package contains mainly one file: [HEXAColor](https://microutils.inmo.dev/micro_utils.dokka/dev.inmo.micro_utils.colors.common/-h-e-x-a-color/index.html). This file
contains unified color with HEXA format. It consumes `UInt` by default constructor and r/g/b/a parameters in other main constructors:
```kotlin
HEXAColor(0xaaff00ffu) // 0xRGBAu as UInt
HEXAColor(r = 0xaa, g = 0xff, b = 0x00, a = 0xff)
HEXAColor(r = 0xaa, g = 0xff, b = 0x00, aOfOne = 1f)
```
Besides, you may use one of converters:
```kotlin
HEXAColor.fromAhex(0xffaaff00u) // 0xARGBu as UInt
HEXAColor.parse("rgba(aa, ff, 00, ff)")
HEXAColor.parse("rgba(aa, ff, 00)")
HEXAColor.parse("#af0")
HEXAColor.parse("#af0f")
HEXAColor.parse("#aaff00")
HEXAColor.parse("#aaff00ff")
```

View File

@ -1,6 +1,6 @@
# TelegramBotAPI # TelegramBotAPI
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-7.1-blue)](https://core.telegram.org/bots/api-changelog#february-16-2024) [![Maven Central](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi/badge.svg)](https://maven-badges.herokuapp.com/maven-central/dev.inmo/tgbotapi) [![Supported version](https://img.shields.io/badge/Telegram%20Bot%20API-7.2-blue)](https://core.telegram.org/bots/api-changelog#march-31-2024)
<!--- [![Telegram Channel](./resources/tg_channel_qr.jpg)](https://t.me/ktgbotapi) ---> <!--- [![Telegram Channel](./resources/tg_channel_qr.jpg)](https://t.me/ktgbotapi) --->

View File

@ -0,0 +1,54 @@
import java.io.File
val templateEnding = ".template.md"
val singleArgumentRegex = Regex("^[\\w\\d]+$")
val splitterRegex = Regex("[ ]*=[ ]*")
val folder = File("./")
fun String.replaceVariables(variables: Map<String, String>): String {
var currentLine = this
variables.forEach { (k, v) ->
currentLine = currentLine.replace("\${${k}}", v)
if (k.matches(singleArgumentRegex)) {
currentLine = currentLine.replace("\$${k}", v)
}
}
return currentLine
}
fun generateFromTemplate(file: File) {
val targetFile = File(folder, file.name.replace(templateEnding, ".md"))
val variables = mutableMapOf<String, String>()
var writeVariables = true
var text = ""
file.readLines().forEach { line ->
when {
writeVariables && line.startsWith("#") -> {
writeVariables = false
}
writeVariables -> {
val splitted = line.split(splitterRegex)
if (splitted.size > 1) {
val k = splitted[0]
val v = splitted[1].replaceVariables(variables)
variables[k] = v
}
return@forEach
}
}
text += line.let {
line.replaceVariables(variables) + "\n"
}
}
targetFile.writeText(text)
println("${targetFile.name} has been recreated")
}
folder.listFiles().forEach { file ->
if (file.name.endsWith(templateEnding)) {
generateFromTemplate(file)
}
}

View File

@ -10,8 +10,10 @@ nav:
- Home: 'index.md' - Home: 'index.md'
- 'MicroUtils': - 'MicroUtils':
- 'micro_utils/index.md' - 'micro_utils/index.md'
- KDocs: 'https://microutils.inmo.dev/index.html'
- 'micro_utils/resources.md' - 'micro_utils/resources.md'
- 'micro_utils/startup.md' - 'micro_utils/startup.md'
- 'micro_utils/colors.md'
- 'Repos': - 'Repos':
- 'micro_utils/repos/index.md' - 'micro_utils/repos/index.md'
- 'micro_utils/repos/inmemory.md' - 'micro_utils/repos/inmemory.md'
@ -89,7 +91,7 @@ theme:
- content.action.view - content.action.view
- content.code.annotate - content.code.annotate
- content.code.copy - content.code.copy
# - content.tabs.link - content.tabs.link
- content.tooltips - content.tooltips
# - header.autohide # - header.autohide
# - navigation.expand # - navigation.expand