EzDevInfo.com

scalate

scala template engine: like JSP but without the crap and with added scala coolness Scalate

Jade interpolation within javascript

(Note, this is the Scalate Jade, if that makes a difference)

I have the following route:

get("/fruit") {
  contentType = "text/html"
  jade("fruity", "fruit" -> "apple")
}

And this fruity.jade template:

-@ val fruit: String

p Alerting #{fruit}
:javascript
  alert("#{fruit}");

It renders like so:

<body><p>Alerting apple</p>
<script type="text/javascript">
  //<![CDATA[
    alert("#{fruit}");
  //]]>
</script>
</body>

The fruit value is not interpolated for the javascript portion. How can I get it to resolve in javascript?


Source: (StackOverflow)

Rendering Underscore variables in Jade

I have included the assets described in this ticket, and the Underscore variables work except when inside tags. I can not get variables to render inside dynamic tags data-id=someidfor doing things onClick with Backbone events.

In standard HTML:

<script type="text/template" id="template-action1-thing">
<tr>
   <td class="action-td" style="width: 10%;">
      <button id="do-remove" data-id="<%= obj.id %>">X</button>             
   </td>
</tr>
</script>

With (Scalate) Jade, which doesn't work:

script(id='template-action1-thing' type='text/template')
  p <%= obj.id %> Will render
  tr
    td.action-td(style='width: 10%;')
      button(id='do-remove' data-id='<%= obj.id %>') 
        | X

If I do this, the actual html renders with the variable properly, though incorrectly:

tr td(style='width: 10%;') button(id='do-remove_thing' data-id='myid') X

With a template like:

script(id='template-action1-thing' type='text/template')
  |   td.action-td(style='width: 10%;')
  |     button(id='do-remove_thing' data-id='<%= obj.id %>') X 

Source: (StackOverflow)

Advertisements

Scalate templates in Scalatra with WAR deployed in Jetty throw ResourceNotFoundException

When attempting to send email using scalate templates, resource not found exceptions are thrown (see below). Initially I thought it was a path issue, as in dev environment on sbt it works file, but deploying the WAR to jetty causes these exceptions.

com.mysite.api.util.mail.EmailActor@324f0f97: caught org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [/WEB-INF/scalate/templates/email-forgotpassword.ssp]

org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [/WEB-INF/scalate/templates/email-forgotpassword.ssp]

After numerous attempts to actually get jetty to look for the template in the right place, this worked:

val dir = this.getClass.getClassLoader().getResource("/").toExternalForm() + "../scalate/"

but still I get this exception:

org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [file:/var/cache/jetty/data/Jetty__8080_mysite_api_2.9.1.0.1.war__api__.1q1r37/webapp/WEB-INF/classes/../scalate/templates/email-forgotpassword.ssp]

The files definitely resides in that exact path, as a directory listing will confirm, so it's not a path issue I don't believe.

Any insight would be greatly appreciated. Thanks!


Source: (StackOverflow)

JADE/SCALATE template error - InvalidSyntaxException

I'm trying out Jade (via Scalate) and am running into an error that I'm not finding an answer to. (Or, at least not seeing.) I mocked up a form using BlueGriffon (it's been years since I've coded HTML...) and placed the resultant HTML into Aarron Powel's HTML-JADE converter. Here is the top portion or that translation which is in my .jade template file:

br
form(method='POST', action='/account/create', name='userAccountDetails')
  | Username:
  input(required='required', name='username', type='text')

etc., etc.,

Trying to run the scala app where this is nested generates this error:

org.fusesource.scalate.InvalidSyntaxException: )' expected but,' found at 5.19 at org.fusesource.scalate.scaml.ScamlParser.parse(ScamlParser.scala:375) at org.fusesource.scalate.jade.JadeCodeGenerator.generate(JadeCodeGenerator.scala:38)

It seems to not like the comman-sperated attributes, but I'm not sure why. Aslo, within the stacktrace clip it appears to be pulling in a Scaml parser, even though the file has a .jade extension.

Can someone point me in the right direction? Thanks.


Source: (StackOverflow)

Scalate ResourceNotFoundException in Scalatra

I'm trying the following based on scalatra-sbt.g8:

class FooWeb extends ScalatraServlet with ScalateSupport {
  beforeAll { contentType = "text/html" }
  get("/") {
    templateEngine.layout("/WEB-INF/scalate/templates/hello-scalate.jade")
  }
}

but I'm getting the following exception (even though the file exists) - any clues?

Could not load resource: [/WEB-INF/scalate/templates/hello-scalate.jade]; are you sure it's within [null]?

org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [/WEB-INF/scalate/templates/hello-scalate.jade]; are you sure it's within [null]?

FWIW, the innermost exception is coming from org.mortbay.jetty.handler.ContextHandler.getResource line 1142: _baseResource==null.


Source: (StackOverflow)

Is there are any lift + scalate full example?

There are hello scalate example, but it's too simple to learn. I want to know how integirat lift and scalate, for example, lift comet, lift form ...


Source: (StackOverflow)

How to share a mustache template between Scalate and Javascript?

So I'm using some server-side mustache templates with Scalatra and Scalate, and I'd like to use them in my Javascript code too.

Ideally I can load the same templates via some sort of ajax call, but I'm not really sure how to set that up with Scalatra + jetty.

Currently the templates live in

src/main/webapp/WEB-INF/templates/views/

This is the default for Scalatra, but those files aren't served statically by jetty, so I'm unsure how to share them with the front end.

Any suggestions?


Source: (StackOverflow)

Are there any Scala template engines other than scalate?

I'm tring to embed scalate in my website with sbt+jrebel, but found there are some problems I can't resolve.

So I want to know if there any other template engines based on scala?


Source: (StackOverflow)

How to interpret SBT error messages

Doing some work in scalatra, and when running ./sbt, I'm seeing this error message:

[trace] Stack trace suppressed: run last compile:sources for the full output.
[error] (compile:sources) org.fusesource.scalate.InvalidSyntaxException: `val' expected but `s' found at 1.12
[error] Total time: 0 s, completed Jul 1, 2013 6:04:31 PM

Can anyone give some insight into what 1.12 refers to? I'm running a pretty basic Scalatra framework, slightly modified (one .ssp file added, one .scala filed edited) from the hello-scala standard that downloads with g8


Source: (StackOverflow)

Mustache Scalate vs Mustache Java

I need to pick a Mustache rendering engine for a Scala project of mine. Seems like the only two choices are Mustache-Java and Scalate? Are there any comparisons? Which one is the more stable/performant of the two?


Source: (StackOverflow)

Getting the scala compiler to work inside an OSGi runtime

I am using a Scala template engine (Scalate) to compile templates at runtime within an OSGi environment (Scala 2.9.1). The templates cannot be pre-compiled because they are built dynamically.

In order for this to work, the Scala compiler needs to run within the OSGi environment. However, since the Scala compiler cannot take a classloader as input, this does not work out of the box.

From my research, there appears to be two general solution approaches:

1) A scala compiler plugin (there is one started here but it has not been touched since 2009, and messages on the scala list in 2009 stated it was not ready for production use.

2) Creating a virtual file system on top of the bundle context which could then be used by the Scala compiler. Apparently the Apache sling guys have successfully used this approach on an older version of Scala.

Has anyone gotten Scalate, Scala 2.9.1, and OSGi to work together to dynamically compile templates?


Source: (StackOverflow)

Scaml syntax highlighting on Emacs

How can I get Scaml (Scalate) syntax highlighting on Emacs? Already using Scala-mode.


Source: (StackOverflow)

play2-scalate publish-local error

I am trying to use the play2-scalate plugin (https://github.com/adetante/play2-scalate) to leverage Jade templates in my Play framework app, but have encountered an error when trying to run 'play publish-local'.

Before I file an issue, I thought I'd check here to see if there may be an easy fix (I'm new to Play/Scala/Scalate). Thanks in advance for any help you can provide.

Versions: Play 2.1-RC1, sbt 0.12.0, scala-2.10.0

instructions are to run play > publish-local in the project-core directory, and here is the error I get:

[info] Generating Scala API documentation for main sources to /tools/play2-scalate/project-code/target/scala-2.10/api...
[error] /tools/play2-scalate/project-code/app/controllers/Template.scala:21: not enough arguments for constructor TemplateEngine: (sourceDirectories: Traversable[java.io.File], mode: String)org.fusesource.scalate.TemplateEngine
[error] /tools/play2-scalate/project-code/app/controllers/Template.scala:21: not enough arguments for constructor TemplateEngine: (sourceDirectories: Traversable[java.io.File], mode: String)org.fusesource.scalate.TemplateEngine
[error]   val engine:TemplateEngine=new TemplateEngine()
[error]   val engine:TemplateEngine=new TemplateEngine()
[error]                             ^
[error]                             ^
[info] No documentation generated with unsucessful compiler run
[error] one error found
[error] one error found
[error] (compile:doc) Scaladoc generation failed

It looks like it is failing on a documentation generation step; I am not sure how to get around this. Any advice is appreciated. Thanks!


Source: (StackOverflow)

How to render a scalate template manually?

I want to try Scalate in this way:

  1. Provide a scalate template, say: index.html
  2. Use scala code to render it with some data manually
  3. Any template format is OK(mustache, Scaml, SSP, Jade)

But I sad found nothing to do this even if I have read all the documentation and source code I found.

In order to make this question more clear, so I have such a template user.html:

<%@ var user: User %>
<p>Hi ${user.name},</p>
#for (i <- 1 to 3)
<p>${i}</p>
#end
<p>See, I can count!</p>

I want to render it with a user instance User(name="Mike"). How to do it?


Source: (StackOverflow)

Value not set error in Scalate/Jade

I am new to Jade and Scalate. I have the following route defined:

get("/") {
  jade("index",
    "pageTitle" -> "Welcome to Jade",
    "welcomeMessage" -> "Hello my pretties")
}

And the template:

-@ val pageTitle: String
-@ val welcomeMessage: String

!!! 5
html(lang="en")
  head
    title= pageTitle
  body
    h1= welcomeMessage

The error I get on page render is:

The value for 'title' was not set
org.fusesource.scalate.NoValueSetException: The value for 'title' was not set
at org.fusesource.scalate.RenderContext$$anonfun$attribute$1.apply(RenderContext.scala:159)

Even if I remove the line title= pageTitle I still get the error. What is the error referring to and how do I fix it?


Source: (StackOverflow)