From 5dd6a1f3f557c5f6e1f2c24f2f5ba0df0302f7b2 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Fri, 31 Jul 2020 12:29:23 +0600 Subject: [PATCH] add markup subsystem --- postssystem.markups.core/build.gradle | 85 ++++++++++++++++++ postssystem.markups.core/maven.publish.gradle | 60 +++++++++++++ postssystem.markups.core/publish.gradle | 55 ++++++++++++ postssystem.markups.core/publish_config.kpsb | 1 + .../markups/core/AbstractMarkupCreator.kt | 24 ++++++ .../postssystem/markups/core/MarkupCreator.kt | 21 +++++ postssystem.markups.html/build.gradle | 86 +++++++++++++++++++ postssystem.markups.html/gradle.properties | 1 + postssystem.markups.html/maven.publish.gradle | 60 +++++++++++++ postssystem.markups.html/publish.gradle | 55 ++++++++++++ postssystem.markups.html/publish_config.kpsb | 1 + .../markups/html/HtmlMarkupCreator.kt | 11 +++ .../markups/html/HtmlMarkupCreator.kt | 11 +++ settings.gradle | 6 ++ 14 files changed, 477 insertions(+) create mode 100644 postssystem.markups.core/build.gradle create mode 100644 postssystem.markups.core/maven.publish.gradle create mode 100644 postssystem.markups.core/publish.gradle create mode 100644 postssystem.markups.core/publish_config.kpsb create mode 100644 postssystem.markups.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core/AbstractMarkupCreator.kt create mode 100644 postssystem.markups.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core/MarkupCreator.kt create mode 100644 postssystem.markups.html/build.gradle create mode 100644 postssystem.markups.html/gradle.properties create mode 100644 postssystem.markups.html/maven.publish.gradle create mode 100644 postssystem.markups.html/publish.gradle create mode 100644 postssystem.markups.html/publish_config.kpsb create mode 100644 postssystem.markups.html/src/jsMain/kotlin/com/insanusmokrassar/postssystem/markups/html/HtmlMarkupCreator.kt create mode 100644 postssystem.markups.html/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/markups/html/HtmlMarkupCreator.kt diff --git a/postssystem.markups.core/build.gradle b/postssystem.markups.core/build.gradle new file mode 100644 index 00000000..f065c698 --- /dev/null +++ b/postssystem.markups.core/build.gradle @@ -0,0 +1,85 @@ +buildscript { + repositories { + mavenLocal() + jcenter() + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" + classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version" + } +} + +plugins { + id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version" + id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" +} + +project.version = "$core_version" +project.group = "com.insanusmokrassar" + +apply from: "publish.gradle" + +repositories { + mavenLocal() + jcenter() + mavenCentral() + maven { url "https://kotlin.bintray.com/kotlinx" } +} + +kotlin { + jvm() + js() + + sourceSets { + commonMain { + dependencies { + implementation kotlin('stdlib') + api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version" + + if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") { + api "com.insanusmokrassar:postssystem.core:$core_version" + } else { + api project(":postssystem.core") + } + + api "com.soywiz.korlibs.klock:klock:$klockVersion" + api "com.benasher44:uuid:$uuidVersion" + } + } + commonTest { + dependencies { + implementation kotlin('test-common') + implementation kotlin('test-annotations-common') + } + } + jvmMain { + dependencies { + implementation kotlin('stdlib-jdk8') + api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version" + } + } + jvmTest { + dependencies { + implementation kotlin('test-junit') + } + } + jsMain { + dependencies { + implementation kotlin('stdlib-js') + api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version" + } + } + jsTest { + dependencies { + implementation kotlin('test-js') + implementation kotlin('test-junit') + } + } + } +} diff --git a/postssystem.markups.core/maven.publish.gradle b/postssystem.markups.core/maven.publish.gradle new file mode 100644 index 00000000..c871a756 --- /dev/null +++ b/postssystem.markups.core/maven.publish.gradle @@ -0,0 +1,60 @@ +apply plugin: 'maven-publish' + +task javadocsJar(type: Jar) { + classifier = 'javadoc' +} + +afterEvaluate { + project.publishing.publications.all { + // rename artifacts + groupId "${project.group}" + if (it.name.contains('kotlinMultiplatform')) { + artifactId = "${project.name}" + } else { + artifactId = "${project.name}-$name" + } + } +} + +publishing { + publications.all { + artifact javadocsJar + + pom { + description = "PostsSystem Core Repos utility subproject" + name = "PostsSystem Core Repos" + url = "https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore" + + scm { + developerConnection = "scm:git:[fetch=]https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git[push=]https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git" + url = "https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git" + } + + developers { + + developer { + id = "InsanusMokrassar" + name = "Ovsiannikov Aleksei" + email = "ovsyannikov.alexey95@gmail.com" + } + + + developer { + id = "mi-ast" + name = "Michail Astafiev" + email = "astaf65@gmail.com" + } + + } + + licenses { + + license { + name = "Apache Software License 2.0" + url = "https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore/src/master/LICENSE" + } + + } + } + } +} \ No newline at end of file diff --git a/postssystem.markups.core/publish.gradle b/postssystem.markups.core/publish.gradle new file mode 100644 index 00000000..b8cf4528 --- /dev/null +++ b/postssystem.markups.core/publish.gradle @@ -0,0 +1,55 @@ +apply plugin: 'com.jfrog.bintray' + +apply from: "maven.publish.gradle" + +bintray { + user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER') + key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY') + filesSpec { + from "${buildDir}/publications/" + eachFile { + String directorySubname = it.getFile().parentFile.name + if (it.getName() == "module.json") { + if (directorySubname == "kotlinMultiplatform") { + it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.module") + } else { + it.setPath("${project.name}-${directorySubname}/${project.version}/${project.name}-${directorySubname}-${project.version}.module") + } + } else { + if (directorySubname == "kotlinMultiplatform" && it.getName() == "pom-default.xml") { + it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.pom") + } else { + it.exclude() + } + } + } + into "${project.group}".replace(".", "/") + } + pkg { + repo = "InsanusMokrassar" + name = "${project.name}" + vcsUrl = "https://github.com/PostsSystem/PostsSystemCore" + licenses = ["Apache-2.0"] + version { + name = "${project.version}" + released = new Date() + vcsTag = "${project.version}" + gpg { + sign = true + passphrase = project.hasProperty('signing.gnupg.passphrase') ? project.property('signing.gnupg.passphrase') : System.getenv('signing.gnupg.passphrase') + } + } + } +} + +bintrayUpload.doFirst { + publications = publishing.publications.collect { + if (it.name.contains('kotlinMultiplatform')) { + null + } else { + it.name + } + } - null +} + +bintrayUpload.dependsOn publishToMavenLocal \ No newline at end of file diff --git a/postssystem.markups.core/publish_config.kpsb b/postssystem.markups.core/publish_config.kpsb new file mode 100644 index 00000000..71046854 --- /dev/null +++ b/postssystem.markups.core/publish_config.kpsb @@ -0,0 +1 @@ +{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}","packageVcs":"https://github.com/PostsSystem/PostsSystemCore"},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore/src/master/LICENSE"}],"mavenConfig":{"name":"PostsSystem Markups Core subsystem","description":"PostsSystem Markups Core subsystem with base things for future markups modules","url":"https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore","vcsUrl":"https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"} \ No newline at end of file diff --git a/postssystem.markups.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core/AbstractMarkupCreator.kt b/postssystem.markups.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core/AbstractMarkupCreator.kt new file mode 100644 index 00000000..e6d29301 --- /dev/null +++ b/postssystem.markups.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core/AbstractMarkupCreator.kt @@ -0,0 +1,24 @@ +package com.insanusmokrassar.postssystem.markups.core + +import com.insanusmokrassar.postssystem.core.content.RegisteredContent +import com.insanusmokrassar.postssystem.core.content.api.ReadContentRepo +import com.insanusmokrassar.postssystem.core.post.PostId +import com.insanusmokrassar.postssystem.core.post.RegisteredPost +import com.insanusmokrassar.postssystem.core.post.repo.ReadPostsRepo + +abstract class AbstractMarkupCreator( + @Suppress("MemberVisibilityCanBePrivate") + protected val postsRepo: ReadPostsRepo, + @Suppress("MemberVisibilityCanBePrivate") + protected val postsContentRepo: ReadContentRepo +) : MarkupCreator { + override suspend fun drawOn(target: MarkupTarget, forPost: PostId) { + val post = postsRepo.getPostById(forPost) ?: return + val contents = post.content.mapNotNull { + postsContentRepo.getContentById(it) + } + drawOn(target, post, contents) + } + + abstract suspend fun drawOn(target: MarkupTarget, forPost: RegisteredPost, content: List) +} diff --git a/postssystem.markups.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core/MarkupCreator.kt b/postssystem.markups.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core/MarkupCreator.kt new file mode 100644 index 00000000..2535ea0d --- /dev/null +++ b/postssystem.markups.core/src/commonMain/kotlin/com/insanusmokrassar/postssystem/markups/core/MarkupCreator.kt @@ -0,0 +1,21 @@ +package com.insanusmokrassar.postssystem.markups.core + +import com.insanusmokrassar.postssystem.core.post.PostId + +/** + * System of markup for some target publishing system, which is drawing on [MarkupTarget]. + * + * Some markup system which knows, how to create the markup system inside of some [MarkupTarget]. This interface + * will be implemented by creators like: + * + * * Telegram + * * Web + * * etc. + * + * [MarkupTarget] here is just a platform, which can be used by [MarkupCreator] to create markup inside. + * + * For example, it could be some creator like "TelegramForHTMLMarkupBuilder" + */ +interface MarkupCreator { + suspend fun drawOn(target: MarkupTarget, forPost: PostId) +} diff --git a/postssystem.markups.html/build.gradle b/postssystem.markups.html/build.gradle new file mode 100644 index 00000000..abbbdd76 --- /dev/null +++ b/postssystem.markups.html/build.gradle @@ -0,0 +1,86 @@ +buildscript { + repositories { + mavenLocal() + jcenter() + mavenCentral() + } + + dependencies { + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath "org.jetbrains.kotlin:kotlin-serialization:$kotlin_version" + classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$gradle_bintray_plugin_version" + } +} + +plugins { + id "org.jetbrains.kotlin.multiplatform" version "$kotlin_version" + id "org.jetbrains.kotlin.plugin.serialization" version "$kotlin_version" +} + +project.version = "$core_version" +project.group = "com.insanusmokrassar" + +apply from: "publish.gradle" + +repositories { + mavenLocal() + jcenter() + mavenCentral() + maven { url "https://kotlin.bintray.com/kotlinx" } +} + +kotlin { + jvm() + js() + + sourceSets { + commonMain { + dependencies { + implementation kotlin('stdlib') + api "org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$kotlin_coroutines_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-common:$kotlin_serialisation_runtime_version" + + if ((project.hasProperty('RELEASE_MODE') && project.property('RELEASE_MODE') == "true") || System.getenv('RELEASE_MODE') == "true") { + api "com.insanusmokrassar:postssystem.markups.core:$core_version" + } else { + api project(":postssystem.markups.core") + } + } + } + commonTest { + dependencies { + implementation kotlin('test-common') + implementation kotlin('test-annotations-common') + } + } + jvmMain { + dependencies { + implementation kotlin('stdlib-jdk8') + api "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-runtime:$kotlin_serialisation_runtime_version" + + api "org.jetbrains.kotlinx:kotlinx-html-jvm:$kotlinx_html_version" + } + } + jvmTest { + dependencies { + implementation kotlin('test-junit') + } + } + jsMain { + dependencies { + implementation kotlin('stdlib-js') + api "org.jetbrains.kotlinx:kotlinx-coroutines-core-js:$kotlin_coroutines_version" + api "org.jetbrains.kotlinx:kotlinx-serialization-runtime-js:$kotlin_serialisation_runtime_version" + + api "org.jetbrains.kotlinx:kotlinx-html-js:$kotlinx_html_version" + } + } + jsTest { + dependencies { + implementation kotlin('test-js') + implementation kotlin('test-junit') + } + } + } +} diff --git a/postssystem.markups.html/gradle.properties b/postssystem.markups.html/gradle.properties new file mode 100644 index 00000000..a975e392 --- /dev/null +++ b/postssystem.markups.html/gradle.properties @@ -0,0 +1 @@ +kotlinx_html_version=0.7.1 diff --git a/postssystem.markups.html/maven.publish.gradle b/postssystem.markups.html/maven.publish.gradle new file mode 100644 index 00000000..c871a756 --- /dev/null +++ b/postssystem.markups.html/maven.publish.gradle @@ -0,0 +1,60 @@ +apply plugin: 'maven-publish' + +task javadocsJar(type: Jar) { + classifier = 'javadoc' +} + +afterEvaluate { + project.publishing.publications.all { + // rename artifacts + groupId "${project.group}" + if (it.name.contains('kotlinMultiplatform')) { + artifactId = "${project.name}" + } else { + artifactId = "${project.name}-$name" + } + } +} + +publishing { + publications.all { + artifact javadocsJar + + pom { + description = "PostsSystem Core Repos utility subproject" + name = "PostsSystem Core Repos" + url = "https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore" + + scm { + developerConnection = "scm:git:[fetch=]https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git[push=]https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git" + url = "https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git" + } + + developers { + + developer { + id = "InsanusMokrassar" + name = "Ovsiannikov Aleksei" + email = "ovsyannikov.alexey95@gmail.com" + } + + + developer { + id = "mi-ast" + name = "Michail Astafiev" + email = "astaf65@gmail.com" + } + + } + + licenses { + + license { + name = "Apache Software License 2.0" + url = "https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore/src/master/LICENSE" + } + + } + } + } +} \ No newline at end of file diff --git a/postssystem.markups.html/publish.gradle b/postssystem.markups.html/publish.gradle new file mode 100644 index 00000000..b8cf4528 --- /dev/null +++ b/postssystem.markups.html/publish.gradle @@ -0,0 +1,55 @@ +apply plugin: 'com.jfrog.bintray' + +apply from: "maven.publish.gradle" + +bintray { + user = project.hasProperty('BINTRAY_USER') ? project.property('BINTRAY_USER') : System.getenv('BINTRAY_USER') + key = project.hasProperty('BINTRAY_KEY') ? project.property('BINTRAY_KEY') : System.getenv('BINTRAY_KEY') + filesSpec { + from "${buildDir}/publications/" + eachFile { + String directorySubname = it.getFile().parentFile.name + if (it.getName() == "module.json") { + if (directorySubname == "kotlinMultiplatform") { + it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.module") + } else { + it.setPath("${project.name}-${directorySubname}/${project.version}/${project.name}-${directorySubname}-${project.version}.module") + } + } else { + if (directorySubname == "kotlinMultiplatform" && it.getName() == "pom-default.xml") { + it.setPath("${project.name}/${project.version}/${project.name}-${project.version}.pom") + } else { + it.exclude() + } + } + } + into "${project.group}".replace(".", "/") + } + pkg { + repo = "InsanusMokrassar" + name = "${project.name}" + vcsUrl = "https://github.com/PostsSystem/PostsSystemCore" + licenses = ["Apache-2.0"] + version { + name = "${project.version}" + released = new Date() + vcsTag = "${project.version}" + gpg { + sign = true + passphrase = project.hasProperty('signing.gnupg.passphrase') ? project.property('signing.gnupg.passphrase') : System.getenv('signing.gnupg.passphrase') + } + } + } +} + +bintrayUpload.doFirst { + publications = publishing.publications.collect { + if (it.name.contains('kotlinMultiplatform')) { + null + } else { + it.name + } + } - null +} + +bintrayUpload.dependsOn publishToMavenLocal \ No newline at end of file diff --git a/postssystem.markups.html/publish_config.kpsb b/postssystem.markups.html/publish_config.kpsb new file mode 100644 index 00000000..71046854 --- /dev/null +++ b/postssystem.markups.html/publish_config.kpsb @@ -0,0 +1 @@ +{"bintrayConfig":{"repo":"InsanusMokrassar","packageName":"${project.name}","packageVcs":"https://github.com/PostsSystem/PostsSystemCore"},"licenses":[{"id":"Apache-2.0","title":"Apache Software License 2.0","url":"https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore/src/master/LICENSE"}],"mavenConfig":{"name":"PostsSystem Markups Core subsystem","description":"PostsSystem Markups Core subsystem with base things for future markups modules","url":"https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore","vcsUrl":"https://git.insanusmokrassar.com/PostsSystem/PostsSystemCore.git","developers":[{"id":"InsanusMokrassar","name":"Ovsiannikov Aleksei","eMail":"ovsyannikov.alexey95@gmail.com"}]},"type":"Multiplatform"} \ No newline at end of file diff --git a/postssystem.markups.html/src/jsMain/kotlin/com/insanusmokrassar/postssystem/markups/html/HtmlMarkupCreator.kt b/postssystem.markups.html/src/jsMain/kotlin/com/insanusmokrassar/postssystem/markups/html/HtmlMarkupCreator.kt new file mode 100644 index 00000000..57a7bac7 --- /dev/null +++ b/postssystem.markups.html/src/jsMain/kotlin/com/insanusmokrassar/postssystem/markups/html/HtmlMarkupCreator.kt @@ -0,0 +1,11 @@ +package com.insanusmokrassar.postssystem.markups.html + +import com.insanusmokrassar.postssystem.core.content.api.ReadContentRepo +import com.insanusmokrassar.postssystem.core.post.repo.ReadPostsRepo +import com.insanusmokrassar.postssystem.markups.core.AbstractMarkupCreator +import kotlinx.html.FlowContent + +abstract class HtmlMarkupCreator( + postsRepo: ReadPostsRepo, + postsContentRepo: ReadContentRepo +) : AbstractMarkupCreator(postsRepo, postsContentRepo) diff --git a/postssystem.markups.html/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/markups/html/HtmlMarkupCreator.kt b/postssystem.markups.html/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/markups/html/HtmlMarkupCreator.kt new file mode 100644 index 00000000..57a7bac7 --- /dev/null +++ b/postssystem.markups.html/src/jvmMain/kotlin/com/insanusmokrassar/postssystem/markups/html/HtmlMarkupCreator.kt @@ -0,0 +1,11 @@ +package com.insanusmokrassar.postssystem.markups.html + +import com.insanusmokrassar.postssystem.core.content.api.ReadContentRepo +import com.insanusmokrassar.postssystem.core.post.repo.ReadPostsRepo +import com.insanusmokrassar.postssystem.markups.core.AbstractMarkupCreator +import kotlinx.html.FlowContent + +abstract class HtmlMarkupCreator( + postsRepo: ReadPostsRepo, + postsContentRepo: ReadContentRepo +) : AbstractMarkupCreator(postsRepo, postsContentRepo) diff --git a/settings.gradle b/settings.gradle index 96a4d38c..2832018b 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,8 +1,14 @@ rootProject.name='postssystem' + include ':postssystem.utils.repos' include ':postssystem.exposed.commons' include ':postssystem.utils.repos.exposed' + include ':postssystem.core' include ':postssystem.core.exposed' + include ':postssystem.core.publishing' include ':postssystem.core.publishing.exposed' + +include ':postssystem.markups.core' +include ':postssystem.markups.html'