All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.template.dust.TemplateLoaders.kt Maven / Gradle / Ivy

There is a newer version: 4.48.0.0
Show newest version
package org.http4k.template.dust

import java.io.File


internal fun loadFromFilesIn(baseDirectory: String): TemplateLoader =
    loadFromFilesIn(File(baseDirectory))


internal fun loadFromFilesIn(baseDirectory: File): TemplateLoader =
    fun(name: String) =
        File(baseDirectory, "$name.dust").takeIf(File::exists)?.readText()


internal fun loadFromResourcesIn(baseClasspathPackage: String): TemplateLoader {
    val resourceRoot = baseClasspathPackage.replace('.', '/')
    return fun(templateName: String) =
        ClassLoader.getSystemClassLoader().getResource(resourcePath(resourceRoot, templateName))?.readText()
}

private fun resourcePath(resourceRoot: String, templateName: String) =
    (if (resourceRoot.isEmpty()) "" else resourceRoot + "/") + templateName + ".dust"




© 2015 - 2025 Weber Informatics LLC | Privacy Policy