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

org.http4k.template.DustTemplates.kt Maven / Gradle / Ivy

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

import org.http4k.template.dust.Dust
import org.http4k.template.dust.TemplateLoader
import org.http4k.template.dust.loadFromFilesIn
import org.http4k.template.dust.loadFromResourcesIn
import java.net.URL

class DustTemplates(
    private val precachePoolSize: Int = 0,
    private val dustPluginScripts: List = emptyList()

) : Templates {
    
    override fun Caching(baseTemplateDir: String): TemplateRenderer =
        dust4Http4K(true, loadFromFilesIn(baseTemplateDir))

    override fun CachingClasspath(baseClasspathPackage: String): TemplateRenderer =
        dust4Http4K(true, loadFromResourcesIn(baseClasspathPackage))

    override fun HotReload(baseTemplateDir: String): TemplateRenderer =
        dust4Http4K(false, loadFromFilesIn(baseTemplateDir))

    private fun dust4Http4K(cacheTemplates: Boolean, loader: TemplateLoader): (ViewModel) -> String {
        val dust = Dust(
            cacheTemplates = cacheTemplates,
            precachePoolSize = precachePoolSize,
            dustPluginScripts = dustPluginScripts,
            loader = loader)
        
        return fun(viewModel: ViewModel) =
            dust.withTemplates { it.expandTemplate(viewModel.template(), viewModel,
                onMissingTemplate = { throw ViewNotFound(viewModel) })
            }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy