summaryrefslogtreecommitdiff
path: root/book
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 /book
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
Diffstat (limited to 'book')
-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
6 files changed, 83 insertions, 86 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