changes in markup common system

This commit is contained in:
InsanusMokrassar 2020-08-01 10:38:22 +06:00
parent 47805b9e91
commit e35d578490
5 changed files with 47 additions and 33 deletions

View File

@ -6,19 +6,19 @@ import com.insanusmokrassar.postssystem.core.post.PostId
import com.insanusmokrassar.postssystem.core.post.RegisteredPost
import com.insanusmokrassar.postssystem.core.post.repo.ReadPostsRepo
abstract class AbstractMarkupBuilderFactory<MarkupTarget>(
abstract class AbstractMarkupPlugin<MarkupTarget>(
@Suppress("MemberVisibilityCanBePrivate")
protected val postsRepo: ReadPostsRepo,
@Suppress("MemberVisibilityCanBePrivate")
protected val postsContentRepo: ReadContentRepo
) : MarkupBuilderFactory<MarkupTarget> {
override suspend fun drawOn(target: MarkupTarget, forPost: PostId) {
val post = postsRepo.getPostById(forPost) ?: return
) : MarkupPlugin<MarkupTarget> {
override suspend fun drawMarkupBuilder(on: MarkupTarget, postId: PostId) {
val post = postsRepo.getPostById(postId) ?: return
val contents = post.content.mapNotNull {
postsContentRepo.getContentById(it)
}
drawOn(target, post, contents)
drawMarkupBuilder(on, post, contents)
}
abstract suspend fun drawOn(target: MarkupTarget, forPost: RegisteredPost, content: List<RegisteredContent>)
abstract suspend fun drawMarkupBuilder(target: MarkupTarget, forPost: RegisteredPost, content: List<RegisteredContent>)
}

View File

@ -1,21 +0,0 @@
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 [MarkupBuilderFactory] to create markup inside.
*
* For example, it could be some creator like "TelegramForHTMLMarkupBuilder"
*/
interface MarkupBuilderFactory<MarkupTarget> {
suspend fun drawOn(target: MarkupTarget, forPost: PostId)
}

View File

@ -0,0 +1,35 @@
package com.insanusmokrassar.postssystem.markups.core
import com.insanusmokrassar.postssystem.core.post.PostId
/**
* That is the plugin for platform, which is able to be drawn on the [MarkupTarget].
*
* * Plugin could be some Telegram plugin
* * [MarkupTarget] could be web.
*/
interface MarkupPlugin<MarkupTarget> {
/**
* This name will be used in `select`-questions on site
*/
val name: String
/**
* Link to icon which will be used for links onto this plugin
*/
val iconLink: String?
/**
* Drawing on [MarkupTarget].
*
* As a result, plugin must use [MarkupTarget] as a canvas to create the builder of markup. This fun
* will be implemented by creators like:
*
* * Telegram
* * Web
* * etc.
*
* For example, it could be some creator like "TelegramForHTMLMarkupBuilder"
*/
suspend fun drawMarkupBuilder(on: MarkupTarget, postId: PostId)
}

View File

@ -2,10 +2,10 @@ 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.AbstractMarkupBuilderFactory
import com.insanusmokrassar.postssystem.markups.core.AbstractMarkupPlugin
import kotlinx.html.FlowContent
abstract class HtmlMarkupBuilderFactory(
abstract class HtmlMarkupPlugin(
postsRepo: ReadPostsRepo,
postsContentRepo: ReadContentRepo
) : AbstractMarkupBuilderFactory<FlowContent>(postsRepo, postsContentRepo)
) : AbstractMarkupPlugin<FlowContent>(postsRepo, postsContentRepo)

View File

@ -2,10 +2,10 @@ 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.AbstractMarkupBuilderFactory
import com.insanusmokrassar.postssystem.markups.core.AbstractMarkupPlugin
import kotlinx.html.FlowContent
abstract class HtmlMarkupBuilderFactory(
abstract class HtmlMarkupPlugin(
postsRepo: ReadPostsRepo,
postsContentRepo: ReadContentRepo
) : AbstractMarkupBuilderFactory<FlowContent>(postsRepo, postsContentRepo)
) : AbstractMarkupPlugin<FlowContent>(postsRepo, postsContentRepo)