Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Fixing Play Scalate
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  16 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Matt Raible  
View profile  
 More options Aug 30 2011, 3:17 pm
From: Matt Raible <mrai...@gmail.com>
Date: Tue, 30 Aug 2011 12:17:35 -0700 (PDT)
Local: Tues, Aug 30 2011 3:17 pm
Subject: Fixing Play Scalate
Hello all,

I've tried contacting the Play-Scalate project owner, but haven't had
a response. I'm trying to upgrade the library to the latest
dependencies to get it working with Play 1.2.3 and Scalate 1.5.1. I've
forked the project and committed the following changes to try and get
it working.

https://github.com/mraible/play-scalate/commit/5743135cf6b6cfafe300f9...

There's a good chance I've messed things up, but there's less
compilation issues and it feels like I'm making progress. However, I'm
unable to diagnose and figure out how to solve the following
compilation error.

$ ant
Buildfile: /Users/mraible/dev/play-scalate/build.xml

clean:
   [delete] Deleting directory /Users/mraible/dev/play-scalate/tmp

build:
    [mkdir] Created dir: /Users/mraible/dev/play-scalate/tmp/classes
   [scalac] Compiling 7 source files to /Users/mraible/dev/play-
scalate/tmp/classes
   [scalac] error: class file needed by Binding is missing.
   [scalac] reference type Serializable of package scala refers to
nonexisting symbol.
   [scalac] one error found

BUILD FAILED
/Users/mraible/dev/play-scalate/build.xml:34: Compile failed with 1
error; see the compiler error output for details.

Total time: 8 seconds

If you have any advice, I'd love to hear it.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guillaume Bort  
View profile  
 More options Aug 30 2011, 3:50 pm
From: Guillaume Bort <guillaume.b...@gmail.com>
Date: Tue, 30 Aug 2011 21:50:09 +0200
Local: Tues, Aug 30 2011 3:50 pm
Subject: Re: [play-framework] Fixing Play Scalate
It looks like an incompatible Scala version error. The play scala
module currently use Scala 2.8.1, what is the Scala version needed by
Scalate?

--
Guillaume Bort, http://guillaume.bort.fr

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Aug 30 2011, 4:12 pm
From: Matt Raible <mrai...@gmail.com>
Date: Tue, 30 Aug 2011 13:12:16 -0700 (PDT)
Local: Tues, Aug 30 2011 4:12 pm
Subject: Re: Fixing Play Scalate
Good catch. If you look at the Scalate homepage, it says it's "Scala
2.8" template engine, but if you dig through the release notes, you
can see that they upgraded to 2.9 in 1.5.

On Aug 30, 1:50 pm, Guillaume Bort <guillaume.b...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Aug 30 2011, 4:22 pm
From: Matt Raible <mrai...@gmail.com>
Date: Tue, 30 Aug 2011 13:22:14 -0700 (PDT)
Local: Tues, Aug 30 2011 4:22 pm
Subject: Re: Fixing Play Scalate
I changed the dependencies to use the Scala 2.8.1 compiler and
downgraded to Scalate 2.4.1 (which says it uses 2.8.1). This results
in the following error when building:

$ ant
Buildfile: /Users/mraible/dev/play-scalate/build.xml

clean:
   [delete] Deleting directory /Users/mraible/dev/play-scalate/tmp

build:
    [mkdir] Created dir: /Users/mraible/dev/play-scalate/tmp/classes
   [scalac] Compiling 7 source files to /Users/mraible/dev/play-
scalate/tmp/classes
   [scalac] error: class file needed by ScalaController is missing.
   [scalac] reference value dispatch of package <root> refers to
nonexisting symbol.
   [scalac] one error found

BUILD FAILED
/Users/mraible/dev/play-scalate/build.xml:34: Compile failed with 1
error; see the compiler error output for details.

On Aug 30, 2:12 pm, Matt Raible <mrai...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guillaume Bort  
View profile  
 More options Aug 31 2011, 3:57 am
From: Guillaume Bort <guillaume.b...@gmail.com>
Date: Wed, 31 Aug 2011 09:57:28 +0200
Local: Wed, Aug 31 2011 3:57 am
Subject: Re: [play-framework] Re: Fixing Play Scalate
Again it looks like an incompatible Scala library in the compile path.
Perhaps it is another library, can you list the jar files you have
added?

--
Guillaume Bort, http://guillaume.bort.fr

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Aug 31 2011, 12:41 pm
From: Matt Raible <mrai...@gmail.com>
Date: Wed, 31 Aug 2011 09:41:58 -0700 (PDT)
Local: Wed, Aug 31 2011 12:41 pm
Subject: Re: Fixing Play Scalate
Here's the JAR files I have in the lib directory:

play-scala-20110830.jar
scala-compiler-2.8.1.jar
scala-library-2.8.1.jar
scalate-core-1.4.1.jar
scalate-util-1.4.1.jar
scalatest-1.2-for-scala-2.8.0.RC7-SNAPSHOT.jar

I've checked in all my changes to https://github.com/mraible/play-scalate

On Aug 31, 1:57 am, Guillaume Bort <guillaume.b...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guillaume Bort  
View profile  
 More options Aug 31 2011, 3:43 pm
From: Guillaume Bort <guillaume.b...@gmail.com>
Date: Wed, 31 Aug 2011 21:43:09 +0200
Local: Wed, Aug 31 2011 3:43 pm
Subject: Re: [play-framework] Re: Fixing Play Scalate
Matt,

Probably a better (and simpler) start for you, here is my test to make
Scalate work with the current Play version (my test use Jade):

https://gist.github.com/1184490

All you need is to drop scalate-core and scalate-utils jars into the
lib directory of your application (or add them as managed dependencies
to the yaml file).

There is no clean error report yet, but it should be really easy to
add for compilation errors since they already contain the problem
position. Not sure how difficult it will be to report properly
execution errors.

--
Guillaume Bort, http://guillaume.bort.fr

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Aug 31 2011, 5:16 pm
From: Matt Raible <mrai...@gmail.com>
Date: Wed, 31 Aug 2011 15:16:16 -0600
Local: Wed, Aug 31 2011 5:16 pm
Subject: Re: [play-framework] Re: Fixing Play Scalate
Thanks Guillaume!

I was able to use this example to get things working.

Improvements I'd like to see:

1. Allow the Scalate syntax to be configurable.

I did this with the following in Scalate:

 case class Template(name: String) {
   val scalateType = "." + Play.configuration.get("scalate");

   def render(args: (Symbol, Any)*) = {
     scalateEngine.layout(name + scalateType, args.map {
       case (k, v) => k.name -> v
     } toMap)
   }
 }

2. Like regular templates, change things so def index {} in Application can have something like the following:

 def index = {
   render('user -> User("Guillaume"))
 }

And "Application/index" will be passed into the Scalate constructor. What's the best way to do this? Create a ScalateController that overrides render() and is able to introspect the class/method names?

Thanks,

Matt

On Aug 31, 2011, at 1:43 PM, Guillaume Bort wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Aug 31 2011, 11:42 pm
From: Matt Raible <mrai...@gmail.com>
Date: Wed, 31 Aug 2011 20:42:46 -0700 (PDT)
Local: Wed, Aug 31 2011 11:42 pm
Subject: Re: Fixing Play Scalate

On Aug 31, 3:16 pm, Matt Raible <mrai...@gmail.com> wrote:

I was able to get this working by creating a ScalateController as
follows:

package controllers

import play.mvc.{Http, Controller}
import models.User._

class ScalateController extends Controller {

  def render(args: (Symbol, Any)*) = {
    def defaultTemplate = Http.Request.current().action.replace(".",
"/")
    Scalate(defaultTemplate).render(args: _*);
  }

}

Then my controller's index() method is as simple as:

  def index = {
    render('user -> User("Raible"))
  }

I'd like to further simplify things to match the Hello World example
for Java (http://www.playframework.org/documentation/1.0/firstapp).

How would I go about modifying things so I can have a method like the
following?

  def sayHello(name: String) = {
    render(name)
  }

Without having to do render('name -> name)?

In my Jade template, I'd also like to simplify and not have to define
"name" as a variable. Currently, I have to have the following in
sayHello.jade:

-@ var name: String
p Hi #{name: String}

Thanks for any advice.

Matt


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guillaume Bort  
View profile  
 More options Sep 1 2011, 4:16 am
From: Guillaume Bort <guillaume.b...@gmail.com>
Date: Thu, 1 Sep 2011 10:16:26 +0200
Local: Thurs, Sep 1 2011 4:16 am
Subject: Re: [play-framework] Re: Fixing Play Scalate

> class ScalateController extends Controller {

>  def render(args: (Symbol, Any)*) = {
>    def defaultTemplate = Http.Request.current().action.replace(".",
> "/")
>    Scalate(defaultTemplate).render(args: _*);
>  }
> }

Yes, but you should use a Trait instead, so it's easier to mix several
concerns into your controller.

object Application extends Controller with Scalate {
...

}
> How would I go about modifying things so I can have a method like the
> following?

>  def sayHello(name: String) = {
>    render(name)
>  }

In Java, this feature relies on heavy bytecode manipulation that we
have disabled for Scala. In theory for your simple use case it could
work, but Scala is way more complicated and there is a lot of
constructs where it would not be possible to track local variable
names properly.

> In my Jade template, I'd also like to simplify and not have to define
> "name" as a variable. Currently, I have to have the following in
> sayHello.jade:

> -@ var name: String
> p Hi #{name: String}

I don't know if it is possible with Scalate? If yes, there should be a
configuration setting to set somewhere on the TemplateEngine.

--
Guillaume ...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Sep 1 2011, 6:56 pm
From: Matt Raible <mrai...@gmail.com>
Date: Thu, 1 Sep 2011 16:56:47 -0600
Local: Thurs, Sep 1 2011 6:56 pm
Subject: Re: [play-framework] Re: Fixing Play Scalate
Thanks for the advice. Now I have it working with Scalate as a trait.

The next issue I'm running into is running it in prod mode. Is there any way to stop Groovy from trying to compile my Jade templates?

$ play run
~        _            _
~  _ __ | | __ _ _  _| |
~ | '_ \| |/ _' | || |_|
~ |  __/|_|\____|\__ (_)
~ |_|            |__/  
~
~ play! 1.2.3, http://www.playframework.org
~
~ Ctrl+C to stop
~
16:49:32,968 INFO  ~ Starting /Users/mraible/dev/play-more
16:49:32,973 INFO  ~ Module coffee is available (/Users/mraible/dev/play-more/modules/coffee-1.0)
16:49:32,974 INFO  ~ Module scala is available (/opt/tools/play-1.2.1/modules/scala-0.9.1)
16:49:34,492 INFO  ~ Scala support is active
16:49:34,642 INFO  ~ Scala support is active
16:49:34,643 INFO  ~ Precompiling ...
Compiling:
       /Users/mraible/dev/play-more/modules/coffee-1.0/app/tags/CoffeeTags.java
16:49:37,491 ERROR ~

@67iec0he2
Cannot start in PROD mode with errors

Template compilation error (In /app/views/Application/index.jade around line 2)
The template /app/views/Application/index.jade does not compile : #{user.name} is not closed.

play.exceptions.TemplateCompilationException: #{user.name} is not closed.
       at play.templates.TemplateCompiler.generate(TemplateCompiler.java:102)
       at play.templates.TemplateCompiler.compile(TemplateCompiler.java:15)
       at play.templates.GroovyTemplateCompiler.compile(GroovyTemplateCompiler.java:4 1)
       at play.templates.TemplateCompiler.compile(TemplateCompiler.java:26)
       at play.templates.TemplateLoader.load(TemplateLoader.java:82)
       at play.templates.TemplateLoader.scan(TemplateLoader.java:222)
       at play.templates.TemplateLoader.scan(TemplateLoader.java:235)
       at play.templates.TemplateLoader.scan(TemplateLoader.java:235)
       at play.templates.TemplateLoader.getAllTemplate(TemplateLoader.java:205)
       at play.Play.preCompile(Play.java:570)
       at play.Play.init(Play.java:291)
       at play.server.Server.main(Server.java:158)

On Sep 1, 2011, at 2:16 AM, Guillaume Bort wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Guillaume Bort  
View profile  
 More options Sep 2 2011, 4:29 am
From: Guillaume Bort <guillaume.b...@gmail.com>
Date: Fri, 2 Sep 2011 10:29:53 +0200
Local: Fri, Sep 2 2011 4:29 am
Subject: Re: [play-framework] Re: Fixing Play Scalate
Easy way: use another folder than view. Otherwise you can create a
plugin then redefine loadTemplate to ignore Scalates one (return null
as this interface is defined in the Java part):

override def loadTemplate(file:VirtualFile )

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Sep 2 2011, 10:53 am
From: Matt Raible <mrai...@gmail.com>
Date: Fri, 2 Sep 2011 08:53:03 -0600
Local: Fri, Sep 2 2011 10:53 am
Subject: Re: [play-framework] Re: Fixing Play Scalate
Thanks! The easy way worked and it's "good enough" for now.

On Sep 2, 2011, at 2:29 AM, Guillaume Bort wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Oct 16 2011, 10:23 am
From: Matt Raible <mrai...@gmail.com>
Date: Sun, 16 Oct 2011 07:23:55 -0700 (PDT)
Local: Sun, Oct 16 2011 10:23 am
Subject: Re: Fixing Play Scalate
What's the best way to make renderArgs and local variable names
available to my Scalate templates? Here's a method I wrote to populate
them:

  def populateRenderArgs(args: (Symbol, Any)*) = {
    val renderArgs = Scope.RenderArgs.current();
    for (o <- args) {
      val names =
LocalVariablesNamesTracer.getAllLocalVariableNames(o);
      for (name <- names) {
        renderArgs.put(name, o);
      }
    }

    renderArgs.put("session", Scope.Session.current());
    renderArgs.put("request", Http.Request.current());
    renderArgs.put("flash", Scope.Flash.current());
    renderArgs.put("params", Scope.Params.current());
    renderArgs.put("errors", Validation.errors());
  }

However, I'm unsure of how to combine renderArgs with my args:

  case class Template(name: String) {

    def render(args: (Symbol, Any)*) = {
      // this doesn't work: args ++ Scope.RenderArgs.current().data;
      scalateEngine.layout(name + scalateType, args.map {
        case (k, v) => k.name -> v
      } toMap)
    }
  }

Thanks for any advice.

Matt

On Sep 2, 8:53 am, Matt Raible <mrai...@gmail.com> wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Oct 16 2011, 6:30 pm
From: Matt Raible <mrai...@gmail.com>
Date: Sun, 16 Oct 2011 16:30:42 -0600
Local: Sun, Oct 16 2011 6:30 pm
Subject: Re: [play-framework] Re: Fixing Play Scalate
I figured this out today. Here's my populateRenderArgs method:

  def populateRenderArgs(args: (Symbol, Any)*) = {
    val renderArgs = Scope.RenderArgs.current();

    args.foreach {
      o =>
        renderArgs.put(o._1.name, o._2)
    }

    renderArgs.put("session", Scope.Session.current());
    renderArgs.put("request", Http.Request.current());
    renderArgs.put("flash", Scope.Flash.current());
    renderArgs.put("params", Scope.Params.current());
    renderArgs.put("errors", Validation.errors());
  }

Then I call it from my Template class and convert the RenderArgs map to a Scalate friendly map.

  case class Template(name: String) {

    import scala.collection.JavaConversions._

    def render(args: (Symbol, Any)*) = {
      populateRenderArgs(args: _*)
      val convertedArgs: Map[String, Any] = Scope.RenderArgs.current().data.toMap
      val argsMap = convertedArgs.map {
        case (k, v) => k -> v
      }.toMap

      scalateEngine.layout(name + scalateType, argsMap)
    }
  }

This allows me to do things like get parameters in a Jade template:

-@ val params: play.mvc.Scope.Params

{params.get('foo')}

If I pass in http://localhost:9000?foo=bar, it'll render "bar".

I'd love it if there was a shortcut where I could write {params.foo} like you can with JSTL.

Please let me know if you think there's anything I could improve.

Thanks,

Matt

On Oct 16, 2011, at 8:23 AM, Matt Raible wrote:

...

read more »


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Matt Raible  
View profile  
 More options Oct 26 2011, 9:35 am
From: Matt Raible <mrai...@gmail.com>
Date: Wed, 26 Oct 2011 06:35:04 -0700 (PDT)
Local: Wed, Oct 26 2011 9:35 am
Subject: Re: Fixing Play Scalate

On Aug 31, 8:42 pm, Matt Raible <mrai...@gmail.com> wrote:

I've changed this to a trait and all has been working fine and
dandy...

trait Scalate {

  def render(args: (Symbol, Any)*) = {
    val defaultTemplate = Http.Request.current().action.replace(".",
"/")
    ScalateTemplate(defaultTemplate).render(args: _*);
  }

}

... until I started trying to call a method from a method in my
Controller. For example:

def postComment(postId:Long) = {
  val author = params.get("author")
  val content = params.get("content")
  Validation.required("author", author)
  Validation.required("content", content)
  if (Validation.hasErrors) {
      show(postId)
  } else {
      Comment.create(Comment(postId, author, content))
      Action(show(postId))
  }

}

When I have validation errors, I end up with the following error:

Could not load resource: [Timeline/postComment.jade]

When what I really want is it to try and render Timeline/show.jade.

I tried changing Http.Request.current().action to
play.classloading.enhancers.ControllersEnhancer.currentAction.get().peek(),
but this results in controllers.Timeline.render instead of
controllers.Timeline.show.

What's the best way to get the local show() call to be handled
properly?

Thanks,

Matt


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »