summaryrefslogtreecommitdiff
path: root/book
diff options
context:
space:
mode:
authorlihaoyi <haoyi.sg@gmail.com>2014-11-23 20:33:33 -0800
committerlihaoyi <haoyi.sg@gmail.com>2014-11-23 20:33:33 -0800
commit7924069976b15ee0c535221673d89200ce3d5570 (patch)
treeb9a3b1f83eb55be73796af1d4fd5f32bcf65092f /book
parent0f58d9da34162cdb85d8b3b6c6c9c38a991f02db (diff)
downloadhands-on-scala-js-7924069976b15ee0c535221673d89200ce3d5570.tar.gz
hands-on-scala-js-7924069976b15ee0c535221673d89200ce3d5570.tar.bz2
hands-on-scala-js-7924069976b15ee0c535221673d89200ce3d5570.zip
Packaged resourcesparboiled
Diffstat (limited to 'book')
-rw-r--r--book/src/main/scala/book/Book.scala26
-rw-r--r--book/src/main/scala/book/Main.scala14
-rw-r--r--book/src/main/scalatex/book/handson/WebPage.scalatex2
-rw-r--r--book/src/main/scalatex/book/indepth/AdvancedTechniques.scalatex2
-rw-r--r--book/src/main/scalatex/book/indepth/JavaAPIs.scalatex8
5 files changed, 33 insertions, 19 deletions
diff --git a/book/src/main/scala/book/Book.scala b/book/src/main/scala/book/Book.scala
index 9323fff..8b5098d 100644
--- a/book/src/main/scala/book/Book.scala
+++ b/book/src/main/scala/book/Book.scala
@@ -8,7 +8,7 @@ import scalatags.Text.all._
* Created by haoyi on 10/26/14.
*/
object Book {
- val autoResources = Seq(
+ val autoResources = Set(
"META-INF/resources/webjars/highlightjs/8.2-1/highlight.min.js",
"META-INF/resources/webjars/highlightjs/8.2-1/styles/idea.min.css",
"META-INF/resources/webjars/highlightjs/8.2-1/languages/scala.min.js",
@@ -18,38 +18,32 @@ object Book {
"META-INF/resources/webjars/highlightjs/8.2-1/languages/xml.min.js",
"META-INF/resources/webjars/pure/0.5.0/pure-min.css",
"META-INF/resources/webjars/pure/0.5.0/grids-responsive-min.css",
- "META-INF/resources/webjars/font-awesome/4.2.0/css/font-awesome.min.css",
"META-INF/resources/webjars/font-awesome/4.2.0/fonts/FontAwesome.otf",
"META-INF/resources/webjars/font-awesome/4.2.0/fonts/fontawesome-webfont.eot",
"META-INF/resources/webjars/font-awesome/4.2.0/fonts/fontawesome-webfont.svg",
"META-INF/resources/webjars/font-awesome/4.2.0/fonts/fontawesome-webfont.ttf",
"META-INF/resources/webjars/font-awesome/4.2.0/fonts/fontawesome-webfont.woff",
- "META-INF/resources/webjars/react/0.11.1/react.min.js",
"css/side-menu.css",
- "example-fastopt.js",
+ "example-opt.js",
"webpage/weather.js",
"favicon.svg",
"favicon.png"
)
- val manualResources = Seq(
+ val fontAwesomeCss =
+ "META-INF/resources/webjars/font-awesome/4.2.0/css/font-awesome.min.css"
+
+ val manualResources = Set(
"images/javascript-the-good-parts-the-definitive-guide.jpg",
"images/Hello World.png",
"images/Hello World White.png",
"images/Hello World Console.png",
"images/IntelliJ Hello.png",
"images/Dropdown.png",
- "images/Scalatags Downloads.png"
+ "images/Scalatags Downloads.png",
+ fontAwesomeCss
)
- val includes = for(res <- autoResources) yield {
- if (res.endsWith(".js"))
- script(src:=res)
- else if (res.endsWith(".css"))
- link(rel:="stylesheet", href:=res)
- else
- raw("")
- }
val txt = Index()
val data = upickle.write(sect.structure)
@@ -61,8 +55,10 @@ object Book {
meta(charset:="utf-8"),
meta(name:="viewport", content:="width=device-width, initial-scale=1.0"),
link(rel:="shortcut icon", `type`:="image/png", href:="favicon.png"),
+ link(rel:="stylesheet", href:=fontAwesomeCss),
+ link(rel:="stylesheet", href:="styles.css"),
tags2.title("Hands-on Scala.js"),
- includes
+ script(src:="scripts.js")
),
body(
onload:=s"Controller().main($data)",
diff --git a/book/src/main/scala/book/Main.scala b/book/src/main/scala/book/Main.scala
index da9bace..cb8ef99 100644
--- a/book/src/main/scala/book/Main.scala
+++ b/book/src/main/scala/book/Main.scala
@@ -22,10 +22,22 @@ object Main {
write(Book.site, "output/index.html")
- for(res <- Book.autoResources ++ Book.manualResources) {
+ val jsFiles = Book.autoResources.filter(_.endsWith(".js")).toSet
+ val cssFiles = Book.autoResources.filter(_.endsWith(".css")).toSet
+ val miscFiles = Book.autoResources -- cssFiles -- jsFiles
+
+ for(res <- Book.manualResources ++ miscFiles) {
copy(getClass.getResourceAsStream("/" + res), "output/" + res)
}
+ for((resources, dest) <- Seq(jsFiles -> "scripts.js", cssFiles -> "styles.css")) {
+ val blobs = for(res <- resources.iterator) yield {
+ io.Source.fromInputStream(getClass.getResourceAsStream("/"+res)).mkString
+ }
+
+ write(blobs.mkString("\n"), "output/"+dest)
+ }
+
val allNames = {
def rec(n: Tree[String]): Seq[String] = {
n.value +: n.children.flatMap(rec)
diff --git a/book/src/main/scalatex/book/handson/WebPage.scalatex b/book/src/main/scalatex/book/handson/WebPage.scalatex
index 58fceb1..1056460 100644
--- a/book/src/main/scalatex/book/handson/WebPage.scalatex
+++ b/book/src/main/scalatex/book/handson/WebPage.scalatex
@@ -159,7 +159,7 @@
@li
@hl.scala("=>") v.s. @hl.javascript{function} to define the callback.
@li
- Scalatags' @hl.scala{pre} v.s. @hl.javascript{document.createElement}
+ Scalatags' @hl.scala{pre} v.s. @hl.javascript{document.createElement("pre")}
@p
Overall, they're pretty close, which is a common theme in Scala.js: using Javascript APIs in Scala.js is often as seamless and easy as using them in Javascript itself, and it often looks almost identical.
diff --git a/book/src/main/scalatex/book/indepth/AdvancedTechniques.scalatex b/book/src/main/scalatex/book/indepth/AdvancedTechniques.scalatex
index f368a71..171b2d3 100644
--- a/book/src/main/scalatex/book/indepth/AdvancedTechniques.scalatex
+++ b/book/src/main/scalatex/book/indepth/AdvancedTechniques.scalatex
@@ -26,7 +26,7 @@
@li
@b{Continuous}: Handling of first-class signals, like in @link("Elm", "http://elm-lang.org/learn/What-is-FRP.elm")
- @sect{Why FPR}
+ @sect{Why FRP}
@p
The value proposition of FRP is that in a "traditional" program, when an event occurs, events and changes propagate throughout the program in an ad-hoc manner. An event-listener may trigger additional events, call some callbacks, or set some mutable variables that subsequent code will read and react to.
diff --git a/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex b/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex
index cecead8..0ad886d 100644
--- a/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex
+++ b/book/src/main/scalatex/book/indepth/JavaAPIs.scalatex
@@ -35,4 +35,10 @@
@hl.scala{sun.misc.Unsafe}
@p
- And other similar APIs will either need to be rewritten to not-use them (e.g. @lnk("AtomicIntegers", "https://github.com/scala-js/scala-js/blob/master/javalib/src/main/scala/java/util/concurrent/atomic/AtomicInteger.scala") can be written without threading/unsafe APIs because Javascript is single-threaded) or can't be ported at all (e.g. @code{java.io.File}) \ No newline at end of file
+ And other similar APIs will either need to be rewritten to not-use them. For example, @hl.scala{AtomicXXXs} can be written without threading/unsafe APIs because Javascript is single-threaded, making the implementation for e.g. an @hl.scala{AtomicBoolean} pretty trivial:
+
+ @hl.ref("output/scala-js/javalib/src/main/scala/java/util/concurrent/atomic/AtomicBoolean.scala")
+
+ @p
+ Others can't be ported at all (e.g. @code{java.io.File}) simply because the API capabilities they provide (blocking reads & writes to files) do not exist in the Javascript runtime.
+