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

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

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

import org.http4k.core.Body
import org.http4k.core.ContentType
import org.http4k.lens.string
import org.http4k.websocket.WsMessage

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 - 2024 Weber Informatics LLC | Privacy Policy