Created
July 6, 2015 18:12
-
-
Save dozed/6a8fb465331d183fb107 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package foo | |
import java.io.{PrintWriter, StringWriter} | |
import org.fusesource.scalate.{TemplateEngine, DefaultRenderContext} | |
class SimpleTemplateEngine(templateSource: String) { | |
val templateEngine = new TemplateEngine() | |
def layoutTemplate(path: String, attributes: (String, Any)*): String = { | |
val uri = f"$templateSource/$path" | |
val buffer = new StringWriter() | |
val out = new PrintWriter(buffer) | |
val context = new DefaultRenderContext("", templateEngine, out) | |
attributes foreach { | |
case (k, v) => context.attributes(k) = v | |
} | |
templateEngine.layout(uri, context) | |
buffer.toString | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tests | |
import com.typesafe.config.ConfigFactory | |
import org.specs2.mutable._ | |
import scala.concurrent.Await | |
class TemplateSpecs extends Specification { | |
val templateEngine = new SimpleTemplateEngine("/home/user/code/path/to/templates") | |
"Template engine" should { | |
"Render a jade template" in { | |
val text = templateEngine.layoutTemplate("mail.verify-account-html.jade", attrs1: _*) | |
text must not empty | |
} | |
"Render a mustache template" in { | |
val text = templateEngine.layoutTemplate("mail.verify-account-text.mustache", attrs1: _*) | |
text must not empty | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment