diff options
Diffstat (limited to 'example/decorated2/app/src')
-rw-r--r-- | example/decorated2/app/src/Decorated2.scala | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/example/decorated2/app/src/Decorated2.scala b/example/decorated2/app/src/Decorated2.scala new file mode 100644 index 0000000..014965e --- /dev/null +++ b/example/decorated2/app/src/Decorated2.scala @@ -0,0 +1,37 @@ +package app +object Decorated2 extends cask.MainRoutes{ + class User{ + override def toString = "[haoyi]" + } + class loggedIn extends cask.Decorator { + def wrapFunction(ctx: cask.ParamContext, delegate: Delegate): Returned = { + delegate(Map("user" -> new User())) + } + } + class withExtra extends cask.Decorator { + def wrapFunction(ctx: cask.ParamContext, delegate: Delegate): Returned = { + delegate(Map("extra" -> 31337)) + } + } + + override def decorators = Seq(new withExtra()) + + @cask.get("/hello/:world") + def hello(world: String)(extra: Int) = { + world + extra + } + + @loggedIn() + @cask.get("/internal-extra/:world") + def internalExtra(world: String)(user: User)(extra: Int) = { + world + user + extra + } + + @loggedIn() + @cask.get("/ignore-extra/:world") + def ignoreExtra(world: String)(user: User)(extra: Int) = { + world + user + } + + initialize() +} |