From: Lanius Trolling Date: Mon, 13 Mar 2023 17:58:41 +0000 (-0400) Subject: Fix not loading functions on page with no data document X-Git-Url: https://gitweb.starshipfights.net/?a=commitdiff_plain;h=f65097b5b451659d73fa5fd52b2b1b6a2b95bf07;p=factbooks Fix not loading functions on page with no data document --- diff --git a/src/main/kotlin/info/mechyrdia/lore/preparser.kt b/src/main/kotlin/info/mechyrdia/lore/preparser.kt index 756be77..34ed415 100644 --- a/src/main/kotlin/info/mechyrdia/lore/preparser.kt +++ b/src/main/kotlin/info/mechyrdia/lore/preparser.kt @@ -90,7 +90,7 @@ object PreParser { is JsonArray -> json.map { convertJson(it, currentFile) } } - private fun loadJsonContext(name: String): Any? = + private fun loadJsonContext(name: String): Map<*, *> = File(Configuration.CurrentConfiguration.jsonDocDir).combineSafe("$name.json") .takeIf { it.isFile } ?.let { file -> @@ -99,13 +99,13 @@ object PreParser { if (data !is Map<*, *>) error("JSON Object expected in file $name, got $text") - data + PreParserFunctions.getFunctions() - } + data + } ?: emptyMap() fun preparse(name: String, content: String): String { return try { val template = compiler.compile(content) - val context = loadJsonContext(name) + val context = loadJsonContext(name) + PreParserFunctions.getFunctions() template.execute(context) } catch (ex: RuntimeException) { application.log.warn("Runtime error pre-parsing factbook $name", ex)