forked from tao-pr/scala-play-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 39fc33f
Showing
14 changed files
with
539 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package controllers | ||
|
||
import javax.inject._ | ||
import play.api.mvc._ | ||
|
||
import play.api.data._ | ||
import play.api.data.Forms._ | ||
|
||
case class $model;format="Camel"$Data(name: String, age: Int) | ||
|
||
// NOTE: Add the following to conf/routes to enable compilation of this class: | ||
/* | ||
GET /$model;format="camel"$ controllers.$model;format="Camel"$Controller.$model;format="camel"$Get | ||
POST /$model;format="camel"$ controllers.$model;format="Camel"$Controller.$model;format="camel"$Post | ||
*/ | ||
|
||
/** | ||
* $model;format="Camel"$ form controller for Play Scala | ||
*/ | ||
class $model;format="Camel"$Controller @Inject()(mcc: MessagesControllerComponents) extends MessagesAbstractController(mcc) { | ||
|
||
val $model;format="camel"$Form = Form( | ||
mapping( | ||
"name" -> text, | ||
"age" -> number | ||
)($model;format="Camel"$Data.apply)($model;format="Camel"$Data.unapply) | ||
) | ||
|
||
def $model;format="camel"$Get() = Action { implicit request: MessagesRequest[AnyContent] => | ||
Ok(views.html.$model;format="camel"$.form($model;format="camel"$Form)) | ||
} | ||
|
||
def $model;format="camel"$Post() = Action { implicit request: MessagesRequest[AnyContent] => | ||
$model;format="camel"$Form.bindFromRequest.fold( | ||
formWithErrors => { | ||
// binding failure, you retrieve the form containing errors: | ||
BadRequest(views.html.$model;format="camel"$.form(formWithErrors)) | ||
}, | ||
$model;format="camel"$Data => { | ||
/* binding success, you get the actual value. */ | ||
/* flashing uses a short lived cookie */ | ||
Redirect(routes.$model;format="Camel"$Controller.$model;format="camel"$Get()).flashing("success" -> ("Successful " + $model;format="camel"$Data.toString)) | ||
} | ||
) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
@($model;format="camel"$Form: Form[$model;format="Camel"$Data])(implicit request: MessagesRequestHeader) | ||
|
||
<h1>$model;format="camel"$ form</h1> | ||
|
||
@request.flash.get("success").getOrElse("") | ||
|
||
@helper.form(action = routes.$model;format="Camel"$Controller.$model;format="camel"$Post()) { | ||
@helper.CSRF.formField | ||
@helper.inputText($model;format="camel"$Form("name")) | ||
@helper.inputText($model;format="camel"$Form("age")) | ||
<input type="submit" value="submit"/> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
description = Generates a Controller with form handling | ||
model = user |
75 changes: 75 additions & 0 deletions
75
.g8/form/test/controllers/$model__Camel$ControllerSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package controllers | ||
|
||
import javax.inject._ | ||
import play.api._ | ||
import play.api.mvc._ | ||
import play.api.i18n._ | ||
|
||
import play.api.data._ | ||
import play.api.data.Forms._ | ||
|
||
import org.scalatestplus.play._ | ||
import play.api.test._ | ||
import play.api.test.Helpers._ | ||
|
||
import play.filters.csrf.CSRF.Token | ||
import play.filters.csrf.{CSRFConfigProvider, CSRFFilter} | ||
|
||
/** | ||
* $model;format="Camel"$ form controller specs | ||
*/ | ||
class $model;format="Camel"$ControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting { | ||
|
||
// Provide stubs for components based off Helpers.stubControllerComponents() | ||
class StubComponents(cc:ControllerComponents = stubControllerComponents()) extends MessagesControllerComponents { | ||
override val parsers: PlayBodyParsers = cc.parsers | ||
override val messagesApi: MessagesApi = cc.messagesApi | ||
override val langs: Langs = cc.langs | ||
override val fileMimeTypes: FileMimeTypes = cc.fileMimeTypes | ||
override val executionContext: ExecutionContext = cc.executionContext | ||
override val actionBuilder: ActionBuilder[Request, AnyContent] = cc.actionBuilder | ||
override val messagesActionBuilder: MessagesActionBuilder = new DefaultMessagesActionBuilderImpl(parsers.default, messagesApi)(executionContext) | ||
} | ||
|
||
"$model;format="Camel"$Controller GET" should { | ||
|
||
"render the index page from a new instance of controller" in { | ||
val controller = new $model;format="Camel"$Controller(new StubComponents()) | ||
val request = FakeRequest().withCSRFToken | ||
val home = controller.$model;format="camel"$Get().apply(request) | ||
|
||
status(home) mustBe OK | ||
contentType(home) mustBe Some("text/html") | ||
} | ||
|
||
"render the index page from the application" in { | ||
val controller = inject[$model;format="Camel"$Controller] | ||
val request = FakeRequest().withCSRFToken | ||
val home = controller.$model;format="camel"$Get().apply(request) | ||
|
||
status(home) mustBe OK | ||
contentType(home) mustBe Some("text/html") | ||
} | ||
|
||
"render the index page from the router" in { | ||
val request = CSRFTokenHelper.addCSRFToken(FakeRequest(GET, "/derp")) | ||
val home = route(app, request).get | ||
|
||
status(home) mustBe OK | ||
contentType(home) mustBe Some("text/html") | ||
} | ||
} | ||
|
||
"$model;format="Camel"$Controller POST" should { | ||
"process form" in { | ||
val request = { | ||
FakeRequest(POST, "/$model;format="camel"$") | ||
.withFormUrlEncodedBody("name" -> "play", "age" -> "4") | ||
} | ||
val home = route(app, request).get | ||
status(home) mustBe SEE_OTHER | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
logs | ||
target | ||
/.idea | ||
/.idea_modules | ||
/.classpath | ||
/.project | ||
/.settings | ||
/RUNNING_PID |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package controllers | ||
|
||
import javax.inject.Inject | ||
|
||
import play.api._ | ||
import play.api.libs.json.Json | ||
import play.api.mvc._ | ||
|
||
class DocumentController @Inject()( | ||
controllerComponents: ControllerComponents | ||
)( | ||
) extends AbstractController(controllerComponents) { | ||
|
||
def index = Action { | ||
Ok(Json.obj("Message" -> "Please implement me!")) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
name := """hashtag-extractor""" | ||
organization := "io.iaa" | ||
|
||
version := "1.0-SNAPSHOT" | ||
|
||
lazy val root = (project in file(".")).enablePlugins(PlayScala) | ||
|
||
scalaVersion := "2.12.8" | ||
|
||
libraryDependencies += guice | ||
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "4.0.1" % Test | ||
|
||
// Adds additional packages into Twirl | ||
//TwirlKeys.templateImports += "io.iaa.controllers._" | ||
|
||
// Adds additional packages into conf/routes | ||
// play.sbt.routes.RoutesKeys.routesImport += "io.iaa.binders._" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# https://www.playframework.com/documentation/latest/Configuration |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<!-- https://www.playframework.com/documentation/latest/SettingsLogger --> | ||
<configuration> | ||
|
||
<conversionRule conversionWord="coloredLevel" converterClass="play.api.libs.logback.ColoredLevel" /> | ||
|
||
<appender name="FILE" class="ch.qos.logback.core.FileAppender"> | ||
<file>${application.home:-.}/logs/application.log</file> | ||
<encoder> | ||
<pattern>%date [%level] from %logger in %thread - %message%n%xException</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> | ||
<encoder> | ||
<pattern>%coloredLevel %logger{15} - %message%n%xException{10}</pattern> | ||
</encoder> | ||
</appender> | ||
|
||
<appender name="ASYNCFILE" class="ch.qos.logback.classic.AsyncAppender"> | ||
<appender-ref ref="FILE" /> | ||
</appender> | ||
|
||
<appender name="ASYNCSTDOUT" class="ch.qos.logback.classic.AsyncAppender"> | ||
<appender-ref ref="STDOUT" /> | ||
</appender> | ||
|
||
<logger name="play" level="INFO" /> | ||
<logger name="application" level="DEBUG" /> | ||
|
||
<!-- Off these ones as they are annoying, and anyway we manage configuration ourselves --> | ||
<logger name="com.avaje.ebean.config.PropertyMapLoader" level="OFF" /> | ||
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader" level="OFF" /> | ||
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread" level="OFF" /> | ||
<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" /> | ||
|
||
<root level="WARN"> | ||
<!--<appender-ref ref="ASYNCFILE" />--> | ||
<appender-ref ref="ASYNCSTDOUT" /> | ||
</root> | ||
|
||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# https://www.playframework.com/documentation/latest/ScalaI18N |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Routes | ||
# This file defines all application routes (Higher priority routes first) | ||
# https://www.playframework.com/documentation/latest/ScalaRouting | ||
# | ||
GET / controllers.DocumentController.index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
sbt.version=1.2.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.7.0") | ||
addSbtPlugin("org.foundweekends.giter8" % "sbt-giter8-scaffold" % "0.11.0") |
Oops, something went wrong.