Add initial application structure with HomeController and routing
This commit is contained in:
25
knockoutwhist-web/app/controllers/HomeController.scala
Normal file
25
knockoutwhist-web/app/controllers/HomeController.scala
Normal file
@@ -0,0 +1,25 @@
|
||||
package controllers
|
||||
|
||||
import javax.inject._
|
||||
import play.api._
|
||||
import play.api.mvc._
|
||||
import de.knockoutwhist.KnockOutWhist
|
||||
|
||||
/**
|
||||
* This controller creates an `Action` to handle HTTP requests to the
|
||||
* application's home page.
|
||||
*/
|
||||
@Singleton
|
||||
class HomeController @Inject()(val controllerComponents: ControllerComponents) extends BaseController {
|
||||
|
||||
/**
|
||||
* Create an Action to render an HTML page.
|
||||
*
|
||||
* The configuration in the `routes` file means that this method
|
||||
* will be called when the application receives a `GET` request with
|
||||
* a path of `/`.
|
||||
*/
|
||||
def index() = Action { implicit request: Request[AnyContent] =>
|
||||
Ok(views.html.main.render("KnockoutWhist", views.html.index.render()))
|
||||
}
|
||||
}
|
||||
5
knockoutwhist-web/app/views/index.scala.html
Normal file
5
knockoutwhist-web/app/views/index.scala.html
Normal file
@@ -0,0 +1,5 @@
|
||||
@()
|
||||
|
||||
@main("Welcome to Play") {
|
||||
<h1>Welcome to Play!</h1>
|
||||
}
|
||||
25
knockoutwhist-web/app/views/main.scala.html
Normal file
25
knockoutwhist-web/app/views/main.scala.html
Normal file
@@ -0,0 +1,25 @@
|
||||
@*
|
||||
* This template is called from the `index` template. This template
|
||||
* handles the rendering of the page header and body tags. It takes
|
||||
* two arguments, a `String` for the title of the page and an `Html`
|
||||
* object to insert into the body of the page.
|
||||
*@
|
||||
@(title: String)(content: Html)
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
@* Here's where we render the page title `String`. *@
|
||||
<title>@title</title>
|
||||
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
|
||||
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
|
||||
|
||||
</head>
|
||||
<body>
|
||||
@* And here's where we render the `Html` object containing
|
||||
* the page content. *@
|
||||
@content
|
||||
|
||||
<script src="@routes.Assets.versioned("javascripts/main.js")" type="text/javascript"></script>
|
||||
</body>
|
||||
</html>
|
||||
1
knockoutwhist-web/conf/application.conf
Normal file
1
knockoutwhist-web/conf/application.conf
Normal file
@@ -0,0 +1 @@
|
||||
# https://www.playframework.com/documentation/latest/Configuration
|
||||
50
knockoutwhist-web/conf/logback.xml
Normal file
50
knockoutwhist-web/conf/logback.xml
Normal file
@@ -0,0 +1,50 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
|
||||
<!-- https://www.playframework.com/documentation/latest/SettingsLogger -->
|
||||
|
||||
<!DOCTYPE configuration>
|
||||
|
||||
<configuration>
|
||||
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
|
||||
<import class="ch.qos.logback.classic.AsyncAppender"/>
|
||||
<import class="ch.qos.logback.core.FileAppender"/>
|
||||
<import class="ch.qos.logback.core.ConsoleAppender"/>
|
||||
|
||||
<appender name="FILE" class="FileAppender">
|
||||
<file>${application.home:-.}/logs/application.log</file>
|
||||
<encoder class="PatternLayoutEncoder">
|
||||
<charset>UTF-8</charset>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="STDOUT" class="ConsoleAppender">
|
||||
<!--
|
||||
On Windows, enabling Jansi is recommended to benefit from color code interpretation on DOS command prompts,
|
||||
which otherwise risk being sent ANSI escape sequences that they cannot interpret.
|
||||
See https://logback.qos.ch/manual/layouts.html#coloring
|
||||
-->
|
||||
<!-- <withJansi>true</withJansi> -->
|
||||
<encoder class="PatternLayoutEncoder">
|
||||
<charset>UTF-8</charset>
|
||||
<pattern>%d{yyyy-MM-dd HH:mm:ss} %highlight(%-5level) %cyan(%logger{36}) %magenta(%X{pekkoSource}) %msg%n</pattern>
|
||||
</encoder>
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCFILE" class="AsyncAppender">
|
||||
<appender-ref ref="FILE"/>
|
||||
</appender>
|
||||
|
||||
<appender name="ASYNCSTDOUT" class="AsyncAppender">
|
||||
<appender-ref ref="STDOUT"/>
|
||||
</appender>
|
||||
|
||||
<logger name="play" level="INFO"/>
|
||||
<logger name="application" level="DEBUG"/>
|
||||
|
||||
<root level="WARN">
|
||||
<appender-ref ref="ASYNCFILE"/>
|
||||
<appender-ref ref="ASYNCSTDOUT"/>
|
||||
</root>
|
||||
|
||||
</configuration>
|
||||
1
knockoutwhist-web/conf/messages
Normal file
1
knockoutwhist-web/conf/messages
Normal file
@@ -0,0 +1 @@
|
||||
# https://www.playframework.com/documentation/latest/ScalaI18N
|
||||
10
knockoutwhist-web/conf/routes
Normal file
10
knockoutwhist-web/conf/routes
Normal file
@@ -0,0 +1,10 @@
|
||||
# Routes
|
||||
# This file defines all application routes (Higher priority routes first)
|
||||
# https://www.playframework.com/documentation/latest/ScalaRouting
|
||||
# ~~~~
|
||||
|
||||
# An example controller showing a sample home page
|
||||
GET / controllers.HomeController.index()
|
||||
|
||||
# Map static resources from the /public folder to the /assets URL path
|
||||
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
|
||||
BIN
knockoutwhist-web/public/images/favicon.png
Normal file
BIN
knockoutwhist-web/public/images/favicon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 687 B |
0
knockoutwhist-web/public/javascripts/main.js
Normal file
0
knockoutwhist-web/public/javascripts/main.js
Normal file
0
knockoutwhist-web/public/stylesheets/main.css
Normal file
0
knockoutwhist-web/public/stylesheets/main.css
Normal file
45
knockoutwhist-web/test/controllers/HomeControllerSpec.scala
Normal file
45
knockoutwhist-web/test/controllers/HomeControllerSpec.scala
Normal file
@@ -0,0 +1,45 @@
|
||||
package controllers
|
||||
|
||||
import org.scalatestplus.play._
|
||||
import org.scalatestplus.play.guice._
|
||||
import play.api.test._
|
||||
import play.api.test.Helpers._
|
||||
|
||||
/**
|
||||
* Add your spec here.
|
||||
* You can mock out a whole application including requests, plugins etc.
|
||||
*
|
||||
* For more information, see https://www.playframework.com/documentation/latest/ScalaTestingWithScalaTest
|
||||
*/
|
||||
class HomeControllerSpec extends PlaySpec with GuiceOneAppPerTest with Injecting {
|
||||
|
||||
"HomeController GET" should {
|
||||
|
||||
"render the index page from a new instance of controller" in {
|
||||
val controller = new HomeController(stubControllerComponents())
|
||||
val home = controller.index().apply(FakeRequest(GET, "/"))
|
||||
|
||||
status(home) mustBe OK
|
||||
contentType(home) mustBe Some("text/html")
|
||||
contentAsString(home) must include ("Welcome to Play")
|
||||
}
|
||||
|
||||
"render the index page from the application" in {
|
||||
val controller = inject[HomeController]
|
||||
val home = controller.index().apply(FakeRequest(GET, "/"))
|
||||
|
||||
status(home) mustBe OK
|
||||
contentType(home) mustBe Some("text/html")
|
||||
contentAsString(home) must include ("Welcome to Play")
|
||||
}
|
||||
|
||||
"render the index page from the router" in {
|
||||
val request = FakeRequest(GET, "/")
|
||||
val home = route(app, request).get
|
||||
|
||||
status(home) mustBe OK
|
||||
contentType(home) mustBe Some("text/html")
|
||||
contentAsString(home) must include ("Welcome to Play")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user