summaryrefslogtreecommitdiff
path: root/example/twirl
diff options
context:
space:
mode:
Diffstat (limited to 'example/twirl')
-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
-rw-r--r--example/twirl/build.sc23
4 files changed, 68 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
diff --git a/example/twirl/build.sc b/example/twirl/build.sc
new file mode 100644
index 0000000..8e95a19
--- /dev/null
+++ b/example/twirl/build.sc
@@ -0,0 +1,23 @@
+import mill._, scalalib._
+import $ivy.`com.lihaoyi::mill-contrib-twirllib:0.2.6-18-b29c13`
+
+trait AppModule extends ScalaModule with mill.twirllib.TwirlModule{
+ def scalaVersion = "2.12.6"
+ def twirlVersion = "1.3.15"
+
+ def generatedSources = T{ Seq(compileTwirl().classes) }
+ def ivyDeps = Agg(
+ ivy"com.lihaoyi::cask:0.1.1",
+ ivy"com.lihaoyi::scalatags:0.6.7",
+ ivy"com.typesafe.play::twirl-api:${twirlVersion()}",
+ )
+
+ object test extends Tests{
+ def testFrameworks = Seq("utest.runner.Framework")
+
+ def ivyDeps = Agg(
+ ivy"com.lihaoyi::utest::0.6.3",
+ ivy"com.lihaoyi::requests::0.1.3",
+ )
+ }
+} \ No newline at end of file