diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-13 00:42:18 +0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-08-13 00:45:14 +0800 |
commit | eb32d8d4a1e2bd50e5416fcfefd72dfe6da1a7bb (patch) | |
tree | 9b58c66dd7f54624b3d023e10ffa62c2a341feca | |
parent | bdf3a1313a171a5a01a8cbec535b7366e4861924 (diff) | |
download | cask-eb32d8d4a1e2bd50e5416fcfefd72dfe6da1a7bb.tar.gz cask-eb32d8d4a1e2bd50e5416fcfefd72dfe6da1a7bb.tar.bz2 cask-eb32d8d4a1e2bd50e5416fcfefd72dfe6da1a7bb.zip |
Add scalatags example
-rw-r--r-- | build.sc | 8 | ||||
-rw-r--r-- | docs/pages/1 - Cask: a Scala HTTP micro-framework .md | 11 | ||||
-rw-r--r-- | example/compress/build.sc | 2 | ||||
-rw-r--r-- | example/compress2/build.sc | 2 | ||||
-rw-r--r-- | example/compress3/build.sc | 2 | ||||
-rw-r--r-- | example/cookies/build.sc | 2 | ||||
-rw-r--r-- | example/decorated/build.sc | 2 | ||||
-rw-r--r-- | example/decorated2/build.sc | 2 | ||||
-rw-r--r-- | example/formJsonPost/build.sc | 2 | ||||
-rw-r--r-- | example/httpMethods/build.sc | 2 | ||||
-rw-r--r-- | example/minimalApplication/build.sc | 2 | ||||
-rw-r--r-- | example/minimalApplication2/build.sc | 2 | ||||
-rw-r--r-- | example/redirectAbort/build.sc | 2 | ||||
-rw-r--r-- | example/scalatags/app/src/Scalatags.scala | 15 | ||||
-rw-r--r-- | example/scalatags/app/test/src/ExampleTests.scala | 29 | ||||
-rw-r--r-- | example/scalatags/build.sc | 19 | ||||
-rw-r--r-- | example/staticFiles/build.sc | 2 | ||||
-rw-r--r-- | example/todo/app/test/src/ExampleTests.scala (renamed from example/todo/app/test/src/TodoTest.scala) | 2 | ||||
-rw-r--r-- | example/todo/build.sc | 2 | ||||
-rw-r--r-- | example/todoApi/build.sc | 2 | ||||
-rw-r--r-- | example/todoDb/build.sc | 2 | ||||
-rw-r--r-- | example/variableRoutes/build.sc | 2 |
22 files changed, 98 insertions, 18 deletions
@@ -12,10 +12,12 @@ import $file.example.httpMethods.build import $file.example.minimalApplication.build import $file.example.minimalApplication2.build import $file.example.redirectAbort.build +import $file.example.scalatags.build import $file.example.staticFiles.build import $file.example.todo.build import $file.example.todoApi.build import $file.example.todoDb.build +import $file.example.twirl.build import $file.example.variableRoutes.build object cask extends ScalaModule{ @@ -33,7 +35,7 @@ object cask extends ScalaModule{ def scalacPluginIvyDeps = Agg(ivy"com.lihaoyi::acyclic:0.1.7") object test extends Tests{ - def forkArgs = Seq("--illegal-access=deny") + def testFrameworks = Seq("utest.runner.Framework") def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", @@ -61,10 +63,12 @@ object example extends Module{ object minimalApplication extends $file.example.minimalApplication.build.AppModule with LocalModule object minimalApplication2 extends $file.example.minimalApplication2.build.AppModule with LocalModule object redirectAbort extends $file.example.redirectAbort.build.AppModule with LocalModule + object scalatags extends $file.example.scalatags.build.AppModule with LocalModule object staticFiles extends $file.example.staticFiles.build.AppModule with LocalModule object todo extends $file.example.todo.build.AppModule with LocalModule object todoApi extends $file.example.todoApi.build.AppModule with LocalModule object todoDb extends $file.example.todoDb.build.AppModule with LocalModule + object twirl extends $file.example.twirl.build.AppModule with LocalModule object variableRoutes extends $file.example.variableRoutes.build.AppModule with LocalModule } @@ -100,10 +104,12 @@ def uploadToGithub(authKey: String) = T.command{ $file.example.minimalApplication.build.millSourcePath, $file.example.minimalApplication2.build.millSourcePath, $file.example.redirectAbort.build.millSourcePath, + $file.example.scalatags.build.millSourcePath, $file.example.staticFiles.build.millSourcePath, $file.example.todo.build.millSourcePath, $file.example.todoApi.build.millSourcePath, $file.example.todoDb.build.millSourcePath, + $file.example.twirl.build.millSourcePath, $file.example.variableRoutes.build.millSourcePath, ) for(example <- examples){ diff --git a/docs/pages/1 - Cask: a Scala HTTP micro-framework .md b/docs/pages/1 - Cask: a Scala HTTP micro-framework .md index 7ed6916..b41fbe6 100644 --- a/docs/pages/1 - Cask: a Scala HTTP micro-framework .md +++ b/docs/pages/1 - Cask: a Scala HTTP micro-framework .md @@ -184,6 +184,17 @@ Cask provides some convenient helpers `cask.Redirect` and `cask.Abort` which you can return; these are simple wrappers around `cask.Request`, and simply set up the relevant headers or status code for you. +### HTML Rendering + +Cask doesn't come bundled with HTML templating functionality, but it makes it +really easy to use community-standard libraries like +[Scalatags](https://github.com/lihaoyi/scalatags) to render your HTML. Simply +adding the relevant `ivy"com.lihaoyi::scalatags:0.6.7"` dependency to your +`build.sc` file is enough to render Scalatags templates: + +$$$scalatags + + ### Extending Endpoints with Decorators diff --git a/example/compress/build.sc b/example/compress/build.sc index 6b3ab3f..2794393 100644 --- a/example/compress/build.sc +++ b/example/compress/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/compress2/build.sc b/example/compress2/build.sc index 6b3ab3f..2794393 100644 --- a/example/compress2/build.sc +++ b/example/compress2/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/compress3/build.sc b/example/compress3/build.sc index 6b3ab3f..2794393 100644 --- a/example/compress3/build.sc +++ b/example/compress3/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/cookies/build.sc b/example/cookies/build.sc index 6b3ab3f..2794393 100644 --- a/example/cookies/build.sc +++ b/example/cookies/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/decorated/build.sc b/example/decorated/build.sc index 6b3ab3f..2794393 100644 --- a/example/decorated/build.sc +++ b/example/decorated/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/decorated2/build.sc b/example/decorated2/build.sc index 6b3ab3f..2794393 100644 --- a/example/decorated2/build.sc +++ b/example/decorated2/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/formJsonPost/build.sc b/example/formJsonPost/build.sc index 6b3ab3f..2794393 100644 --- a/example/formJsonPost/build.sc +++ b/example/formJsonPost/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/httpMethods/build.sc b/example/httpMethods/build.sc index 6b3ab3f..2794393 100644 --- a/example/httpMethods/build.sc +++ b/example/httpMethods/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/minimalApplication/build.sc b/example/minimalApplication/build.sc index 6b3ab3f..2794393 100644 --- a/example/minimalApplication/build.sc +++ b/example/minimalApplication/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/minimalApplication2/build.sc b/example/minimalApplication2/build.sc index 6b3ab3f..2794393 100644 --- a/example/minimalApplication2/build.sc +++ b/example/minimalApplication2/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/redirectAbort/build.sc b/example/redirectAbort/build.sc index 6b3ab3f..2794393 100644 --- a/example/redirectAbort/build.sc +++ b/example/redirectAbort/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/scalatags/app/src/Scalatags.scala b/example/scalatags/app/src/Scalatags.scala new file mode 100644 index 0000000..600f022 --- /dev/null +++ b/example/scalatags/app/src/Scalatags.scala @@ -0,0 +1,15 @@ +package app +import scalatags.Text.all._ +object Scalatags extends cask.MainRoutes{ + @cask.get("/") + def hello() = { + "<!doctype html>" + html( + body( + h1("Hello World"), + p("I am cow") + ) + ) + } + + initialize() +} diff --git a/example/scalatags/app/test/src/ExampleTests.scala b/example/scalatags/app/test/src/ExampleTests.scala new file mode 100644 index 0000000..8eccecf --- /dev/null +++ b/example/scalatags/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 { + 'Scalatags - test(Scalatags) { 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/scalatags/build.sc b/example/scalatags/build.sc new file mode 100644 index 0000000..ff39504 --- /dev/null +++ b/example/scalatags/build.sc @@ -0,0 +1,19 @@ +import mill._, scalalib._ + + +trait AppModule extends ScalaModule{ + def scalaVersion = "2.12.6" + def ivyDeps = Agg( + ivy"com.lihaoyi::cask:0.0.1", + ivy"com.lihaoyi::scalatags:0.6.7", + ) + + 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.2", + ) + } +}
\ No newline at end of file diff --git a/example/staticFiles/build.sc b/example/staticFiles/build.sc index 6b3ab3f..2794393 100644 --- a/example/staticFiles/build.sc +++ b/example/staticFiles/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/todo/app/test/src/TodoTest.scala b/example/todo/app/test/src/ExampleTests.scala index 8f38612..e8ca7eb 100644 --- a/example/todo/app/test/src/TodoTest.scala +++ b/example/todo/app/test/src/ExampleTests.scala @@ -1,6 +1,6 @@ package app import utest._ -object TodoTests extends TestSuite{ +object ExampleTests extends TestSuite{ def test[T](example: cask.main.BaseMain)(f: String => T): T = { val server = io.undertow.Undertow.builder .addHttpListener(8080, "localhost") diff --git a/example/todo/build.sc b/example/todo/build.sc index b570b3b..77a4dee 100644 --- a/example/todo/build.sc +++ b/example/todo/build.sc @@ -11,7 +11,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/todoApi/build.sc b/example/todoApi/build.sc index 6b3ab3f..2794393 100644 --- a/example/todoApi/build.sc +++ b/example/todoApi/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/todoDb/build.sc b/example/todoDb/build.sc index b570b3b..77a4dee 100644 --- a/example/todoDb/build.sc +++ b/example/todoDb/build.sc @@ -11,7 +11,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", diff --git a/example/variableRoutes/build.sc b/example/variableRoutes/build.sc index 6b3ab3f..2794393 100644 --- a/example/variableRoutes/build.sc +++ b/example/variableRoutes/build.sc @@ -9,7 +9,7 @@ trait AppModule extends ScalaModule{ object test extends Tests{ def testFrameworks = Seq("utest.runner.Framework") - def forkArgs = Seq("--illegal-access=deny") + def ivyDeps = Agg( ivy"com.lihaoyi::utest::0.6.3", ivy"com.lihaoyi::requests::0.1.2", |