summaryrefslogtreecommitdiff
path: root/example/twirl/app
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-08-22 18:15:24 +0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-08-22 18:15:24 +0800
commitdfe179d66517ab60dc80a89e6d5d14dd20b3fa2f (patch)
tree1fc9331f337fb622217d9cddfb0b723c85e6a8ed /example/twirl/app
parentf3fe134973e06b7498403c2775b8cdd181139380 (diff)
downloadcask-dfe179d66517ab60dc80a89e6d5d14dd20b3fa2f.tar.gz
cask-dfe179d66517ab60dc80a89e6d5d14dd20b3fa2f.tar.bz2
cask-dfe179d66517ab60dc80a89e6d5d14dd20b3fa2f.zip
0.1.30.1.3
Diffstat (limited to 'example/twirl/app')
-rw-r--r--example/twirl/app/src/Twirl.scala9
-rw-r--r--example/twirl/app/test/src/ExampleTests.scala29
-rw-r--r--example/twirl/app/views/hello.scala.html7
3 files changed, 45 insertions, 0 deletions
diff --git a/example/twirl/app/src/Twirl.scala b/example/twirl/app/src/Twirl.scala
new file mode 100644
index 0000000..f6f12b4
--- /dev/null
+++ b/example/twirl/app/src/Twirl.scala
@@ -0,0 +1,9 @@
+package app
+object Twirl extends cask.MainRoutes{
+ @cask.get("/")
+ def hello() = {
+ "<!doctype html>" + html.hello("Hello World")
+ }
+
+ initialize()
+}
diff --git a/example/twirl/app/test/src/ExampleTests.scala b/example/twirl/app/test/src/ExampleTests.scala
new file mode 100644
index 0000000..815f656
--- /dev/null
+++ b/example/twirl/app/test/src/ExampleTests.scala
@@ -0,0 +1,29 @@
+package app
+import io.undertow.Undertow
+
+import utest._
+
+object ExampleTests extends TestSuite{
+ def test[T](example: cask.main.BaseMain)(f: String => T): T = {
+ val server = Undertow.builder
+ .addHttpListener(8080, "localhost")
+ .setHandler(example.defaultHandler)
+ .build
+ server.start()
+ val res =
+ try f("http://localhost:8080")
+ finally server.stop()
+ res
+ }
+
+ val tests = Tests {
+ 'Twirl - test(Twirl) { host =>
+ val body = requests.get(host).text()
+
+ assert(
+ body.contains("<h1>Hello World</h1>"),
+ body.contains("<p>I am cow</p>"),
+ )
+ }
+ }
+}
diff --git a/example/twirl/app/views/hello.scala.html b/example/twirl/app/views/hello.scala.html
new file mode 100644
index 0000000..604a8f4
--- /dev/null
+++ b/example/twirl/app/views/hello.scala.html
@@ -0,0 +1,7 @@
+@(titleTxt: String)
+<html>
+ <body>
+ <h1>@titleTxt</h1>
+ <p>I am cow</p>
+ </body>
+</html> \ No newline at end of file