enum class IndexSort {
ASCENDING,
DESCENDING,
- ;
}
typealias IndexSortProperty<T> = Pair<KProperty1<T, *>, IndexSort>
@Serializable(with = TextAlignmentSerializer::class)
enum class TextAlignment {
- LEFT {
- override fun processWidth(widthDiff: Int): Int {
- return 0
- }
- },
- CENTER {
- override fun processWidth(widthDiff: Int): Int {
- return widthDiff / 2
- }
- },
- RIGHT {
- override fun processWidth(widthDiff: Int): Int {
- return widthDiff
- }
- },
- ;
-
- abstract fun processWidth(widthDiff: Int): Int
+ LEFT,
+ CENTER,
+ RIGHT,
+}
+
+fun TextAlignment.processWidth(widthDiff: Int) = when (this) {
+ TextAlignment.LEFT -> 0
+ TextAlignment.CENTER -> widthDiff / 2
+ TextAlignment.RIGHT -> widthDiff
}
object TextAlignmentSerializer : KeyedEnumSerializer<TextAlignment>(TextAlignment.entries)
BLOCK,
ITEM,
LAYOUT,
- ;
-
- fun combine(env: LexerTagEnvironment<HtmlBuilderContext, HtmlBuilderSubject>, subNodes: ParserTree) = when (this) {
- INLINE -> HtmlLexerProcessor.combineInline(env, subNodes)
- BLOCK -> HtmlLexerProcessor.combineBlock(env, subNodes)
- ITEM -> HtmlLexerProcessor.combineItem(env, subNodes)
- LAYOUT -> HtmlLexerProcessor.combineLayout(env, subNodes)
- }
+}
+
+fun HtmlTagMode.combine(env: LexerTagEnvironment<HtmlBuilderContext, HtmlBuilderSubject>, subNodes: ParserTree) = when (this) {
+ HtmlTagMode.INLINE -> HtmlLexerProcessor.combineInline(env, subNodes)
+ HtmlTagMode.BLOCK -> HtmlLexerProcessor.combineBlock(env, subNodes)
+ HtmlTagMode.ITEM -> HtmlLexerProcessor.combineItem(env, subNodes)
+ HtmlTagMode.LAYOUT -> HtmlLexerProcessor.combineLayout(env, subNodes)
}
class HtmlTagLexerTag(
enum class PlainTextTagBehavior {
PASS_THROUGH,
PASS_THROUGH_SPACED,
- ABSORB
+ ABSORB,
}
abstract class PlainTextFormattingProcessor : LexerTagFallback<PlainTextBuilderContext, PlainTextBuilderSubject>, LexerTextProcessor<PlainTextBuilderContext, PlainTextBuilderSubject>, LexerLineBreakProcessor<PlainTextBuilderContext, PlainTextBuilderSubject>, LexerCombiner<PlainTextBuilderContext, PlainTextBuilderSubject> {
enum class LoreArticleFormat(val format: String? = null) {
HTML(null),
RAW_HTML("raw"),
- ;
}
object LoreArticleFormatSerializer : KeyedEnumSerializer<LoreArticleFormat>(LoreArticleFormat.entries, LoreArticleFormat::format)
SYSTEM(null),
LIGHT("light"),
DARK("dark"),
- ;
}
object PageThemeSerializer : KeyedEnumSerializer<PageTheme>(PageTheme.entries, PageTheme::attributeValue)
@Serializable(with = April1stModeSerializer::class)
enum class April1stMode {
- DEFAULT {
- override val isEnabled: Boolean
- get() = isApril1st()
- },
- ALWAYS {
- override val isEnabled: Boolean
- get() = true
- },
- NEVER {
- override val isEnabled: Boolean
- get() = false
- },
- ;
-
- abstract val isEnabled: Boolean
+ DEFAULT,
+ ALWAYS,
+ NEVER,
}
+val April1stMode.isEnabled: Boolean
+ get() = when (this) {
+ April1stMode.DEFAULT -> isApril1st()
+ April1stMode.ALWAYS -> true
+ April1stMode.NEVER -> false
+ }
+
object April1stModeSerializer : KeyedEnumSerializer<April1stMode>(April1stMode.entries)
val ApplicationCall.april1stMode: April1stMode
import io.ktor.server.application.ApplicationCall
import io.ktor.server.html.respondHtml
import io.ktor.server.response.respondText
-import kotlinx.html.*
+import kotlinx.html.Entities
+import kotlinx.html.FlowContent
+import kotlinx.html.HTML
+import kotlinx.html.a
+import kotlinx.html.blockQuote
+import kotlinx.html.h1
+import kotlinx.html.id
+import kotlinx.html.img
+import kotlinx.html.p
+import kotlinx.html.section
+import kotlinx.html.style
+import kotlinx.html.unsafe
import kotlinx.serialization.Serializable
import kotlinx.serialization.builtins.ListSerializer
import kotlinx.serialization.json.buildJsonObject
@Serializable(with = QuoteFormatSerializer::class)
enum class QuoteFormat(val format: String?) {
- HTML(null) {
- override suspend fun ApplicationCall.respondQuote(quote: Quote) {
- respondHtml(block = quote.toHtml(RANDOM_QUOTE_HTML_TITLE, this))
- }
- },
- RAW_HTML("raw") {
- override suspend fun ApplicationCall.respondQuote(quote: Quote) {
- respondHtml(block = quote.toRawHtml(RANDOM_QUOTE_HTML_TITLE, this))
- }
- },
- JSON("json") {
- override suspend fun ApplicationCall.respondQuote(quote: Quote) {
- respondText(quote.toJson(), contentType = ContentType.Application.Json)
- }
- },
- XML("xml") {
- override suspend fun ApplicationCall.respondQuote(quote: Quote) {
- respondXml { quote(quote) }
- }
- },
- ;
-
- abstract suspend fun ApplicationCall.respondQuote(quote: Quote)
+ HTML(null),
+ RAW_HTML("raw"),
+ JSON("json"),
+ XML("xml"),
+}
+
+suspend fun ApplicationCall.respondQuote(quote: Quote, format: QuoteFormat) = when (format) {
+ QuoteFormat.HTML -> respondHtml(block = quote.toHtml(RANDOM_QUOTE_HTML_TITLE, this))
+ QuoteFormat.RAW_HTML -> respondHtml(block = quote.toRawHtml(RANDOM_QUOTE_HTML_TITLE, this))
+ QuoteFormat.JSON -> respondText(quote.toJson(), contentType = ContentType.Application.Json)
+ QuoteFormat.XML -> respondXml { quote(quote) }
}
object QuoteFormatSerializer : KeyedEnumSerializer<QuoteFormat>(QuoteFormat.entries, QuoteFormat::format)
DAILY,
HOURLY,
ALWAYS,
- ;
}
val SitemapChangeFrequency.xmlValue: String
import info.mechyrdia.lore.recentCommentsRssFeedGenerator
import info.mechyrdia.lore.redirectHref
import info.mechyrdia.lore.respondAsset
+import info.mechyrdia.lore.respondQuote
import info.mechyrdia.lore.respondRss
import info.mechyrdia.lore.sitemap
import info.mechyrdia.lore.toCommentHtml
override suspend fun RoutingContext.handleCall() {
with(root) { call.filterCall() }
- with(format) { call.respondQuote(randomQuote()) }
+ call.respondQuote(randomQuote(), format)
}
}