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
Trying to create Scalate Plugin and getting "not found: value render"
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
  11 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 Nov 3 2011, 11:28 am
From: Matt Raible <mrai...@gmail.com>
Date: Thu, 3 Nov 2011 08:28:20 -0700 (PDT)
Local: Thurs, Nov 3 2011 11:28 am
Subject: Trying to create Scalate Plugin and getting "not found: value render"
Hello all,

I'm trying to turn the following Scalate Trait into a Plugin.

import play.mvc.{Scope, Http}

trait Scalate {

  def render(args: (Symbol, Any)*) = {
    var template = Scope.RenderArgs.current().get("template")
    if (template == null) {
      template = Http.Request.current().action.replace(".", "/")
    }

    renderTemplate(template.toString, args: _*);
  }

  def renderTemplate(template: String, args: (Symbol, Any)*) = {
    ScalateTemplate(template).render(args: _*);
  }

}

With this trait, I had the following in ScalateTemplate.scala:

  case class Template(name: String) {

    def render(args: (Symbol, Any)*) = {
      val argsMap = populateRenderArgs(args: _*)

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

  def apply(template: String) = Template(template)

To turn this into a plugin, I copied ScalateTemplate into a module
project and modified the Template class to be as follows:

  case class Template(name: String) {

    def render(args: Map[String, Any]): String = {
      scalateEngine.layout(name + scalateType, args)
    }
  }

I created the following Plugin to call ScalateTemplate:

class Plugin extends PlayPlugin {

  var templateLoader:PlayPlugin = null

  override def loadTemplate(file: VirtualFile): Template = {
      if (null == templateLoader) return new FancyTemplate(file)
      return templateLoader.loadTemplate(file);
  }

  case class FancyTemplate(file: VirtualFile) extends Template {
    var template:String = null

    def apply(file: VirtualFile) {
      this.name = file.getName
      this.source = file.getRealFile.getAbsolutePath
      this.template =
Scope.RenderArgs.current().get("template").toString
      if (this.template == null) {
        this.template = Http.Request.current().action.replace(".",
"/")
      }
    }

    override def compile(): Unit = {}
    override def render(): String = {
      ScalateTemplate(template).render(Map())
    }
    override def internalRender(args: java.util.Map[String, AnyRef]):
String = {
      import scala.collection.JavaConversions._

      ScalateTemplate(template).render(args.toMap)
    }
  }

}

However, when I try to use it, I get:

/Users/mraible/dev/play-more/app/controllers/Home.scala:10: not found:
value render
    render('athlete -> athlete)
    ^
/Users/mraible/dev/play-more/app/controllers/Home.scala:14: not found:
value render
    render()
    ^
/Users/mraible/dev/play-more/app/controllers/Home.scala:18: not found:
value render
    render()
    ^
three errors found

Any ideas?

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.
Guillaume Bort  
View profile  
 More options Nov 3 2011, 3:13 pm
From: Guillaume Bort <guillaume.b...@gmail.com>
Date: Thu, 3 Nov 2011 20:13:22 +0100
Local: Thurs, Nov 3 2011 3:13 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"
The ScalaController type doesn't define any render method right?

The problem is that in Play 1.2, the Plugin API was designed for the
Java API, and then we started to experiment in a separate module with
scala. So most methods of the Plugin API are not relevant for the
Scala API.

Btw, that's why we started Play 2.0 to clean all this stuff and have 2
API at the same level with a proper Plugin mechanism.

In the meantime you should just provide a trait in your jade module.
It is probably the easiest and cleanest way to handle it.

--
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 Nov 4 2011, 1:14 pm
From: Matt Raible <mrai...@gmail.com>
Date: Fri, 4 Nov 2011 11:14:25 -0600
Local: Fri, Nov 4 2011 1:14 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"
Copying my trait to a plugin solved the problem. However, I'd also like to try and override the default behavior (rending a Template with Template() instead of render()). I've gotten close, but can't figure out how to turn a java.util.Map into (Symbol, Any).

   override def compile(): Unit = {}

   override def render(args: java.util.Map[String, AnyRef]): String = {
     internalRender(args)
   }
   override def internalRender(args: java.util.Map[String, AnyRef]): String = {
     // todo: Convert from a [String, AnyRef] to (Symbol, Any)
     // ScalateTemplate(template).render(args)
     ""
   }

Anyone know how to do this conversion?

Thanks,

Matt

On Nov 3, 2011, at 1:13 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 Hildebrand  
View profile  
 More options Nov 4 2011, 1:27 pm
From: Matt Hildebrand <matt.hildebr...@gmail.com>
Date: Fri, 4 Nov 2011 13:27:56 -0400
Local: Fri, Nov 4 2011 1:27 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"

Here is one possibility:

def convertMap(in: java.util.Map[String, AnyRef]): Map[Symbol, Any] = {
  import scala.collection.JavaConversions._

  Map.empty ++ (in map { pair => (Symbol(pair._1) ->
pair._2.asInstanceOf[Any]) })


 
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 Nov 4 2011, 3:29 pm
From: Matt Raible <mrai...@gmail.com>
Date: Fri, 4 Nov 2011 13:29:38 -0600
Local: Fri, Nov 4 2011 3:29 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"

Nope:

   [scalac] /Users/mraible/dev/play-scalate/src/play/modules/scalate/Plugin.scala:36: error: type mismatch;
   [scalac]  found   : scala.collection.immutable.Map[Symbol,Any]
   [scalac]  required: String
   [scalac]       Map.empty ++ (args map { pair => (Symbol(pair._1) -> pair._2.asInstanceOf[Any]) })
   [scalac]                 ^
   [scalac] one error found

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

On Nov 4, 2011, at 11:27 AM, Matt Hildebrand 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 Nov 4 2011, 3:35 pm
From: Guillaume Bort <guillaume.b...@gmail.com>
Date: Fri, 4 Nov 2011 20:35:02 +0100
Local: Fri, Nov 4 2011 3:35 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"

Have you tried scala.collection.JavaConverters ?

Le 4 nov. 2011 à 20:29, Matt Raible <mrai...@gmail.com> a écrit :


 
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 Nov 4 2011, 3:38 pm
From: Matt Raible <mrai...@gmail.com>
Date: Fri, 4 Nov 2011 13:38:03 -0600
Local: Fri, Nov 4 2011 3:38 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"

I feel like I've tried everything. I spent several hours last night trying everything I could think of. Of course, it was from 12-3 am, so it could be something very simple that I missed. ;)

On Nov 4, 2011, at 1:35 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 Hildebrand  
View profile   Translate to Translated (View Original)
 More options Nov 4 2011, 3:43 pm
From: Matt Hildebrand <matt.hildebr...@gmail.com>
Date: Fri, 4 Nov 2011 15:43:08 -0400
Local: Fri, Nov 4 2011 3:43 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"

The compiler error suggests that you actually want a String.  Perhaps you
forgot to render the template using the Map[Symbol, Any]?

Your question was apparently asking how to convert a java.util.Map[String,
AnyRef] to a Map[Symbol, Any], and that is what the snippet I sent does --
see below.  Perhaps I misunderstood the question.

scala> val m = new java.util.HashMap[String, AnyRef]
m: java.util.HashMap[String,AnyRef] = {}

scala> m.put("a", "123")
res0: AnyRef = null

scala> m.put("b", "456")
res1: AnyRef = null

scala> def convertMap(in: java.util.Map[String, AnyRef]): Map[Symbol, Any]
= {
     |   import scala.collection.JavaConversions._
     |   Map.empty ++ (in map { pair => (Symbol(pair._1) ->
pair._2.asInstanceOf[Any]) })
     | }
convertMap: (in: java.util.Map[String,AnyRef])Map[Symbol,Any]

scala> convertMap(m)
res2: Map[Symbol,Any] = Map('a -> 123, 'b -> 456)


 
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 Nov 4 2011, 3:53 pm
From: Matt Raible <mrai...@gmail.com>
Date: Fri, 4 Nov 2011 13:53:39 -0600
Local: Fri, Nov 4 2011 3:53 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"

The render method I'm trying to call takes the following:

def render(args: (Symbol, Any)*)

To be honest, I'm not sure if this is a Map or a Seq.

On Nov 4, 2011, at 1:43 PM, Matt Hildebrand 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 Hildebrand  
View profile  
 More options Nov 4 2011, 4:23 pm
From: Matt Hildebrand <matt.hildebr...@gmail.com>
Date: Fri, 4 Nov 2011 16:23:16 -0400
Local: Fri, Nov 4 2011 4:23 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"

On Fri, Nov 4, 2011 at 3:53 PM, Matt Raible <mrai...@gmail.com> wrote:
> The render method I'm trying to call takes the following:

> def render(args: (Symbol, Any)*)

In that case, you need a Seq[(Symbol, Any)], not a Map[Symbol, Any] or
String.  How about this, then?

render(convertMap(theMapToConvert).toSeq :_*)

The * in the render method's parameter list means "zero or more" (Symbol,
Any) tuples -- in other words, it's Scala syntax for varargs.  The :_* at
the call site means "don't pass this collection as a single parameter, but
rather pass each element that it contains as its own, separate parameter to
the varargs method I'm calling".

Cheers,
-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.
Matt Raible  
View profile  
 More options Nov 4 2011, 5:13 pm
From: Matt Raible <mrai...@gmail.com>
Date: Fri, 4 Nov 2011 15:13:11 -0600
Local: Fri, Nov 4 2011 5:13 pm
Subject: Re: [play-framework] Trying to create Scalate Plugin and getting "not found: value render"

Could this be failing because I'm using Scala 2.8.1?

Here's my code, which is what I believe you're suggesting:

    override def internalRender(args: java.util.Map[String, AnyRef]): String = {
      var map:Map[Symbol, Any] = convertMap(args);
      ScalateTemplate(template).render(map.toSeq :_*)
    }

    def convertMap(in: java.util.Map[String, AnyRef]): Map[Symbol, Any] = {
      import scala.collection.JavaConversions._

      Map.empty ++ (in map { pair => (Symbol(pair._1) -> pair._2.asInstanceOf[Any]) })
    }

The result is:

   [scalac] /Users/mraible/dev/play-scalate/src/play/modules/scalate/Plugin.scala:36: error: type mismatch;
   [scalac]  found   : Any
   [scalac]  required: String
   [scalac]       ScalateTemplate(template).render(map.toSeq :_*)
   [scalac]                                                                     ^
   [scalac] one error found

The ^ in my console points to the opening paren before map.toSeq

On Nov 4, 2011, at 2:23 PM, Matt Hildebrand 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.
End of messages
« Back to Discussions « Newer topic     Older topic »