<quote>
You can also write your Coffee in a separate file, including it via a script tag.
For example (Java),
<script type="text/javascript" href="@{'/public/javascripts/sample.coffee'}"></script>
or (Scala),
<script type="text/javascript" href="@asset("/public/javascripts/sample.coffee")"></script>
The module handles the request and compiles the coffee on the fly.
</quote>
FWIW I've just checked in a couple of coffeescript examples.
To run it, grab the code & do a local build...
http://scalate.fusesource.org/source.html
http://scalate.fusesource.org/building.html
then run this...
cd samples/scalate-example
mvn jetty:run
then open
http://localhost:8080/coffee/index
there are 2 sample jade files which use embedded coffee or a separate
coffee file (using the .js extension in the <script src attribute>
https://github.com/scalate/scalate/tree/master/samples/scalate-example/src/main/webapp/coffee
e.g. here's a jade file references a separate .js file for a coffee
script which gets converted to .js on the server...
https://github.com/scalate/scalate/blob/master/samples/scalate-example/src/main/webapp/coffee/external.jade
> However, even if you add that, I'm not sure it'd give me what I want.
> Because as soon as you give me this ability, then I'm going to want
> the ability to concatenate and minimize my JS and CSS files.
Yeah, sounds like wro4j can give you that today; then someday soon we
can add something wro4j-like as I described in the separate thread...
http://groups.google.com/group/scalate/browse_thread/thread/2904bbdc8ca9dd46
I just added a sass/scss sample too btw
https://github.com/scalate/scalate/blob/master/samples/scalate-example/src/main/webapp/coffee/external.jade#L1
https://github.com/scalate/scalate/blob/master/samples/scalate-example/src/main/webapp/coffee/mysass.scss
though if you want to minify collections of css/sass/coffee/js today
the best option is wro4j (or some helper scala functions).
I was able to work something out. I changed external.jade to have:
script(src="/assets/foo.js" type="text/javascript")
Then I added a new route to my Play application:
GET /assets/{template} ScalateResource.process
My ScalateResource.scala class is as follows:
package controllers
import play.mvc._
object ScalateResource extends Controller {
def process(args: (Symbol, Any)*) = {
var template = params.get("template")
// replace .js with .coffee
template = template.replace(".js", ".coffee")
// replace .css with .scss
template = template.replace(".css", ".scss")
ScalateTemplate(template).render();
}
}
However, when I try to go to http://localhost:9000/assets/foo.js, I get:
TemplateException occured : Not a template file extension (md | markdown | ssp | scaml | mustache | jade), you requested: coffee
Any ideas are much appreciated.
Thanks,
Matt
Quick update. I was able to get past this because I discovered the Play CoffeeScript module[1] handles external CoffeeScript files. For example, in a Jade template:
script(type="text/javascript" src={uri("/public/javascripts/script.coffee")})
Thanks,
Matt
P.S. I was also able to find a Sass module: