Skip to content

Commit 4af58fd

Browse files
committed
Update to js-scala-0.3-SNAPSHOT and Play 2.1-RC2
1 parent 88227cf commit 4af58fd

File tree

22 files changed

+65
-53
lines changed

22 files changed

+65
-53
lines changed

.gitignore

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ local.properties
66
\#*
77
.\#*
88
*~
9-
9+
.idea/
10+
.idea_modules/

README.md

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,19 @@
1-
Uses JavaScript as an embedded DSL in Scala to integrate client-side
2-
and server-side validation into Play 2.0.
3-
4-
Dependencies:
5-
[Scala-Virtualized](https://github.com/js-scala/scala/tree/js),
6-
[LMS core](https://github.com/js-scala/virtualization-lms-core),
7-
[js.scala](https://github.com/js-scala/js-scala),
8-
[build-play20](https://github.com/js-scala/build-play20).
1+
Uses JavaScript as an embedded DSL in Scala to integrate client-side and server-side validation into Play 2.
2+
3+
# Run it!
4+
5+
Setup [LMS](https://github.com/TiarkRompf/virtualization-lms-core) and [js-scala](https://github.com/js-scala/js-scala).
6+
7+
Setup the validation library:
8+
9+
```bash
10+
$ cd core
11+
$ sbt publish-local
12+
```
13+
14+
Finally run the samples:
15+
16+
```bash
17+
$ cd samples/{sample} # Replace “sample” with “forms”, “mini” or “mini-forms”
18+
$ sbt run
19+
```

core/README

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
Installation Notes
22

3-
mkdir lib
4-
cp $PLAY_20/framework/src/play/target/scala-2.10.0-virtualized-SNAPSHOT/play_2.10.0-virtualized-SNAPSHOT-2.0-SNAPSHOT.jar lib/
3+
sbt publish-local

core/build.sbt

+8-10
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@ organization := "EPFL"
44

55
version := "0.2-SNAPSHOT"
66

7-
scalaVersion := Option(System.getenv("SCALA_VIRTUALIZED_VERSION")).getOrElse("2.10.0-M1-virtualized")
7+
scalaOrganization := "org.scala-lang.virtualized"
88

9-
//--- Dependencies
9+
scalaVersion := "2.10.0"
1010

11-
resolvers ++= Seq(
12-
ScalaToolsSnapshots,
13-
//needed for custom build of scala test
14-
"Dropbox" at "http://dl.dropbox.com/u/12870350/scala-virtualized"
15-
)
11+
//--- Dependencies
1612

1713
libraryDependencies ++= Seq(
18-
"org.scalatest" % "scalatest_2.10.0-virtualized-SNAPSHOT" % "1.6.1-SNAPSHOT" % "test",
19-
"EPFL" %% "js-scala" % "0.2-SNAPSHOT")
14+
"org.scalatest" %% "scalatest" % "1.9.1" % "test",
15+
"EPFL" %% "js-scala" % "0.3-SNAPSHOT",
16+
"play" %% "play" % "2.1-RC2"
17+
)
2018

2119
//--- End of Dependencies
2220

23-
scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xexperimental", "-P:continuations:enable", "-Yvirtualize")
21+
scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature", "-Xexperimental", "-P:continuations:enable", "-Yvirtualize")
2422

2523
//Our tests are not threadsafe so disabling parallel execution for now
2624
parallelExecution in Test := false

core/src/main/scala/scala/jsvalidation/PlayLMS.scala

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import validation.Constraints._
1212
import scala.js._
1313

1414
object PlayLMS {
15+
import language.{reflectiveCalls, existentials}
16+
1517
abstract class JSConstraint[-T:Manifest](name: String, errorName: String, args: Seq[Any], f: T => Boolean) extends Constraint[T](Some(name), args)(o => if (f(o)) Valid else Invalid(ValidationError(errorName, args: _*))) {
1618
val jsExp: JSExp
1719
val fExp: jsExp.Rep[Array[Any]] => jsExp.Rep[T => Boolean]

core/src/test/scala/scala/jsvalidation/TestPlayLMS.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import scala.js._
1616
import PlayLMS._
1717

1818
class TestPlayLMS extends Suite {
19+
import language.reflectiveCalls
1920
case class Fields(a: String, b: Int)
2021
case class OptFields(a: String, b: Option[Int])
2122
case class MoreFields(a: String, b: Int, c: Int, d: Int)
@@ -153,7 +154,7 @@ class TestPlayLMS extends Suite {
153154
def assertEqualsCheck(name: String)(content: String): Unit = {
154155
var failed = true
155156
try {
156-
expect(readFile(prefix+name+".check")){content}
157+
expectResult(readFile(prefix+name+".check")){content}
157158
failed = false
158159
} finally {
159160
if (failed) writeFile(prefix+name, content)

core/test-out/bootstrap.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
jQuery.validator.addMethod("constraint$eq5", function(value, element, params) {
22
return this.optional(element) || ((function(x0) {
33
var x1 = function(x2) {
4-
var x3 = x2==5
4+
var x3 = x2==5;
55
return x3
66
}
77
return x1

core/test-out/multiple.check

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
jQuery.validator.addMethod("constraint$eq5", function(value, element, params) {
22
return this.optional(element) || ((function(x0) {
33
var x1 = function(x2) {
4-
var x3 = x2==5
4+
var x3 = x2==5;
55
return x3
66
}
77
return x1
@@ -11,9 +11,9 @@ return x1
1111

1212
jQuery.validator.addMethod("constraint$eq", function(value, element, params) {
1313
return this.optional(element) || ((function(x0) {
14-
var x3 = x0[0]
14+
var x3 = x0[0];
1515
var x1 = function(x2) {
16-
var x4 = x2==x3
16+
var x4 = x2==x3;
1717
return x4
1818
}
1919
return x1

core/test-out/optional.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
jQuery.validator.addMethod("constraint$eq5", function(value, element, params) {
22
return this.optional(element) || ((function(x0) {
33
var x1 = function(x2) {
4-
var x3 = x2==5
4+
var x3 = x2==5;
55
return x3
66
}
77
return x1

core/test-out/param.check

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
jQuery.validator.addMethod("constraint$eq", function(value, element, params) {
22
return this.optional(element) || ((function(x0) {
3-
var x3 = x0[0]
3+
var x3 = x0[0];
44
var x1 = function(x2) {
5-
var x4 = x2==x3
5+
var x4 = x2==x3;
66
return x4
77
}
88
return x1

core/test-out/pattern.check

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
jQuery.validator.addMethod("constraint$pattern", function(value, element, params) {
22
return this.optional(element) || ((function(x0) {
3-
var x3 = x0[0]
4-
var x4 = new RegExp(x3)
3+
var x3 = x0[0];
4+
var x4 = new RegExp(x3);
55
var x1 = function(x2) {
6-
var x5 = x4.test(x2)
6+
var x5 = x4.test(x2);
77
return x5
88
}
99
return x1

core/test-out/simple.check

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
jQuery.validator.addMethod("constraint$eq5", function(value, element, params) {
22
return this.optional(element) || ((function(x0) {
33
var x1 = function(x2) {
4-
var x3 = x2==5
4+
var x3 = x2==5;
55
return x3
66
}
77
return x1

samples/forms/project/Build.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sbt._
22
import Keys._
3-
import PlayProject._
3+
import play.Project._
44

55
object ApplicationBuild extends Build {
66

@@ -11,9 +11,9 @@ object ApplicationBuild extends Build {
1111
"EPFL" %% "play-js-validation" % "0.2-SNAPSHOT"
1212
)
1313

14-
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
15-
resolvers += Resolver.url("ivy-local", url("file://" + Path.userHome + "/.ivy2/local"))(Resolver.ivyStylePatterns),
16-
scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xexperimental", "-Yvirtualize")
14+
val main = play.Project(appName, appVersion, appDependencies).settings(
15+
scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xexperimental", "-Yvirtualize"),
16+
scalaOrganization := "org.scala-lang.virtualized"
1717
)
1818

1919
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.11.3
1+
sbt.version=0.12.2-RC2

samples/forms/project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ logLevel := Level.Warn
55
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
66

77
// Use the Play sbt plugin for Play projects
8-
addSbtPlugin("play" % "sbt-plugin" % Option(System.getProperty("play.version")).getOrElse("2.0"))
8+
addSbtPlugin("play" % "sbt-plugin" % "2.1-RC2")

samples/mini-forms/app/controllers/Comments.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object Comments extends Controller {
2222
"company" -> optional(text),
2323
"email" -> email,
2424
"phone" -> optional(text verifying jsPattern("""[0-9.+]+""", "constraint.phone", "A valid phone number is required")),
25-
"message" -> nonEmptyText.verifying(jsConstraint("constraint.nice_message", "error.nice_message") { new { def eval(c: JS) = { import c._;
25+
"message" -> nonEmptyText.verifying(jsConstraint("constraint.nice_message", "error.nice_message") { new { def eval(c: JS) = { import c._
2626
(msg: Rep[String]) => {
2727
val words = msg.split(" ")
2828
def countWords(regex: String) = words.filter(regex.r.test(_)).length
@@ -40,7 +40,7 @@ object Comments extends Controller {
4040
* Display an empty form.
4141
*/
4242
def form = Action {
43-
Ok(html.comment.form(js, commentForm));
43+
Ok(html.comment.form(js, commentForm))
4444
}
4545

4646
/**
+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sbt._
22
import Keys._
3-
import PlayProject._
3+
import play.Project._
44

55
object ApplicationBuild extends Build {
66

@@ -11,9 +11,9 @@ object ApplicationBuild extends Build {
1111
"EPFL" %% "play-js-validation" % "0.2-SNAPSHOT"
1212
)
1313

14-
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
15-
resolvers += Resolver.url("ivy-local", url("file://" + Path.userHome + "/.ivy2/local"))(Resolver.ivyStylePatterns),
16-
scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xexperimental", "-Yvirtualize")
14+
val main = play.Project(appName, appVersion, appDependencies).settings(
15+
scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xexperimental", "-Yvirtualize"),
16+
scalaOrganization := "org.scala-lang.virtualized"
1717
)
1818

1919
}
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.11.3
1+
sbt.version=0.12.2-RC2

samples/mini-forms/project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ logLevel := Level.Warn
55
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
66

77
// Use the Play sbt plugin for Play projects
8-
addSbtPlugin("play" % "sbt-plugin" % Option(System.getProperty("play.version")).getOrElse("2.0"))
8+
addSbtPlugin("play" % "sbt-plugin" % "2.1-RC2")

samples/mini/project/Build.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import sbt._
22
import Keys._
3-
import PlayProject._
3+
import play.Project._
44

55
object ApplicationBuild extends Build {
66

@@ -11,9 +11,9 @@ object ApplicationBuild extends Build {
1111
"EPFL" %% "play-js-validation" % "0.2-SNAPSHOT"
1212
)
1313

14-
val main = PlayProject(appName, appVersion, appDependencies, mainLang = SCALA).settings(
15-
resolvers += Resolver.url("ivy-local", url("file://" + Path.userHome + "/.ivy2/local"))(Resolver.ivyStylePatterns),
16-
scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xexperimental", "-Yvirtualize")
14+
val main = play.Project(appName, appVersion, appDependencies).settings(
15+
scalacOptions ++= Seq("-deprecation", "-unchecked", "-Xexperimental", "-Yvirtualize"),
16+
scalaOrganization := "org.scala-lang.virtualized"
1717
)
1818

1919
}

samples/mini/project/build.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.11.3
1+
sbt.version=0.12.2-RC2

samples/mini/project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ logLevel := Level.Warn
55
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"
66

77
// Use the Play sbt plugin for Play projects
8-
addSbtPlugin("play" % "sbt-plugin" % "2.0-SNAPSHOT")
8+
addSbtPlugin("play" % "sbt-plugin" % "2.1-RC2")

0 commit comments

Comments
 (0)