Scalate in Play 1.2.3
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 controllers { | |
import play._ | |
import play.mvc._ | |
object Scalate { | |
import java.io._ | |
import org.fusesource.scalate._ | |
import org.fusesource.scalate.util._ | |
lazy val scalateEngine = { | |
val engine = new TemplateEngine | |
engine.resourceLoader = new FileResourceLoader(Some(Play.getFile("/app/views"))) | |
engine.classpath = Play.getFile("/tmp/classes").getAbsolutePath | |
engine.workingDirectory = Play.getFile("tmp") | |
engine.combinedClassPath = true | |
engine.classLoader = Play.classloader | |
engine | |
} | |
case class Template(name:String) { | |
def render(args:(Symbol,Any)*) = { | |
scalateEngine.layout(name, args.map {case (k,v) => k.name -> v} toMap) | |
} | |
} | |
def apply(template:String) = Template(template) | |
} | |
object Application extends Controller { | |
import views.Application._ | |
def index = { | |
Scalate("yop.jade").render('user -> model.User("Guillaume")) | |
} | |
} | |
} | |
package model { | |
case class User(name:String) | |
} |
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
-@ var user: model.User | |
p Hi #{user.name}, | |
- for(i <- 1 to 3) | |
p= i | |
p See, I can count! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment