From: Lanius Trolling Date: Sat, 22 Jun 2024 01:43:44 +0000 (-0400) Subject: Fix April 1st mode X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=4d6c5e8cf8846365b12f587732349796dced36e7;p=factbooks Fix April 1st mode --- diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/ParserPreprocess.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/ParserPreprocess.kt index 5e68d77..ba8debd 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/ParserPreprocess.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/ParserPreprocess.kt @@ -7,6 +7,7 @@ import io.ktor.server.request.* import kotlinx.coroutines.* import java.time.Instant import kotlin.math.roundToInt +import java.util.function.Function as JFunction class PreProcessorContext private constructor( val variables: MutableMap, @@ -337,9 +338,9 @@ enum class PreProcessorTags(val type: PreProcessorLexerTag) { } }), FOR_EACH(PreProcessorLexerTag { env, param, subNodes -> - val itemToContext: (ParserTree) -> Map = if (param == null) - ParserTree::asPreProcessorMap - else ({ mapOf(param to it) }) + val itemToContext: JFunction> = if (param == null) + JFunction(ParserTree::asPreProcessorMap) + else JFunction { mapOf(param to it) } val subTags = subNodes.filterIsInstance() val list = subTags.singleOrNull { it isTag "in" }?.subNodes @@ -349,14 +350,14 @@ enum class PreProcessorTags(val type: PreProcessorLexerTag) { val body = subTags.singleOrNull { it isTag "do" }?.subNodes if (list != null && body != null) list.mapSuspend { item -> - PreProcessorUtils.processWithContext(env, env.context + itemToContext(item), body) + PreProcessorUtils.processWithContext(env, env.context + itemToContext.apply(item), body) }.flatten() else formatErrorToParserTree("Expected child tag [in] to take list input and child tag [do] to take loop body") }), MAP(PreProcessorLexerTag { env, param, subNodes -> - val itemToContext: (ParserTree) -> Map = if (param == null) - ParserTree::asPreProcessorMap - else ({ mapOf(param to it) }) + val itemToContext: JFunction> = if (param == null) + JFunction(ParserTree::asPreProcessorMap) + else JFunction { mapOf(param to it) } val subTags = subNodes.filterIsInstance() val list = subTags.singleOrNull { it isTag "in" }?.subNodes @@ -366,7 +367,7 @@ enum class PreProcessorTags(val type: PreProcessorLexerTag) { val body = subTags.singleOrNull { it isTag "do" }?.subNodes if (list != null && body != null) list.mapSuspend { item -> - ParserTreeNode.Tag("item", null, PreProcessorUtils.processWithContext(env, env.context + itemToContext(item), body)) + ParserTreeNode.Tag("item", null, PreProcessorUtils.processWithContext(env, env.context + itemToContext.apply(item), body)) } else formatErrorToParserTree("Expected child tag [in] to take list input and child tag [do] to take loop body") }), diff --git a/src/jvmMain/kotlin/info/mechyrdia/lore/ViewsPrefs.kt b/src/jvmMain/kotlin/info/mechyrdia/lore/ViewsPrefs.kt index 99307e9..faf41db 100644 --- a/src/jvmMain/kotlin/info/mechyrdia/lore/ViewsPrefs.kt +++ b/src/jvmMain/kotlin/info/mechyrdia/lore/ViewsPrefs.kt @@ -44,11 +44,9 @@ enum class April1stMode { object April1stModeSerializer : KeyedEnumSerializer(April1stMode.entries) val ApplicationCall.april1stMode: April1stMode - get() = when (request.cookies["APRIL_1ST_MODE"]) { - "always" -> April1stMode.ALWAYS - "never" -> April1stMode.NEVER - else -> April1stMode.DEFAULT - } + get() = request.cookies["APRIL_1ST_MODE"]?.let { modeCookie -> + April1stMode.entries.firstOrNull { mode -> mode.name.equals(modeCookie, ignoreCase = true) } + } ?: April1stMode.DEFAULT class JoinToHtmlConsumer(val iterator: Iterator) { inline fun T.invokeReceiver(separator: T.() -> Unit, body: T.(E) -> Unit) {