Quantcast

Unfiltered Scalate patch to support layouts

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Unfiltered Scalate patch to support layouts

andrewoma
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() }
   }
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unfiltered Scalate patch to support layouts

Dustin Whitney
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,

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() }
   }



If you reply to this email, your message will be added to the discussion below:
http://databinder.3617998.n2.nabble.com/Unfiltered-Scalate-patch-to-support-layouts-tp6021558p6021558.html
To start a new topic under Unfiltered, email [hidden email]
To unsubscribe from Unfiltered, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unfiltered Scalate patch to support layouts

n8han
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

D

On Sun, Feb 13, 2011 at 8:20 PM, andrewoma [via Databinder] <[hidden email]> wrote:
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() }
   }



If you reply to this email, your message will be added to the discussion below:
http://databinder.3617998.n2.nabble.com/Unfiltered-Scalate-patch-to-support-layouts-tp6021558p6021558.html
To start a new topic under Unfiltered, email [hidden email]




If you reply to this email, your message will be added to the discussion below:
http://databinder.3617998.n2.nabble.com/Unfiltered-Scalate-patch-to-support-layouts-tp6021558p6021657.html
To start a new topic under Unfiltered, email [hidden email]
To unsubscribe from Unfiltered, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unfiltered Scalate patch to support layouts

andrewoma
In reply to this post by Dustin Whitney
Thanks Dustin! (You've also won an award for the fastest applied patch ;-)
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unfiltered Scalate patch to support layouts

teamon
Could you show an example how to use unfiltered + scalate with layouts?
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unfiltered Scalate patch to support layouts

n8han
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?


If you reply to this email, your message will be added to the discussion below:
http://databinder.3617998.n2.nabble.com/Unfiltered-Scalate-patch-to-support-layouts-tp6021558p6700915.html
To start a new topic under Unfiltered, email [hidden email]
To unsubscribe from Unfiltered, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Unfiltered Scalate patch to support layouts

chris_lewis
In reply to this post by teamon
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?


If you reply to this email, your message will be added to the discussion below:
http://databinder.3617998.n2.nabble.com/Unfiltered-Scalate-patch-to-support-layouts-tp6021558p6700915.html
To start a new topic under Unfiltered, email [hidden email]
To unsubscribe from Unfiltered, click here.

Loading...