Commit a7af82c1 authored by Mathieu leclaire's avatar Mathieu leclaire

Get ride off Scalate !

parent 3e763aa1
......@@ -35,7 +35,7 @@ object ScalaTraJSTagsWireRxBuild extends Build {
"org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6",
"org.scala-lang.modules.scalajs" %%% "scalajs-jquery" % "0.6"
),
jsCall := "Client().run();",
//jsCall := "Client().run();",
outputPath := "server/src/main/webapp/"
)
).dependsOn(shared)
......@@ -52,9 +52,9 @@ object ScalaTraJSTagsWireRxBuild extends Build {
libraryDependencies ++= Seq(
"com.lihaoyi" %% "autowire" % "0.1.2",
"com.lihaoyi" %%% "upickle" % "0.2.1",
"com.scalatags" %%% "scalatags" % "0.4.0",
"org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6",
"org.scalatra" %% "scalatra" % ScalatraVersion,
"org.scalatra" %% "scalatra-scalate" % ScalatraVersion,
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
"ch.qos.logback" % "logback-classic" % "1.0.12" % "runtime",
"org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container",
......
......@@ -10,26 +10,37 @@ import shared._
import upickle._
import scala.concurrent.duration._
import scala.concurrent.Await
import scalatags.Text.all._
import scalatags.Text.{all => tags}
object Server extends Api {
def hello(a: Int) = a * 3
def caseClass = MyCaseClass("Hello !")
}
class MyScalatraServlet extends ServertestStack {
class MyScalatraServlet extends ScalatraServlet {
val basePath = "shared"
get("/") {
contentType = "text/html"
jade("/default.jade")
tags.html(
tags.head(
tags.meta(tags.httpEquiv := "Content-Type", tags.content := "text/html; charset=UTF-8"),
tags.script(tags.`type` := "text/javascript", tags.src := "js/client-fastopt.js"),
tags.script(tags.`type` := "text/javascript", tags.src := "js/client-opt.js")
),
tags.body(tags.onload := "Client().run();")
)
}
post(s"/$basePath/*") {
Await.result(autowire.Macros.route[Web](Server)(
autowire.Request(Seq(basePath) ++ multiParams("splat").head.split("/"),
upickle.read[Map[String, String]](request.body))
),Duration.Inf)
), Duration.Inf)
}
}
}
\ No newline at end of file
package fr.iscpif.app
import org.scalatra._
import scalate.ScalateSupport
import org.fusesource.scalate.{ TemplateEngine, Binding }
import org.fusesource.scalate.layout.DefaultLayoutStrategy
import javax.servlet.http.HttpServletRequest
import collection.mutable
trait ServertestStack extends ScalatraServlet with ScalateSupport {
/* wire up the precompiled templates */
override protected def defaultTemplatePath: List[String] = List("/WEB-INF/templates/views")
override protected def createTemplateEngine(config: ConfigT) = {
val engine = super.createTemplateEngine(config)
engine.layoutStrategy = new DefaultLayoutStrategy(engine,
TemplateEngine.templateTypes.map("/WEB-INF/templates/layouts/default." + _): _*)
engine.packagePrefix = "templates"
engine
}
/* end wiring up the precompiled templates */
override protected def templateAttributes(implicit request: HttpServletRequest): mutable.Map[String, Any] = {
super.templateAttributes ++ mutable.Map.empty // Add extra attributes here, they need bindings in the build file
}
notFound {
// remove content type in case it was set through an action
contentType = null
// Try to render a ScalateTemplate if no route matched
findTemplate(requestPath) map { path =>
contentType = "text/html"
layoutTemplate(path)
} orElse serveStaticResource() getOrElse resourceNotFound()
}
}
html
head
meta(charset="utf-8")
script(type="text/javascript" src="js/client-fastopt.js")
script(type="text/javascript" src="js/client-opt.js")
body
script="Client().run();"
\ No newline at end of file
<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="css/bootstrap.min.css"/>
<script type="text/javascript" src="js/d3.v3.min.js"></script>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/ui-opt.js"></script>
<script type="text/javascript" src="js/ui-fastopt.js"></script>
</head>
<body>
<script>Plot().run();</script>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment