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

com.github.andriykuba.play.handlebars.scala.HandlebarsSupport.scala Maven / Gradle / Ivy

Go to download

Handlebars templates based on Java port of handlebars with special handlers for Play Framework

There is a newer version: 2.6.7
Show newest version
package com.github.andriykuba.play.handlebars.scala

import com.github.andriykuba.play.handlebars.HandlebarsApi
import play.api.i18n.Lang
import play.twirl.api.Content
import play.api.http.Writeable
import play.api.mvc.Codec
import play.api.http.ContentTypes

trait HandlebarsSupport {
  def handlebarsApi: HandlebarsApi
  
  /**
   * Render handlebars template with the current language
   */
  def render(templateId: String, jsonData:AnyRef)(implicit lang: Lang): Content = {
    return handlebarsApi.html(templateId, jsonData, lang.code)
  }
  
  /**
   * Write content to the result
   */
  implicit def writableHttp(implicit codec: Codec): Writeable[Content] =
    Writeable[Content]((result:Content) => codec.encode(result.body), Some(ContentTypes.HTML))
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy