Add support for imports

This commit is contained in:
Shadowfacts 2017-08-19 16:42:04 -04:00
parent c5f94ef738
commit a444838bf9
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 11 additions and 1 deletions

View File

@ -24,6 +24,8 @@ object EKT {
private val startStringRegex = Regex("([:=#])]")
private val endStringRegex = Regex("\\[([:=#])")
private val lastImportRegex = Regex("(import (.*?)\\n)+")
private val scriptPrefix = """
val _env = bindings["_env"] as net.shadowfacts.ekt.EKT.TemplateEnvironment
val _result = StringBuilder()
@ -67,7 +69,11 @@ _result.toString()
}
})
val script = scriptPrefix + template + scriptSuffix
val lines = template.split("\n")
val imports = lines.filter { it.trim().startsWith("import") }.joinToString("\n")
template = lines.filterNot { it.trim().startsWith("import") }.joinToString("\n")
val script = imports + scriptPrefix + template + scriptSuffix
if (env.cacheDir != null) {
env.cacheFile.apply {

View File

@ -1,3 +1,7 @@
[: import java.util.ArrayList :]
[= ArrayList::class.simpleName =]
Environment type: [= _env::class.simpleName =]
[= list.joinToString("\n") =]