summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2014-11-10 21:20:58 -0800
committerLi Haoyi <haoyi@dropbox.com>2014-11-10 21:20:58 -0800
commitebdba5a49e6c1be8d271752d1d546142c37453a9 (patch)
treebe2b9498319a2b6e8de76ee8c08eca6860088b67
parent8ced367e0d736b429f0b39ae7fde2b76b1d64ed5 (diff)
downloadhands-on-scala-js-ebdba5a49e6c1be8d271752d1d546142c37453a9.tar.gz
hands-on-scala-js-ebdba5a49e6c1be8d271752d1d546142c37453a9.tar.bz2
hands-on-scala-js-ebdba5a49e6c1be8d271752d1d546142c37453a9.zip
First checked-internal-references working
-rw-r--r--book/src/main/scala/book/Main.scala20
-rw-r--r--book/src/main/scala/book/Utils.scala8
-rw-r--r--book/src/main/scalatex/book/Index.scalatex6
3 files changed, 30 insertions, 4 deletions
diff --git a/book/src/main/scala/book/Main.scala b/book/src/main/scala/book/Main.scala
index 8ebcbd4..fb61e57 100644
--- a/book/src/main/scala/book/Main.scala
+++ b/book/src/main/scala/book/Main.scala
@@ -25,7 +25,25 @@ object Main {
for(res <- Book.autoResources ++ Book.manualResources) {
copy(getClass.getResourceAsStream("/" + res), "output/" + res)
}
- sect.structure
+
+ val allNames = {
+ def rec(n: Node): Seq[String] = {
+ n.name +: n.children.flatMap(rec)
+ }
+ rec(sect.structure).toSet
+ }
+ val dupes = allNames.groupBy(x => x)
+ .values
+ .filter(_.size > 1)
+ .map(_.head)
+ .toSet
+
+ assert(dupes.size == 0, s"Duplicate names: $dupes")
+
+ val dangling = sect.usedRefs -- allNames
+
+ assert(dangling.size == 0, s"Dangling Refs: $dangling")
+
println("Writing Done")
}
diff --git a/book/src/main/scala/book/Utils.scala b/book/src/main/scala/book/Utils.scala
index fd9dd97..494b861 100644
--- a/book/src/main/scala/book/Utils.scala
+++ b/book/src/main/scala/book/Utils.scala
@@ -4,6 +4,7 @@ import acyclic.file
import scala.collection.mutable
import scalatags.Text.all._
object sect{
+
var indent = 0
val headers = Seq[((String, String) => scalatags.Text.Tag, Option[Frag => Frag])](
@@ -25,6 +26,13 @@ object sect{
var structure = Node("root", mutable.Buffer.empty)
+ val usedRefs = mutable.Set.empty[String]
+
+ def ref(s: String) = {
+ usedRefs += s
+ a(s, href:=s"#${munge(s)}")
+ }
+
def munge(name: String) = {
name.replace(" ", "")
}
diff --git a/book/src/main/scalatex/book/Index.scalatex b/book/src/main/scalatex/book/Index.scalatex
index 6948be5..524612e 100644
--- a/book/src/main/scalatex/book/Index.scalatex
+++ b/book/src/main/scalatex/book/Index.scalatex
@@ -12,7 +12,7 @@
@a("Scala.js", href:="http://www.scala-js.org/") is a compiler that compiles Scala source code to equivalent Javascript code. That lets you write Scala code that you can run in a web browser, or other environments (Chrome plugins, Node.js, etc.) where Javascript is supported.
@p
- This book contains something for all levels of experience with Scala.js: absolute beginners can get started with the Introduction and Hands-on tutorial, people who have used it before can skip ahead to the later parts of the tutorial, building a canvas app or dynamic HTML page. Intermediate users will find the chapters on cross-publishing a Scala.js library interesting, and even experienced users will find the In-depth Documention useful.
+ This book contains something for all levels of experience with Scala.js: absolute beginners can get started with the @sect.ref{Intro to Scala.js} and @sect.ref{Hands On} tutorial, people who have used it before can skip ahead to the later parts of the tutorial, @sect.ref{Making a Canvas App} or @sect.ref{Interactive Web Pages}. Intermediate users will find the chapters on @sect.ref{Cross Publishing Libraries} with Scala.js or @sect.ref{Integrating Client-Server}, and even experienced users will find the @sect.ref{In Depth} documention useful.
@p
This book does not spend time on pontifying a philosophy or ideology behind Scala.js or Scala. It instead spends its words on hands-on tutorials and in-depth dives into parts of the Scala.js platform, to try and get you acquainted with Scala.js as soon as possible, so you can make your own decisions about its merits or qualities.
@@ -36,13 +36,13 @@
@sect("The Command Line")
@handson.CommandLine()
- @sect("Publishing Modules")
+ @sect("Cross Publishing Libraries")
@handson.PublishingModules()
@sect("Integrating Client-Server")
@handson.ClientServer()
-@sect("Scala.js in Depth", "Exploring Scala.js")
+@sect("In Depth", "Exploring Scala.js")
@p
This half of the book dives into a few aspects of Scala.js much more deeply that the hands-on introduction does. It's aimed at someone who has already used Scala.js, and wants to explore the edge-cases, how things work under-the-cover, or why it has been designed in such a way. It's not a formal specification; rather, it's aim is to be a useful reference to read instead of (or in preparation for) digging into the implementation code.