BAM Weblog

Ray - Roy on Play

Brian McKenna — 2012-03-04

This week I worked on a Play 2.0 plugin that automatically compiles Roy files. I’ve named the plugin ‘Ray’.

With Ray enabled in your application, you can write a plain .roy file and place it in the app/assets/javascripts directory:

You can then include it in your page like a normal .js asset:

<script src="@routes.Assets.at("javascripts/main.js")"></script>

Any compile errors will be shown when the page is requested:

Change to your editor to fix up the error:

Then refresh the page to have working JavaScript:

Download Ray from GitHub or Bitbucket.

I couldn’t find any prior Play 2.0 plugins so a lot of this was trial and error. In the end, I needed to make this an SBT plugin that is put into the Play 2.0 local Ivy repository.

These were main lines in the build.sbt file:

sbtPlugin := true

addSbtPlugin("play" % "sbt-plugin" % playVersion)

publishTo := Some(playRepository)

publishMavenStyle := false

The playRepository and playVersion values are calculated from environment variables given on the command line:

sbt -Dplay.path=../play-2.0-RC3 -Dplay.version=2.0-RC3 publish

Then the plugin can be added in the application’s plugins.sbt:

addSbtPlugin("org.brianmckenna" % "ray" % "0.1")

And then imported in the application’s Build.scala:

import org.brianmckenna.ray.RoyBuild

Then your Play 2.0 plugin can add resource generators or other build changes.

Please enable JavaScript to view the comments powered by Disqus.