summaryrefslogtreecommitdiff
path: root/book/src/main/scala/book/Book.scala
diff options
context:
space:
mode:
authorLi Haoyi <haoyi@dropbox.com>2014-10-28 00:11:20 -0700
committerLi Haoyi <haoyi@dropbox.com>2014-10-28 00:11:20 -0700
commit899ab6b865e4381b6f5b9b31bc662ea51604a7a5 (patch)
tree993d29801abb32acd457e98ed3f43551f0bc5195 /book/src/main/scala/book/Book.scala
parent65fe456b96d81b6d166ff1a38a7c6ab529d284c2 (diff)
downloadhands-on-scala-js-899ab6b865e4381b6f5b9b31bc662ea51604a7a5.tar.gz
hands-on-scala-js-899ab6b865e4381b6f5b9b31bc662ea51604a7a5.tar.bz2
hands-on-scala-js-899ab6b865e4381b6f5b9b31bc662ea51604a7a5.zip
lots of cleanup
Diffstat (limited to 'book/src/main/scala/book/Book.scala')
-rw-r--r--book/src/main/scala/book/Book.scala70
1 files changed, 46 insertions, 24 deletions
diff --git a/book/src/main/scala/book/Book.scala b/book/src/main/scala/book/Book.scala
index 6e4122f..4e2d015 100644
--- a/book/src/main/scala/book/Book.scala
+++ b/book/src/main/scala/book/Book.scala
@@ -12,27 +12,56 @@ import scalatags.Text.all._
object Book {
import Utils.sect
- val intro = twf("book/intro.tw")
- val gettingStarted = twf("book/getting-started.tw")
+ lazy val intro = sect("Intro to Scala.js")(twf("book/intro.tw"))
+ lazy val gettingStarted = sect("Getting Started")(twf("book/getting-started.tw"))
+ val txt = twf("book/index.tw")
val contentBar = {
- def rec(current: Node, depth: Int): Seq[Frag] = 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 "")
+ 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))
+ ) ++ current.children.flatMap(rec(_, depth + 1))
+ }
- // @li(cls:="menu-item-divided pure-menu-selected")
+ println("TABLE OF CONTENTS")
rec(Utils.structure, 0)
}
-
-
- val txt = twf("book/index.tw").render
-
+ 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", txt)
+ )
+ ).render
object hli{
def javascript(code: String*) = hl.highlight(code, "javascript", inline=true)
def scala(code: String*) = hl.highlight(code, "scala", inline=true)
@@ -47,8 +76,6 @@ object Book {
if (inline){
code(cls:=lang + " highlight-me", lines(0), padding:=0, display:="inline")
}else{
- println("LINES " + lines.toList)
- println(snippet)
val minIndent = lines.map(_.takeWhile(_ == ' ').length)
.filter(_ > 0)
.min
@@ -114,15 +141,11 @@ object Book {
firstCharIndex == -1 || firstCharIndex >= whitespace + (if (indented) 1 else 0)
}
- things.foreach(println)
val stuff =
if (!indented) {
- println("NOT INDENTED " + things)
things
- }
- else {
+ } else {
val last = lines(firstLine + things.length + 1)
-// println("LAST: " + last)
if (last.trim.toSet subsetOf "}])".toSet) {
lines(firstLine) +: things :+ last
} else {
@@ -131,7 +154,6 @@ object Book {
}
stuff.map(_.drop(whitespace)).mkString("\n")
}
- println(blob)
pre(code(cls:=lang + " highlight-me", blob))
}