Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update for play 2.9 #13

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ jobs:
strategy:
matrix:
java_version: [
8,
11
11,
17,
21
]
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Scala
uses: actions/setup-java@v3
with:
distribution: temurin
java-version: ${{ matrix.java_version }}
cache: sbt
- name: Format
run: sbt scalafmtAll sample/scalafmtAll scalafmtSbt
- name: Test and coverage
run: sbt clean sample/compile coverage +test; sbt coverageReport
- name: Archive coverage
Expand Down
3 changes: 3 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
version = 3.7.15
preset = IntelliJ
runner.dialect = scala213
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ You know why you want it:

## SBT

### for play 2.9.x

```scala
libraryDependencies ++= Seq(
"com.beachape" %% "play-csv" % "1.7"
)
```

### for play 2.8.x

```scala
Expand Down
36 changes: 16 additions & 20 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
import scalariform.formatter.preferences._
import com.typesafe.sbt.SbtScalariform.ScalariformKeys

lazy val theVersion = "1.7-SNAPSHOT"
lazy val theScalaVersion = "2.13.8"
lazy val theScalaVersion = "2.13.12"

lazy val root = Project(id = "root", base = file("."))
.settings(commonWithPublishSettings)
.settings(
name := "play-csv",
crossScalaVersions := Seq("2.13.8", "2.12.15"),
crossScalaVersions := Seq("2.13.12", "3.3.1"),
crossVersion := CrossVersion.binary,
libraryDependencies ++= Seq(
"org.apache.commons" % "commons-lang3" % "3.12.0",
"org.apache.commons" % "commons-text" % "1.10.0",
"com.typesafe.play" %% "play" % "2.8.19" % Provided,
"org.scalatest" %% "scalatest" % "3.2.15" % Test
"org.apache.commons" % "commons-lang3" % "3.13.0",
"org.apache.commons" % "commons-text" % "1.11.0",
"com.typesafe.play" %% "play" % "2.9.0" % Provided,
"org.scalatest" %% "scalatest" % "3.2.17" % Test
)
)

Expand All @@ -24,7 +21,8 @@ lazy val sample = Project(id = "sample", base = file("sample"))
.settings(
libraryDependencies += guice,
routesImport += "com.beachape.play.Csv"
).dependsOn(root)
)
.dependsOn(root)

lazy val commonWithPublishSettings =
commonSettings ++
Expand All @@ -36,18 +34,16 @@ lazy val commonSettings = Seq(
scalaVersion := theScalaVersion,
Test / testOptions += Tests.Argument("-oF")
) ++
scalariformSettings(true) ++
formatterPrefs ++
compilerSettings

lazy val formatterPrefs = Seq(
ScalariformKeys.preferences := ScalariformKeys.preferences.value
.setPreference(AlignParameters, true)
.setPreference(DoubleIndentConstructorArguments, true)
)

lazy val compilerSettings = Seq(
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature", "-Xlint", "-Xlog-free-terms")
scalacOptions ++= Seq(
"-unchecked",
"-deprecation",
"-feature",
"-Xlint",
"-Xlog-free-terms"
)
)

lazy val publishSettings = Seq(
Expand Down Expand Up @@ -76,7 +72,7 @@ lazy val publishSettings = Seq(
if (v.trim.endsWith("SNAPSHOT"))
Some("snapshots" at s"${nexus}content/repositories/snapshots")
else
Some("releases" at s"${nexus}service/local/staging/deploy/maven2")
Some("releases" at s"${nexus}service/local/staging/deploy/maven2")
}.value,
publishMavenStyle := true,
Test / publishArtifact := false,
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.7.2
sbt.version=1.9.7
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.8.19")
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.9.0")

addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.2.1")

addSbtPlugin("org.scalariform" % "sbt-scalariform" % "1.8.0")
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")

addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "1.9.3")
addSbtPlugin("org.scoverage" %% "sbt-scoverage" % "2.0.9")
39 changes: 18 additions & 21 deletions sample/app/controllers/Application.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@ import com.beachape.play.Csv
import play.api.data.Form
import play.api.data.Forms._
import play.api.i18n.I18nSupport
import play.api.mvc.{ AbstractController, ControllerComponents }
import play.api.mvc.{AbstractController, ControllerComponents}
import play.twirl.api.Html

import javax.inject.Inject

class Application @Inject() (cc: ControllerComponents) extends AbstractController(cc) with I18nSupport {
class Application @Inject() (cc: ControllerComponents)
extends AbstractController(cc)
with I18nSupport {

val form = Form("ids" -> Csv.mapping(number))

def queryParams(ids: Csv[Int]) = Action {
Ok(Html(
s"""
Ok(Html(s"""
|<html>
|<body>
| <h1>Query Params</h1>
Expand All @@ -26,8 +27,7 @@ class Application @Inject() (cc: ControllerComponents) extends AbstractControlle
}

def pathParams(ids: Csv[Int]) = Action {
Ok(Html(
s"""
Ok(Html(s"""
|<html>
|<body>
| <h1>Path Params<h1>
Expand All @@ -39,44 +39,41 @@ class Application @Inject() (cc: ControllerComponents) extends AbstractControlle

def showForm = Action { implicit r =>
import views.html.helper
Ok(Html(
s"""
Ok(Html(s"""
|<html>
|<body>
| ${
helper.form(controllers.routes.Application.postForm) {
Html(
s"""
| ${helper.form(controllers.routes.Application.postForm) {
Html(s"""
|${helper.CSRF.formField}
|${helper.inputText(form("ids"))}
|<button type='submit'>Submit</button>""".stripMargin)
}
}
}}
|
|</body>
|</html>
""".stripMargin))
}

def postForm = Action { implicit r =>
form.bindFromRequest().fold(
_ => BadRequest(Html(
"""
form
.bindFromRequest()
.fold(
_ => BadRequest(Html("""
| <html>
| <body>
| <h1>Something went wrong with binding the CSV<h1>
| </body>
| </html>
""".stripMargin)),
data => Ok(Html(
s"""
data => Ok(Html(s"""
|<html>
|<body>
| <h1>Bound</h1>
| <p>${data.toSeq.mkString(",")}</p>
|</body>
|</html>
""".stripMargin)))
""".stripMargin))
)
}

}
}