I don't know enough about play-scala and play to be sure; what happens
if you try use play-scalate with Java controllers?
--
James
-------
http://macstrac.blogspot.com/
Open Source Integration
http://fusesource.com/
I wonder if play-scalate should add a JavaScalateController to make it
easier to extend from Java code?
> Please tell me if I can use scalate in plain java code? If is, I think
> we can use scalate from java controller too.
There's no reason why you can't use Scalate from Java code. We might
want to make a Java API that hides some of its Scala-isms maybe.
Though a new JavaScalateController is maybe a good place for this?
2010/8/6 Tim <che...@gmail.com>:
--
Regards,
Hiram
Blog: http://hiramchirino.com
Open Source SOA
http://fusesource.com/
You can use Scalate as a servlet for scaml / jade / ssp / mustache.
Integrating Scalate into JSPs so it can work with JSP tag libraries is
going to be harder; but there's no reason why you couldn't write a JSP
tag which evaluates its body using Scalate maybe
You can do exactly the same thing in scaml too. Just use scala
expressions. In scaml thats "=" on the start of a line or {} in
attribute values or #{foo} inside text
%p
= someMethodCall(1, 2, 3)
%h1 Hello #{user.name}
%a{:href => {createSomeLinkUrl("hey")}, :title => "Some title"} My Link
etc
To expose functions to Scalate scripts (ssp/scaml) you can either just
import methods from companion objects, or import attribute methods or
create objects and import their methods (or use the objects directly)
-@ import val someAttribute: MyType
or create a helper object in your template...
- val helper = new SomeHelperObject
- import helper._
To avoid adding common imports to all templates you can set the
imports you want to add on the TemplateEngine globally if you wish.
Also if you put your templates in the sample package structure as your
code, you don't need to explicitly import the fully qualified class
name.
We should be able to include JSP fragments inside servlets (so they
can evaluate using JSP and evaluate whatever tag libraries are in
them) then process them or lay them out using Scalate.
Or vice versa.
That didn't come out right - let me try again.
A Scalate template should be able to do a kind of server-side include,
evaluating an arbitrary servlet URI (passing parameters etc) so that
it can evaluate any servlet - such as a JSP page with some custom tags
on it - then the Scalate template can render/process the servlets
output.
> Or vice versa.
Or the JSP page can include the Scalate template using servlet includes
The TemplateEngine instance is meant to be used like a application
wide singleton. It is thread safe and handles caching the scala
compiler instance and compiled templates so that subsequent compiles
are faster. The first page accessed is usually extra slow since it's
setting up the compiler. After that, subsequent compiles are faster
too. But like TIm said, if you precompile, the compiler is never even
booted up so that's even faster still, but then you loose the ability
to hot reload changes to the templates.
--
As I said, maybe we can have a JavaScalateController? Ideally we'd be
able to reuse the code in play-scalate but just provide a different
controller. Or create a more Java-friendly facade for Scalate so its
easier to use from a Java controller in Play?
http://github.com/pk11/play-scalate/issues#issue/5
http://scalate.assembla.com/spaces/scalate/support/tickets/129