Rocker.kt

  1. package com.hexagontk.templates.rocker

  2. import com.fizzed.rocker.Rocker
  3. import com.fizzed.rocker.runtime.RockerRuntime
  4. import com.fizzed.rocker.runtime.StringBuilderOutput
  5. import com.hexagontk.templates.TemplatePort
  6. import java.net.URL
  7. import java.util.*

  8. class Rocker(reloading: Boolean = false) : TemplatePort {

  9.     init {
  10.         RockerRuntime.getInstance().isReloading = reloading
  11.     }

  12.     override fun render(url: URL, context: Map<String, *>, locale: Locale): String =
  13.         Rocker.template(url.file)
  14.             .bind("context", context)
  15.             .render(StringBuilderOutput.FACTORY)
  16.             .toString()

  17.     override fun render(
  18.         name: String, templates: Map<String, String>, context: Map<String, *>, locale: Locale
  19.     ): String =
  20.         throw UnsupportedOperationException("Rocker does not support memory templates")
  21. }