Created
March 22, 2012 06:29
-
-
Save eishay/2156645 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
//current is a reference to the Application object | |
import play.api.Play.current | |
object Templates extends Controller { | |
//name is the template name | |
//callback is the jQuery jsonp function name as in jQuery17104730278281494975_1332396095851 | |
def load(name: String, callback: String) = Action { request => | |
val path = current.getFile("/templates/%s.handlebars.html".format(name)); | |
val content = Files.readFile(path) | |
//making the file content javascript ready | |
val escaped = content.replace("\"", "\\\"").replace("\n", "\\n\\\n") | |
//making the escaped content jsonp ready as in jQuery17104730278281494975_1332396095851("<div id=\"q .... | |
Ok("""%s("%s")""".format(callback, escaped)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment