Fix not loading functions on page with no data document
authorLanius Trolling <lanius@laniustrolling.dev>
Mon, 13 Mar 2023 17:58:41 +0000 (13:58 -0400)
committerLanius Trolling <lanius@laniustrolling.dev>
Mon, 13 Mar 2023 17:58:41 +0000 (13:58 -0400)
src/main/kotlin/info/mechyrdia/lore/preparser.kt

index 756be773fd2e2727acf0ca1cd7c9434582365d9e..34ed415b09b86926086791fbd60a9e8ccaf3055a 100644 (file)
@@ -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<String, Any?>()
        
        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)