summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2014-11-10 20:49:32 -0800
committerLi Haoyi <haoyi@dropbox.com>2014-11-10 20:49:32 -0800
commit916476a310661a0b81011e0af429f356d5cd36e7 (patch)
treeae0515e87b30681dd291bd78276a8f2edb6e1a4e
parentaaea4afbf3b47d623f396cb1eae247fa92053032 (diff)
downloadhands-on-scala-js-916476a310661a0b81011e0af429f356d5cd36e7.tar.gz
hands-on-scala-js-916476a310661a0b81011e0af429f356d5cd36e7.tar.bz2
hands-on-scala-js-916476a310661a0b81011e0af429f356d5cd36e7.zip
Small cleanup, book is now acyclic
-rw-r--r--book/src/main/scala/book/Book.scala54
-rw-r--r--book/src/main/scala/book/Main.scala62
-rw-r--r--book/src/main/scala/book/Utils.scala2
-rw-r--r--book/src/main/scalatex/book/Intro.scalatex9
-rw-r--r--book/src/main/scalatex/book/handson/ClientServer.scalatex21
-rw-r--r--book/src/main/scalatex/book/handson/PublishingModules.scalatex21
-rw-r--r--build.sbt24
-rw-r--r--examples/crossBuilds/clientserver/build.sbt9
-rw-r--r--examples/crossBuilds/clientserver/project/build.sbt6
-rw-r--r--examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala2
-rw-r--r--examples/demos/build.sbt2
-rw-r--r--project/build.sbt2
-rw-r--r--scalatexApi/src/main/scala/scalatex/Util.scala10
-rw-r--r--scalatexApi/src/main/scala/scalatex/package.scala2
-rw-r--r--scalatexApi/src/main/scala/scalatex/stages/Compiler.scala1
-rw-r--r--scalatexApi/src/main/scala/scalatex/stages/Parser.scala5
-rw-r--r--scalatexApi/src/main/scala/scalatex/stages/Trim.scala1
17 files changed, 122 insertions, 111 deletions
diff --git a/book/src/main/scala/book/Book.scala b/book/src/main/scala/book/Book.scala
index 785e6ab..e11c512 100644
--- a/book/src/main/scala/book/Book.scala
+++ b/book/src/main/scala/book/Book.scala
@@ -1,5 +1,5 @@
package book
-
+import acyclic.file
import scalatex._
import scalatags.Text.tags2
@@ -11,7 +11,6 @@ import scalatags.Text.all._
*/
object Book {
import Utils.sect
-
val myTable = Seq(
("Most of java.lang.*", "j.l.Thread, j.l.Runtime, ..."),
("Almost all of scala.*", "s.c.parallel, s.tools.nsc"),
@@ -23,58 +22,7 @@ object Book {
("JavaScript libraries: chipmunk.js, hand.js, react.js, jquery", "Java ecosystem: guice, junit, apache-commons, log4j"),
("IntelliJ, Eclipse, SBT, Chrome console, firebug", "Scala REPL, Yourkit, VisualVM, JProfiler")
)
- val txt = Index.template
- val contentBar = {
- def rec(current: Node, depth: Int): Seq[Frag] = {
- println("\t"*depth + current.name)
- Seq(
- li(
- a(
- current.name,
- href:="#"+Utils.munge(current.name),
- paddingLeft := s"${depth * 10 + 10}px",
- cls := "menu-item" + (if (depth == 1) " menu-item-divided " else "")
- )
- )
- ) ++ current.children.flatMap(rec(_, depth + 1))
- }
-
- println("TABLE OF CONTENTS")
- rec(Utils.structure, 0)
- }
- val site = Seq(
- raw("<!doctype html>"),
- html(
- head(
- meta(charset:="utf-8"),
- meta(name:="viewport", content:="width=device-width, initial-scale=1.0"),
- tags2.title("Hands-on Scala.js"),
- Utils.includes
- ),
-
- div(id:="layout")(
- a(href:="#menu", id:="menuLink", cls:="menu-link")(
- span
- ),
- div(id:="menu")(
- div(cls:="pure-menu pure-menu-open")(
- a(cls:="pure-menu-heading", href:="#")(
- "Contents"
- ),
- ul(cls:="menu-item-list")(
- contentBar
- )
- )
- )
- ),
- div(id:="main",
- div(id:="main-box")(
- txt
- )
- )
- )
- ).render
object hl{
def highlight(snippet: Seq[String], lang: String) = {
diff --git a/book/src/main/scala/book/Main.scala b/book/src/main/scala/book/Main.scala
index 19b256a..78c9c33 100644
--- a/book/src/main/scala/book/Main.scala
+++ b/book/src/main/scala/book/Main.scala
@@ -1,5 +1,5 @@
package book
-
+import acyclic.file
import java.io.InputStream
import java.nio.charset.StandardCharsets
import java.nio.file.{Paths, Files}
@@ -23,16 +23,64 @@ object Main {
Files.copy(src, Paths.get(dest))
}
+ val txt = Index.template
+ val contentBar = {
+ def rec(current: Node, depth: Int): Seq[Frag] = {
+ println("\t"*depth + current.name)
+ Seq(
+ li(
+ a(
+ current.name,
+ href:="#"+Utils.munge(current.name),
+ paddingLeft := s"${depth * 10 + 10}px",
+ cls := "menu-item" + (if (depth == 1) " menu-item-divided " else "")
+ )
+ )
+ ) ++ current.children.flatMap(rec(_, depth + 1))
+ }
+
+ println("TABLE OF CONTENTS")
+ rec(Utils.structure, 0)
+ }
+ val site = Seq(
+ raw("<!doctype html>"),
+ html(
+ head(
+ meta(charset:="utf-8"),
+ meta(name:="viewport", content:="width=device-width, initial-scale=1.0"),
+ tags2.title("Hands-on Scala.js"),
+ Utils.includes
+ ),
+
+ div(id:="layout")(
+ a(href:="#menu", id:="menuLink", cls:="menu-link")(
+ span
+ ),
+
+ div(id:="menu")(
+ div(cls:="pure-menu pure-menu-open")(
+ a(cls:="pure-menu-heading", href:="#")(
+ "Contents"
+ ),
+ ul(cls:="menu-item-list")(
+ contentBar
+ )
+ )
+ )
+ ),
+ div(id:="main",
+ div(id:="main-box")(
+ txt
+ )
+ )
+ )
+ ).render
+
def main(args: Array[String]): Unit = {
println("Writing Book")
-// Files.deleteIfExists(Paths.get("output/temp"))
-// Git.cloneRepository()
-// .setURI("https://github.com/lihaoyi/workbench-example-app")
-// .setDirectory(new java.io.File("output/temp"))
-// .call()
- write(Book.site, "output/index.html")
+ write(site, "output/index.html")
for(res <- Utils.autoResources ++ Utils.manualResources) {
copy(getClass.getResourceAsStream("/" + res), "output/" + res)
diff --git a/book/src/main/scala/book/Utils.scala b/book/src/main/scala/book/Utils.scala
index 4738324..01682da 100644
--- a/book/src/main/scala/book/Utils.scala
+++ b/book/src/main/scala/book/Utils.scala
@@ -1,6 +1,6 @@
package book
-
+import acyclic.file
import scala.collection.mutable
import scalatags.Text.all._
diff --git a/book/src/main/scalatex/book/Intro.scalatex b/book/src/main/scalatex/book/Intro.scalatex
index 4e09d99..dbe1960 100644
--- a/book/src/main/scalatex/book/Intro.scalatex
+++ b/book/src/main/scalatex/book/Intro.scalatex
@@ -96,7 +96,7 @@
@p
At this point, all of Google, Facebook, and Microsoft have all announced work on a typed variant of Javascript. These are not academic exercises: Dart/AtScript/Flow/Typescript are all problems that solve a real need, that these large companies have all faced once they've grown beyond a certain size. Clearly, Javascript isn't cutting it anymore, and the convenience and "native-ness" of the language is more than made up for in the constant barrage of self-inflicted problems. Scala.js takes this idea and runs with it!
- @sect{Shared Code}
+ @sect{Sharing Code}
@p
Scala.js does not just stop at writing code on the client, though! Scala itself is a very successful, capable language for writing all sorts of systems, from web servers to backend infrastructure. With Scala.js, you can utilize the same libraries you use writing your Scala servers when writing your Scala web clients! On one end, you are sharing your templating language with @a("Scalatags", href:="https://github.com/lihaoyi/scalatags") or sharing your serialization logic with @a("uPickle", href:="https://github.com/lihaoyi/upickle"). At the other, you are sharing large, abstract libraries like @a("Scalaz", href:="https://github.com/japgolly/scalaz") or @a("Shapeless", href:="https://groups.google.com/forum/#!searchin/scala-js/shapeless/scala-js/5Sf2up0z3PU/9F9SYB0qHEcJ").
@@ -147,7 +147,7 @@
@p
This book will be roughly divided into three sections. These sections can be read in any order. Although the later chapters will make references to earlier chapters, there'll be hyperlinks so you can quickly go back and catch up on what you missed skipping over ,
- @sect{Hands On}
+ @sect{Part 1: Hands On}
@p
A whirlwind tour of the various things that Scala.js can be used for. We will cover:
@@ -164,16 +164,13 @@
@p
After going through this chapter and following along with the exercises, you should have a good sense of how Scala.js works and how it feels building things in Scala.js. You would not be an expert, but you'll know where to get started if you decide to try out Scala.js for your next project.
- @sect{In Depth}
+ @sect{Part 2: In Depth}
@p
This section of the book will cover lots of content that does not fit in the earlier Hands-On portion of the book. Things that aren't immediately necessary to get something up and running, things that only advanced users would care about, things that you probably don't need to know but you'd like to know out of intellectual curiosity.
@p
In general, this section of the book will go much deeper into Scala.js, much more than is necessary to get your first applications built. We will talk about the small number of semantic differences between Scala.js and Scala, details of the foreign-function-interface with Javascript, the various optimization levels and what they do. Nothing pressing or urgently needed, but all very interesting, and worth reading if you want to really understand Scala.js in depth.
- @p
- Lastly, we will explore the solution space. Scala.js isn't the only game in town, and there are hundreds of over attempts at covering the same ground the Scala.js now attempts to cover. We'll compare and contrast the different approaches to see what Scala.js can bring to the table that other approaches cannot. Many decisions have been made that shape what Scala.js is today; why did we make them?
-
@hr
@p
diff --git a/book/src/main/scalatex/book/handson/ClientServer.scalatex b/book/src/main/scalatex/book/handson/ClientServer.scalatex
index b29df03..817f568 100644
--- a/book/src/main/scalatex/book/handson/ClientServer.scalatex
+++ b/book/src/main/scalatex/book/handson/ClientServer.scalatex
@@ -15,7 +15,22 @@
@sect{A Client-Server Setup}
@p
- Getting started with client-server integration, let's go with the simplest configuration possible: a Spray server and a Scala.js client. Most of the other web-frameworks (Play, Scalatra, etc.) will have more complex configurations, but the basic mechanism of wiring up Scala.js to your web framework will be the same.
+ Getting started with client-server integration, let's go with the simplest configuration possible: a Spray server and a Scala.js client. Most of the other web-frameworks (Play, Scalatra, etc.) will have more complex configurations, but the basic mechanism of wiring up Scala.js to your web framework will be the same. Our project will look like this:
+
+ @hl.bash
+ $ tree
+ .
+ ├── build.sbt
+ ├── client
+ │   ├── shared/main/scala/simple/FileData.scala
+ │   └── src/main/scala/simple/Client.scala
+ ├── project
+ │   └── build.sbt
+ └── server
+ ├── shared -> ../client/shared
+ └── src/main/scala/simple
+ ├── Page.scala
+ └── Server.scala
@p
First, let's do the wiring in @code{build.sbt}:
@@ -94,4 +109,6 @@
@li
Try adding additional functionality to the client-server interface: what about making it show the contents of a file if you've entered its full path? This can be added as a separate Ajax call or as part of the existing one.
@li
- How about setting up the build.sbt so it serves the fully-optimized Scala.js blob, @code{client-opt.js}? This is probably what you want before deployment into production, and the same technique as we used to serve the fast-optimized version applies here too. \ No newline at end of file
+ How about setting up the build.sbt so it serves the fully-optimized Scala.js blob, @code{client-opt.js}? This is probably what you want before deployment into production, and the same technique as we used to serve the fast-optimized version applies here too.
+ @li
+ What if you wanted to use another server rather than Spray? How about trying to set up a Play or Scalatra server to serve our Scala.js application code? \ No newline at end of file
diff --git a/book/src/main/scalatex/book/handson/PublishingModules.scalatex b/book/src/main/scalatex/book/handson/PublishingModules.scalatex
index 7882283..b329966 100644
--- a/book/src/main/scalatex/book/handson/PublishingModules.scalatex
+++ b/book/src/main/scalatex/book/handson/PublishingModules.scalatex
@@ -15,25 +15,12 @@
.
├── build.sbt
├── js
- │   ├── shared
- │   │   └── main
- │   │   └── scala
- │   │   └── simple
- │   │   └── Simple.scala
- │   └── src
- │   └── main
- │   └── scala
- │   └── simple
- │   └── Platform.scala
+ │   ├── shared/main/scala/simple/Simple.scala
+ │   └── src/main/scala/simple/Platform.scala
├── jvm
│   ├── shared -> ../js/shared
- │   └── src
- │   └── main
- │   └── scala
- │   └── simple
- │   └── Platform.scala
- └── project
- └── build.sbt
+ │   └── src/main/scala/simple/Platform.scala
+ └── project/ build.sbt
@p
In this case the two @code{shared/} folders are symlinked together to keep them in sync. This can be done by first creating @code{js/shared}, and then running
diff --git a/build.sbt b/build.sbt
index 9a40e85..c4e02c8 100644
--- a/build.sbt
+++ b/build.sbt
@@ -1,9 +1,11 @@
+
import scala.scalajs.sbtplugin.ScalaJSPlugin._
import ScalaJSKeys._
+
lazy val scalatexApi = project.in(file("scalatexApi"))
.settings(
- scalaVersion := "2.11.2",
+ scalaVersion := "2.11.4",
libraryDependencies ++= Seq(
"com.lihaoyi" %% "utest" % "0.2.4",
"com.scalatags" %% "scalatags" % "0.4.2",
@@ -20,7 +22,7 @@ lazy val scalatexPlugin = Project(
base = file("scalatexPlugin"),
dependencies = Seq(scalatexApi)
) settings (
- scalaVersion := "2.11.2",
+ scalaVersion := "2.11.4",
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value,
publishArtifact in Compile := false
)
@@ -30,7 +32,7 @@ lazy val book = Project(
base = file("book"),
dependencies = Seq(scalatexApi)
).settings(
- scalaVersion := "2.11.2",
+ scalaVersion := "2.11.4",
libraryDependencies ++= Seq(
"org.webjars" % "highlightjs" % "8.2-1",
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
@@ -57,8 +59,20 @@ lazy val book = Project(
},
(watchSources in Test) ++= {
((sourceDirectory in Test).value / "scalatex" ** "*.scalatex").get
- }
+ },
+ libraryDependencies += "com.lihaoyi" %% "acyclic" % "0.1.2" % "provided",
+ autoCompilerPlugins := true,
+ addCompilerPlugin("com.lihaoyi" %% "acyclic" % "0.1.2")
)
-lazy val demos = project.in(file("examples/demos")) \ No newline at end of file
+lazy val demos = project.in(file("examples/demos"))
+
+lazy val simple = project.in(file("examples/crossBuilds/simple"))
+
+lazy val simple2 = project.in(file("examples/crossBuilds/simple2"))
+
+lazy val client = ProjectRef(file("examples/crossBuilds/clientserver"), "client")
+
+lazy val server = ProjectRef(file("examples/crossBuilds/clientserver"), "server")
+
diff --git a/examples/crossBuilds/clientserver/build.sbt b/examples/crossBuilds/clientserver/build.sbt
index 618ac8a..457c5b1 100644
--- a/examples/crossBuilds/clientserver/build.sbt
+++ b/examples/crossBuilds/clientserver/build.sbt
@@ -7,7 +7,8 @@ val sharedSettings = Seq(
libraryDependencies ++= Seq(
"com.scalatags" %%% "scalatags" % "0.4.2",
"com.lihaoyi" %%% "upickle" % "0.2.5"
- )
+ ),
+ scalaVersion := "2.11.4"
)
lazy val client = project.in(file("client"))
@@ -21,6 +22,8 @@ lazy val client = project.in(file("client"))
lazy val server = project.in(file("server"))
.settings(sharedSettings:_*)
+ .settings(com.lihaoyi.workbench.Plugin.workbenchSettings:_*)
+ .settings(spray.revolver.RevolverPlugin.Revolver.settings:_*)
.settings(
libraryDependencies ++= Seq(
"io.spray" %% "spray-can" % "1.3.2",
@@ -30,5 +33,7 @@ lazy val server = project.in(file("server"))
(resources in Compile) += {
(fastOptJS in (client, Compile)).value
(artifactPath in (client, Compile, fastOptJS)).value
- }
+ },
+ bootSnippet := "",
)
+
diff --git a/examples/crossBuilds/clientserver/project/build.sbt b/examples/crossBuilds/clientserver/project/build.sbt
index 5bd83ce..9c68ece 100644
--- a/examples/crossBuilds/clientserver/project/build.sbt
+++ b/examples/crossBuilds/clientserver/project/build.sbt
@@ -1,4 +1,8 @@
/*project/build.sbt*/
addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.5.5")
-addSbtPlugin("com.lihaoyi" % "utest-js-plugin" % "0.2.4") \ No newline at end of file
+addSbtPlugin("com.lihaoyi" % "utest-js-plugin" % "0.2.4")
+
+addSbtPlugin("com.lihaoyi" % "workbench" % "0.2.3")
+
+addSbtPlugin("io.spray" % "sbt-revolver" % "0.7.2")
diff --git a/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala b/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala
index 6b2fea3..83947ac 100644
--- a/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala
+++ b/examples/crossBuilds/clientserver/server/src/main/scala/simple/Server.scala
@@ -3,7 +3,7 @@ package simple
import akka.actor.ActorSystem
import spray.http.{HttpEntity, MediaTypes}
import spray.routing.SimpleRoutingApp
-
+import upickle._
object Server extends SimpleRoutingApp{
def main(args: Array[String]): Unit = {
diff --git a/examples/demos/build.sbt b/examples/demos/build.sbt
index 7e6b685..20b9fca 100644
--- a/examples/demos/build.sbt
+++ b/examples/demos/build.sbt
@@ -4,7 +4,7 @@ name := "Example"
version := "0.1-SNAPSHOT"
-scalaVersion := "2.11.1"
+scalaVersion := "2.11.4"
libraryDependencies += "org.scala-lang.modules.scalajs" %%% "scalajs-dom" % "0.6"
diff --git a/project/build.sbt b/project/build.sbt
index 3d8ec82..1fbce95 100644
--- a/project/build.sbt
+++ b/project/build.sbt
@@ -1,3 +1,3 @@
addSbtPlugin("org.scala-lang.modules.scalajs" % "scalajs-sbt-plugin" % "0.5.5")
-addSbtPlugin("com.lihaoyi" % "utest-js-plugin" % "0.2.4") \ No newline at end of file
+addSbtPlugin("com.lihaoyi" % "utest-js-plugin" % "0.2.4")
diff --git a/scalatexApi/src/main/scala/scalatex/Util.scala b/scalatexApi/src/main/scala/scalatex/Util.scala
deleted file mode 100644
index 3bf9553..0000000
--- a/scalatexApi/src/main/scala/scalatex/Util.scala
+++ /dev/null
@@ -1,10 +0,0 @@
-package scalatex
-import acyclic.file
-
-object Util {
-
- implicit class Pipeable[T](t: T){
- def |>[V](f: T => V): V = f(t)
- }
-}
-
diff --git a/scalatexApi/src/main/scala/scalatex/package.scala b/scalatexApi/src/main/scala/scalatex/package.scala
index 78df45f..ca06411 100644
--- a/scalatexApi/src/main/scala/scalatex/package.scala
+++ b/scalatexApi/src/main/scala/scalatex/package.scala
@@ -7,7 +7,7 @@ import scala.language.experimental.macros
import acyclic.file
package object scalatex {
- import Util._
+
/**
* Wraps the given string as a twist fragment.
*/
diff --git a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala
index b34e94d..4f11b04 100644
--- a/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala
+++ b/scalatexApi/src/main/scala/scalatex/stages/Compiler.scala
@@ -1,5 +1,6 @@
package scalatex
package stages
+
import acyclic.file
import scala.reflect.macros.whitebox.Context
diff --git a/scalatexApi/src/main/scala/scalatex/stages/Parser.scala b/scalatexApi/src/main/scala/scalatex/stages/Parser.scala
index 6929f34..1b67446 100644
--- a/scalatexApi/src/main/scala/scalatex/stages/Parser.scala
+++ b/scalatexApi/src/main/scala/scalatex/stages/Parser.scala
@@ -1,9 +1,8 @@
package scalatex
package stages
-
+import acyclic.file
import org.parboiled2._
import torimatomeru.ScalaSyntax
-import Util._
/**
* Parses the input text into a roughly-structured AST. This AST
@@ -168,4 +167,4 @@ object Ast{
case class TypeArgs(str: String, offset: Int = 0) extends Sub
case class Args(str: String, offset: Int = 0) extends Sub
}
-} \ No newline at end of file
+}
diff --git a/scalatexApi/src/main/scala/scalatex/stages/Trim.scala b/scalatexApi/src/main/scala/scalatex/stages/Trim.scala
index 1ac7be1..8993734 100644
--- a/scalatexApi/src/main/scala/scalatex/stages/Trim.scala
+++ b/scalatexApi/src/main/scala/scalatex/stages/Trim.scala
@@ -1,4 +1,5 @@
package scalatex.stages
+import acyclic.file
/**
* Preprocesses the input string to normalize things related to whitespace