diff --git a/.fleet/run.json b/.fleet/run.json index d665fc0..9d69c81 100644 --- a/.fleet/run.json +++ b/.fleet/run.json @@ -18,5 +18,12 @@ "program": "poetry", "args": ["run", "mkdocs", "serve"], }, + { + "type": "command", + "name": "Generate MicroUtils", + "program": "kotlin", + "args": ["../../generate_from_template.kts"], + "workingDir": "./docs/micro_utils/", + }, ] } diff --git a/docs/micro_utils/colors.md b/docs/micro_utils/colors.md new file mode 100644 index 0000000..dcf3bb7 --- /dev/null +++ b/docs/micro_utils/colors.md @@ -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") +``` + + diff --git a/docs/micro_utils/colors.template.md b/docs/micro_utils/colors.template.md new file mode 100644 index 0000000..7884a1e --- /dev/null +++ b/docs/micro_utils/colors.template.md @@ -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") +``` + + diff --git a/docs/tgbotapi/index.md b/docs/tgbotapi/index.md index 26b07ae..46c2cc3 100644 --- a/docs/tgbotapi/index.md +++ b/docs/tgbotapi/index.md @@ -1,6 +1,6 @@ # 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) diff --git a/generate_from_template.kts b/generate_from_template.kts new file mode 100644 index 0000000..ec87f62 --- /dev/null +++ b/generate_from_template.kts @@ -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 { + 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() + 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) + } +} diff --git a/mkdocs.yml b/mkdocs.yml index 9eb9fba..b0ba63c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -10,8 +10,10 @@ nav: - Home: 'index.md' - 'MicroUtils': - 'micro_utils/index.md' + - KDocs: 'https://microutils.inmo.dev/index.html' - 'micro_utils/resources.md' - 'micro_utils/startup.md' + - 'micro_utils/colors.md' - 'Repos': - 'micro_utils/repos/index.md' - 'micro_utils/repos/inmemory.md' @@ -89,7 +91,7 @@ theme: - content.action.view - content.code.annotate - content.code.copy - # - content.tabs.link + - content.tabs.link - content.tooltips # - header.autohide # - navigation.expand