Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ c3b04b90d9863ca2c7b7e56bc0bda148ce392642

# Scala Steward: Reformat with scalafmt 3.10.2
b023f22d7c3d7c29d6a69d3ff6a258cdc44a1b78

# Scala Steward: Reformat with scalafmt 3.10.3
0d36cbc27a3e478bd7bffc1183d936d83fd01d70
2 changes: 1 addition & 1 deletion .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version = 3.10.2
version = 3.10.3

project.layout=StandardConvention

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ object ScalaTemplatesSpec extends Specification {
val customer = Customer("mr customer")
val orders = List(Order("foo"), Order("bar"))

"Scala templates" should {
"support an example template" in {
"Scala templates".should {
"support an example template".in {

val c = Customer("mr customer")
val o = List(Order("foo"), Order("bar"))
Expand All @@ -47,60 +47,60 @@ object ScalaTemplatesSpec extends Specification {
// #invoke-template

val body = content.body
body must contain("mr customer")
body must contain("foo")
body must contain("bar")
body.must(contain("mr customer"))
body.must(contain("foo"))
body.must(contain("bar"))
}

"support string interpolation" in {
"support string interpolation".in {
// #string-interpolation
import play.twirl.api.StringInterpolation

val name = "Martin"
val p = html"<p>Hello $name</p>"
// #string-interpolation

p.body must_== "<p>Hello Martin</p>"
p.body.must_==("<p>Hello Martin</p>")
}

"allow simple parameters" in {
"allow simple parameters".in {
val body = html.simpleParameters(customer, orders).body
body must contain(customer.toString)
body must contain(orders(0).toString)
body must contain(orders(1).toString)
body.must(contain(customer.toString))
body.must(contain(orders(0).toString))
body.must(contain(orders(1).toString))
}

"allow default parameters" in {
html.defaultParameters("foo").body must contain("foo")
html.defaultParameters().body must contain("Home")
"allow default parameters".in {
html.defaultParameters("foo").body.must(contain("foo"))
html.defaultParameters().body.must(contain("Home"))
}

"allow curried parameters" in {
"allow curried parameters".in {
val body = html.curriedParameters("foo")(Html("bar")).body
body must contain("foo")
body must contain("bar")
body.must(contain("foo"))
body.must(contain("bar"))
}

"allow constructors" in {
"allow constructors".in {
val body = new html.constructor(MyComponent())(customer, orders).body
body must contain("MyComponent")
body must contain(customer.toString)
body must contain(orders(0).toString)
body must contain(orders(1).toString)
body.must(contain("MyComponent"))
body.must(contain(customer.toString))
body.must(contain(orders(0).toString))
body.must(contain(orders(1).toString))
}

"allow import statements" in {
html.importStatement(customer, orders).body must contain("import working")
"allow import statements".in {
html.importStatement(customer, orders).body.must(contain("import working"))
}

"allow absolute import statements" in {
html.importStatement(customer, orders).body must contain("absolute import is working")
"allow absolute import statements".in {
html.importStatement(customer, orders).body.must(contain("absolute import is working"))
}

"allow comments on the first line" in {
"allow comments on the first line".in {
val body = html.firstLineComment("blah").body
body must contain("blah")
body must not contain "Home page"
body.must(contain("blah"))
body.must(not).contain("Home page")
}

{
Expand All @@ -113,54 +113,54 @@ object ScalaTemplatesSpec extends Specification {
.mkString("\n")
}

"allow escaping the @ character" in {
body must contain("bob@example.com")
"allow escaping the @ character".in {
body.must(contain("bob@example.com"))
}

"allow iterating" in {
segment("for-loop") must contain("p1 ($1)")
segment("for-loop") must contain("p2 ($2)")
"allow iterating".in {
segment("for-loop").must(contain("p1 ($1)"))
segment("for-loop").must(contain("p2 ($2)"))
}

"allow conditionals" in {
body must contain("2 items!")
"allow conditionals".in {
body.must(contain("2 items!"))
}

"allow reusable code blocks" in {
segment("reusable") must contain("p1 ($1)")
segment("reusable") must contain("p2 ($2)")
"allow reusable code blocks".in {
segment("reusable").must(contain("p1 ($1)"))
segment("reusable").must(contain("p2 ($2)"))
}

"allow pure scala reusable code blocks" in {
body must contain("Hello World")
"allow pure scala reusable code blocks".in {
body.must(contain("Hello World"))
}

"allow declaring implicit variables" in {
body must contain("implicit working")
"allow declaring implicit variables".in {
body.must(contain("implicit working"))
}

"allow defining variables" in {
body must contain("Hello John Doe")
"allow defining variables".in {
body.must(contain("Hello John Doe"))
}

"allow comments" in {
body must not contain "This is a comment"
"allow comments".in {
body.must(not).contain("This is a comment")
}

"allow intering raw HTML" in {
body must contain("<foo>")
"allow intering raw HTML".in {
body.must(contain("<foo>"))
}
}

"display Scala types" in {
"display Scala types".in {
val body = html.displayScalaTypes().body

body must contain("User(Foo,Bar)")
body must contain("value inside option")
body must not contain "Option(value inside option)"
body must contain("firstlast")
body must not contain "List"
body must contain("helloUser(Foo,Bar)value inside optionfirstlast")
body.must(contain("User(Foo,Bar)"))
body.must(contain("value inside option"))
body.must(not).contain("Option(value inside option)")
body.must(contain("firstlast"))
body.must(not).contain("List")
body.must(contain("helloUser(Foo,Bar)value inside optionfirstlast"))
}
}
}
2 changes: 1 addition & 1 deletion docs/project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>

lazy val plugins = (project in file(".")).dependsOn(sbtTwirl)
lazy val plugins = project.in(file(".")).dependsOn(sbtTwirl)

lazy val sbtTwirl = ProjectRef(Path.fileProperty("user.dir").getParentFile, "plugin")

Expand Down
3 changes: 2 additions & 1 deletion sbt-twirl/src/sbt-test/twirl/compile-scala3/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>

lazy val root = (project in file("."))
lazy val root = project
.in(file("."))
.enablePlugins {
// Make sure scalajs plugin is not available
val sjsPluginName = "org.scalajs.sbtplugin.ScalaJSPlugin"
Expand Down
2 changes: 1 addition & 1 deletion sbt-twirl/src/sbt-test/twirl/compile/build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (C) from 2022 The Play Framework Contributors <https://github.com/playframework>, 2011-2021 Lightbend Inc. <https://www.lightbend.com>

lazy val root = (project in file(".")).enablePlugins {
lazy val root = project.in(file(".")).enablePlugins {
// Make sure scalajs plugin is not available
val sjsPluginName = "org.scalajs.sbtplugin.ScalaJSPlugin"
try Class.forName(sjsPluginName)
Expand Down
3 changes: 2 additions & 1 deletion sbt-twirl/src/sbt-test/twirl/scalajs-compile/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

logLevel := Level.Debug

lazy val root = (project in file("."))
lazy val root = project
.in(file("."))
.enablePlugins(ScalaJSPlugin, SbtTwirl)
.settings(
scalaJSUseMainModuleInitializer := true,
Expand Down
Loading