Hi,
I've been playing with the Unfiltered Scalate support and encountered a problem using layouts. If you override the default engine to use a LayoutStrategy, it is ignored. I've traced the problem to scalate.scala. It renders the template directly instead of using the engine. The patch below (a one line change) fixes the problem, by routing rendering via the engine (which applies the layout strategy if set). Cheers, Andrew diff --git a/scalate/src/main/scala/scalate.scala b/scalate/src/main/scala/scalate.scala index a73cfea..c40876a 100644 --- a/scalate/src/main/scala/scalate.scala +++ b/scalate/src/main/scala/scalate.scala @@ -41,7 +41,7 @@ case class Scalate[A, B](request: HttpRequest[A], template: String, attributes:( val context = contextBuilder(request, res, engine) for(attr <- additionalAttributes) context.attributes(attr._1) = attr._2 for(attr <- attributes) context.attributes(attr._1) = attr._2 - scalateTemplate.render(context) + engine.layout(scalateTemplate, context) } finally { writer.close() } } |
Oh, nice catch. I changed the source, and while I was at it, I upgraded to Scalate 1.4
D On Sun, Feb 13, 2011 at 8:20 PM, andrewoma [via Databinder] <[hidden email]> wrote: Hi, |
Administrator
|
Thanks Dustin!
On 02/13/2011 04:07 PM, Dustin Whitney [via Databinder] wrote: Oh, nice catch. I changed the source, and while I was at it, I upgraded to Scalate 1.4 |
In reply to this post by Dustin Whitney
Thanks Dustin! (You've also won an award for the fastest applied patch ;-)
|
Could you show an example how to use unfiltered + scalate with layouts?
|
Administrator
|
Does anyone have an example of this they can share?
On 08/18/2011 05:17 PM, teamon [via Databinder] wrote: Could you show an example how to use unfiltered + scalate with layouts? |
In reply to this post by teamon
The Scalate ResponseWriter takes a handful of parameters (https://github.com/n8han/Unfiltered/blob/master/scalate/src/main/scala/scalate.scala#L9); one of them is a TemplateEngine. The default provided uses the NullLayouStrategy, so no layouts are applied. One solution is to provide your own, and one way to do this is to provide overrides in a trait which you mixin to any plans using scalate: trait ScalateConfig { import org.fusesource.scalate.TemplateEngine import org.fusesource.scalate.layout.DefaultLayoutStrategy implicit val engine = new TemplateEngine(List(new java.io.File("src/main/resources"))) engine.layoutStrategy = new DefaultLayoutStrategy(engine) } When you mix this trait into your plans, scalate will now employ layouts according to the DefaultLayoutStrategy. -chris On 08/18/2011 05:17 PM, teamon [via Databinder] wrote: Could you show an example how to use unfiltered + scalate with layouts? |
Free forum by Nabble | Edit this page |