
org.http4k.template.ViewModel.kt Maven / Gradle / Ivy
package org.http4k.template
import org.http4k.core.Body
import org.http4k.core.ContentType
import org.http4k.lens.string
import org.http4k.websocket.WsMessage
import java.io.File
interface ViewModel {
/**
* This is the path of the template file - which matches the fully qualified classname. The templating suffix
* is added by the template implementation (eg. java.lang.String -> java/lang/String.hbs)
*/
fun template(): String = javaClass.name.replace('.', '/')
}
fun Body.Companion.viewModel(renderer: TemplateRenderer, contentType: ContentType) =
string(contentType)
.map({ throw UnsupportedOperationException("Cannot parse a ViewModel") }, renderer::invoke)
fun WsMessage.Companion.viewModel(renderer: TemplateRenderer) =
string().map({ throw UnsupportedOperationException("Cannot parse a ViewModel") }, renderer::invoke)
© 2015 - 2025 Weber Informatics LLC | Privacy Policy